当前位置: 首页>>代码示例>>Python>>正文


Python File.keys方法代码示例

本文整理汇总了Python中mutagen.File.keys方法的典型用法代码示例。如果您正苦于以下问题:Python File.keys方法的具体用法?Python File.keys怎么用?Python File.keys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mutagen.File的用法示例。


在下文中一共展示了File.keys方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: getSongInfo

# 需要导入模块: from mutagen import File [as 别名]
# 或者: from mutagen.File import keys [as 别名]
def getSongInfo(inputFile):
    info = {}
    # detect format and type of tags
    file = File(inputFile)
    """
    if 'APIC:' in file.keys():
        artwork = file.tags['APIC:'].data # access APIC frame and grab the image
        with open('./image.jpg', 'wb') as img:
            img.write(artwork) # write artwork to new image
    """
    # check for album art existence
    if "APIC:" in file.keys():
        artwork = file.tags["APIC:"].data  # access APIC frame and grab the image
        # extract image
        info["image"] = artwork

    # extract title
    info["title"] = str(file["TIT2"][0])
    # extract artist
    info["artist"] = str(file["TPE1"][0])
    # extract album
    info["album"] = str(file["TALB"][0])
    if "TDRC" in file.keys():
        # extract year
        info["year"] = str(file["TDRC"][0])
    if "TCON" in file.keys():
        # extract genre
        info["genre"] = str(file["TCON"][0])
    if "TPUB" in file.keys():
        # extract publisher
        info["publisher"] = str(file["TPUB"][0])
    # extract length / duration
    info["length"] = str(round(file.info.length / 60, 2))

    return info
开发者ID:imsparsh,项目名称:Music-Fingerprinting-Lycaon,代码行数:37,代码来源:__init__.py

示例2: get_cover_art

# 需要导入模块: from mutagen import File [as 别名]
# 或者: from mutagen.File import keys [as 别名]
def get_cover_art(song):
  if song.path == 'None':
    return None
  file = File(song.path)
  APIC = None
  for key in file.keys():
    if 'APIC:' in key:
      APIC = key
  if APIC is None:
    return None
  artwork = file.tags[APIC].data
  return artwork
开发者ID:mamins1376,项目名称:MPDroid-CoverServer,代码行数:14,代码来源:server.py

示例3: process_metadata

# 需要导入模块: from mutagen import File [as 别名]
# 或者: from mutagen.File import keys [as 别名]
  def process_metadata(self, metadata):

    Log('Reading OGG tags from: ' + self.filename)
    try: 
      tags = MFile(self.filename)
      Log('Found tags: ' + str(tags.keys()))
    except:
      Log('An error occured while attempting to parse the OGG file: ' + self.filename)
      return

    # Genres
    try:
      genres = tags.get('genre')
      if genres is not None and len(genres) > 0:
        metadata.genres.clear()
        for genre in genres:
          for sub_genre in parse_genres(genre):
            metadata.genres.add(sub_genre.strip())
    except Exception, e:
      Log('Exception reading genre: ' + str(e))
开发者ID:kmoore134,项目名称:plexmediaserver-freebsd-10.1-amd64,代码行数:22,代码来源:audiohelpers.py

示例4: process_metadata

# 需要导入模块: from mutagen import File [as 别名]
# 或者: from mutagen.File import keys [as 别名]
    def process_metadata(self, metadata):

        Log("Reading FLAC tags from: " + self.filename)
        try:
            tags = MFile(self.filename)
            Log("Found tags: " + str(tags.keys()))
        except:
            Log("An error occurred while attempting to parse the FLAC file: " + self.filename)
            return

        # Genres
        try:
            genres = tags.get("genre")
            if genres is not None and len(genres) > 0:
                metadata.genres.clear()
                for genre in genres:
                    for sub_genre in parse_genres(genre):
                        if sub_genre.strip():
                            metadata.genres.add(sub_genre.strip())
        except Exception, e:
            Log("Exception reading genre: " + str(e))
开发者ID:TGVarik,项目名称:LocalMedia.bundle,代码行数:23,代码来源:audiohelpers.py

示例5: unicode

# 需要导入模块: from mutagen import File [as 别名]
# 或者: from mutagen.File import keys [as 别名]
					except KeyError:
						artist = unicode("")
					try:
						album = data["album"][0].strip()
					except KeyError:
						album = unicode("")
					try:
						title = data["title"][0].strip()
					except KeyError:
						title = unicode("")
					duration = int(data.info.length)
					print (fp, artist, album, title, duration)
					cur.execute("insert into songs values(?,?,?,?,?)",(fp, artist, album, title, duration))
					con.commit()
				except KeyError:
					print fp,data.keys()
					raise

cur.execute("select artist,album, count(title) from songs group by artist,album having count(title)>2 and artist!=\"\"")
artists = {}
lower = {}
d = cur.fetchall()
#print d
for (artist, album,title) in d:
	if artist.lower() in lower:
		artist = lower[artist.lower()]
	if artist not in artists:
		artists[artist] = {}
		lower[artist.lower()] = artist
	artists[artist][album] = title
	
开发者ID:palfrey,项目名称:missing-albums,代码行数:32,代码来源:missing_albums.py

示例6: AudioFile

# 需要导入模块: from mutagen import File [as 别名]
# 或者: from mutagen.File import keys [as 别名]
class AudioFile(MutableMapping):
    """A simple class just for tag editing.

    No internal mutagen tags are exposed, or filenames or anything. So
    calling clear() won't destroy the filename field or things like
    that. Use it like a dict, then .write() it to commit the changes.
    When saving, tags that cannot be saved by the file format will be
    skipped with a debug message, since this is a common occurrance
    with MP3/M4A.

    Optional argument blacklist is a list of regexps matching
    non-transferrable tags. They will effectively be hidden, nether
    settable nor gettable.

    Or grab the actual underlying mutagen format object from the
    .data field and get your hands dirty.

    """
    def __init__(self, filename: str, blacklist: List[Pattern[str]]=[],
                 easy: bool=True) -> None:
        self.filename = filename
        self.data = MusicFile(self.filename, easy=easy)
        if self.data is None:
            raise ValueError("Unable to identify %s as a music file" % (repr(filename)))
        # Also exclude mutagen's internal tags
        self.blacklist = [ re.compile("^~") ] + blacklist
    def __getitem__(self, item: str) -> Any:
        if self.blacklisted(item):
            logger.debug("Attempted to get blacklisted key: %s." % repr(item))
        else:
            return self.data.__getitem__(item)
    def __setitem__(self, item: str, value: Any) -> None:
        if self.blacklisted(item):
            logger.debug("Attempted to set blacklisted key: %s." % repr(item))
        else:
            try:
                return self.data.__setitem__(item, value)
            except KeyError:
                logger.debug("Skipping unsupported tag %s for file type %s",
                             item, type(self.data))
    def __delitem__(self, item: str):
        if self.blacklisted(item):
            logger.debug("Attempted to del blacklisted key: %s." % repr(item))
        else:
            return self.data.__delitem__(item)
    def __len__(self) -> int:
        return len(list(self.keys()))
    def __iter__(self) -> Iterable[Any]:
        return iter(self.keys())

    def blacklisted(self, item: str) -> bool:
        """Return True if tag is blacklisted.

        Blacklist automatically includes internal mutagen tags (those
        beginning with a tilde)."""
        for regex in self.blacklist:
            if re.search(regex, item):
                return True
        else:
            return False
    def keys(self) -> Iterable[str]:
        return [ key for key in self.data.keys() if not self.blacklisted(key) ]
    def write(self) -> None:
        return self.data.save()
开发者ID:DarwinAwardWinner,项目名称:transfercoder,代码行数:66,代码来源:__init__.py

示例7: sorted

# 需要导入模块: from mutagen import File [as 别名]
# 或者: from mutagen.File import keys [as 别名]

# 3.: copy the tags and rename files

oldfiles = sorted(os.listdir(os.getcwd()))
for f in oldfiles:
	if not os.path.isfile(f):
		oldfiles.remove(f)
newfiles = sorted(glob.glob("abcde*/*.flac"))
if len(newfiles) != numfiles:
	print("Anzahl der Tracks stimmt nicht überein!")
	print(oldfiles)
	print("---")
	print(newfiles)
	sys.exit(1)
for i in range(len(oldfiles)):
	new_audio = File(newfiles[i])
	old_audio = File(oldfiles[i])
	for key in old_audio.keys():
		new_audio[key] = old_audio[key]
	new_audio.save()
	newname = oldfiles[i].rsplit(".",1)[0] + ".flac"
	os.rename(newfiles[i],newname)
	print("successfully tagged and renamed " + newname)

subprocess.call(["rm", "-rf"] + glob.glob("abcde*"))
ans = raw_input("Delete ogg files? [Y/n] ").strip()
if ans in "yYjJ" or ans == "":
	for f in oldfiles:
		os.remove(f)
开发者ID:supermihi,项目名称:littlehelpers,代码行数:31,代码来源:flacify.py


注:本文中的mutagen.File.keys方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。