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


Python OggVorbis.has_key方法代码示例

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


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

示例1: CopyTags

# 需要导入模块: from mutagen.oggvorbis import OggVorbis [as 别名]
# 或者: from mutagen.oggvorbis.OggVorbis import has_key [as 别名]
def CopyTags(source_file, target_file):
    o = OggVorbis(source_file)
    m = EasyID3(target_file)

    for key in ["artist", "title", "album", "date", "genre", "tracknumber"]:
        if o.has_key(key):
            m[key] = o[key]
    m.save()

    if o.has_key("discnumber"):
        m = MP3(target_file)
        m["TPOS"] = TPOS(encoding=3, text=o["discnumber"])
        m.save()
开发者ID:tbashore,项目名称:transcoder-scripts,代码行数:15,代码来源:oggtomp3.py

示例2: get_ogg_tag_info

# 需要导入模块: from mutagen.oggvorbis import OggVorbis [as 别名]
# 或者: from mutagen.oggvorbis.OggVorbis import has_key [as 别名]
def get_ogg_tag_info(f):
  global blankstr
  ret = {"file":f,"length":"0"}
  try:
    i = OggVorbis(f)
    ret["length"] = str(i.info.length)
    for k in ["artist", "album", "year", "tracknumber", "title"]:
      if i.has_key(k):
        ret[k] = str(i[k])
  except Exception, e:
    print("\r%s\rUnable to read OGG info for\n%s" %(blankstr, f))
    print(str(e))
开发者ID:qingfeng,项目名称:fappy,代码行数:14,代码来源:fappy.py

示例3: walk_audio_files

# 需要导入模块: from mutagen.oggvorbis import OggVorbis [as 别名]
# 或者: from mutagen.oggvorbis.OggVorbis import has_key [as 别名]
def walk_audio_files():
        
        tag_count = 0

	for root, dirs, files in os.walk('.'):
		for name in files:
                        
                        audio_set = False

			if name.lower().endswith(".mp3"):
                                try:
                                        audio = ID3(os.path.join(root, name))
                                except Exception, e:
                                        print 'ERROR: ID3 Error %s : %s' % (e, os.path.join(root, name))
                                        continue

				if not select_audio(audio):
					continue
				if tag_mode == TAG_MODE_NORMAL and audio.has_key('TPE1'):
					artist = audio["TPE1"]
					genre = artist_to_genre(artist[0])
					grouping = artist_to_groupings(artist[0])
					if genre != None:
						audio["TCON"] = TCON(encoding=3, text=genre)
                                                audio_set = True
					if grouping != None:
						audio["TIT1"] = TIT1(encoding=3, text=grouping)
                                                audio_set = True
				else:
					if audio.has_key("TIT1"):
						genre = refine_genre(audio["TIT1"].text[0].split(","))
						if genre != "":
							print "Refining genre for artist %s from %s to %s" % (audio["TPE1"].text[0], audio["TCON"].text[0], genre)
							audio["TCON"] = TCON(encoding=3, text=genre)
                                                        audio_set = True


                        elif name.lower().endswith(".ogg"):
                                try:
                                        audio = OggVorbis(os.path.join(root, name))
                                except Exception, e:
                                        print 'ERROR: Ogg Comment Error %s : %s' % (e, os.path.join(root, name))
                                        continue

                                if not audio.has_key('artist'):
                                        print 'ERROR: Vorbis comment has no "artist" key in file %s' % os.path.join(root, name)
                                        continue

                                artist = audio['artist']
                                genre = artist_to_genre(artist[0])
                                if genre != None:
                                        audio["genre"] = genre
                                        audio_set = True
开发者ID:Tecuya,项目名称:mp3tagger,代码行数:55,代码来源:tagger.py

示例4: test_ogg_file

# 需要导入模块: from mutagen.oggvorbis import OggVorbis [as 别名]
# 或者: from mutagen.oggvorbis.OggVorbis import has_key [as 别名]
    def test_ogg_file(self):
        ogg = OggVorbis(self.ogg_file)
        self.assertTrue(ogg.has_key('coverart'))
        self.assertTrue(ogg.has_key('coverartmime'))
        self.assertTrue(ogg.has_key('coverartdescription'))

        rm_ogg_cover(self.ogg_episode._episode)
        self.assertFalse(filecmp.cmp(self.ogg_file, self.ogg_file_save))

        ogg = OggVorbis(self.ogg_file)
        self.assertFalse(ogg.has_key('coverart'))
        self.assertFalse(ogg.has_key('coverartmime'))
        self.assertFalse(ogg.has_key('coverartdescription'))
开发者ID:AndreySV,项目名称:gpodder-hook-scripts,代码行数:15,代码来源:rm_ogg_cover_test.py

示例5: process_metadata

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

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

    # Posters
    valid_posters = []
    if tags.has_key('coverart'):
      for poster in tags['coverart']:
        poster_data = base64.standard_b64decode(poster)
        poster_name = hashlib.md5(poster_data).hexdigest()
        valid_posters.append(poster_name)
        if poster_name not in metadata.posters:
          Log('Adding embedded art from OGG file: ' + self.filename)
          metadata.posters[poster_name] = Proxy.Media(poster_data)
        else:
          Log('Skipping embedded art since its already added')

    return valid_posters
开发者ID:emandino,项目名称:LocalMedia.bundle,代码行数:24,代码来源:audiohelpers.py

示例6: __init__

# 需要导入模块: from mutagen.oggvorbis import OggVorbis [as 别名]
# 或者: from mutagen.oggvorbis.OggVorbis import has_key [as 别名]
class VorbisFile:
    def __init__(self, fn):
        self.config = config

        if fn is not None:
            self.SetFile(fn)

    def SetFile(self, fn):
        self.fn = fn
        self.filename = os.path.basename(self.fn)
        self.af = OggVorbis(self.fn)

    def read_comments(self):
        dic = {'title' : '',
               'artist' : '',
               'album' : '',
               'license' : '',
               'label' : '',
               'comment' : ''
              }
	for tag in self.af.keys():
	    tag = tag.lower()
            val = self.af.get(tag).pop(0)
            if val <> '': dic[tag] = val
        return dic

    def write_comments(self, metadata, userInfo, cache=1, removeSpool=0):
        '''
	Cache the file (copy it to a tmp dir) and write the tags there.
        '''

        logger.debug99("called VorbisFile.write_comments()")

        # now write the comments to file (self.af)
	dic = {}
	for tag in metadata:
	    tag = tag.lower()
            val = metadata[tag]

	    # build up metadata object together with audio file object
            if val != '':
                self.af[tag] = val
            else:
                logger.debug3("Not writing tag: %s (was left empty)" % tag)

	self.af.save()
        logger.debug3( "in VorbisFile.write_comments() Done! Wrote tags successfully to %s!" % self.fn )

        # FIXME : el ImportOGG en modo 'edit' es para que re-lea tags y actualice la DB
	#         pero no deberia ir dentro de la clase VorbisFile
        '''
        if not cache:
            logger.debug2("Should re-import/update: %s" % self.fn)
            ImportOGG(self, self.fn, userInfo, 'edit')
        '''
	return self.fn

    def getFilepath(self):
        return self.fn

    def getFilename(self):
        return self.filename

    def getTag(self, tag):
        if self.af.has_key(tag) and self.af[tag] is not '':
            return self.af.get(tag).pop(0)
        else: return ''

    def getLength(self):
        return self.af.info.length

    def getBitrate(self):
        return self.af.info.bitrate

    def getSamplerate(self):
        return self.af.info.sample_rate

    def getInfo(self):
	'''Available info (for OGG/Vorbis) is:  channels, bitrate, serial, sample_rate, length'''
        return self.af.info

    def listTags(self):
        return self.af.keys()

    def getSize(self):
        return os.stat(self.fn).st_size
开发者ID:Xicnet,项目名称:burnstation,代码行数:88,代码来源:VorbisFile.py

示例7: cleanAllTags

# 需要导入模块: from mutagen.oggvorbis import OggVorbis [as 别名]
# 或者: from mutagen.oggvorbis.OggVorbis import has_key [as 别名]
    def cleanAllTags(self, db, element, path_normalizado):
        """ Method to clean all rating and playcount tags from the file"""
        try:
            # Get the audio tagging format of the current element
            format = self._check_recognized_format(path_normalizado)
            if format is None:
                raise Exception("Unrecognized format")
            else:
                needsave = False
                if format == "id3v2":
                    audio = ID3(path_normalizado)
                    if audio.has_key("POPM"):
                        audio.delall("POPM")
                        needsave = True
                    if audio.has_key("PCNT"):
                        audio.delall("PCNT")
                        needsave = True
                    if audio.has_key(u"TXXX:FMPS_Rating"):
                        audio.delall(u"TXXX:FMPS_Rating")
                        needsave = True
                    if audio.has_key(u"TXXX:FMPS_Playcount"):
                        audio.delall(u"TXXX:FMPS_Playcount")
                        needsave = True

                elif format == "oggvorbis":
                    audio = OggVorbis(path_normalizado)
                    if audio.has_key("FMPS_RATING"):
                        del audio["FMPS_RATING"]
                        needsave = True
                    if audio.has_key("FMPS_PLAYCOUNT"):
                        del audio["FMPS_PLAYCOUNT"]
                        needsave = True

                elif format == "flac":
                    audio = FLAC(path_normalizado)
                    if audio.has_key("FMPS_RATING"):
                        del audio["FMPS_RATING"]
                        needsave = True
                    if audio.has_key("FMPS_PLAYCOUNT"):
                        del audio["FMPS_PLAYCOUNT"]
                        needsave = True

                elif format == "mp4":
                    audio = MP4(path_normalizado)
                    if audio.has_key("----:com.apple.iTunes:FMPS_Rating"):
                        del audio["----:com.apple.iTunes:FMPS_Rating"]
                        needsave = True
                    if audio.has_key("----:com.apple.iTunes:FMPS_Playcount"):
                        del audio["----:com.apple.iTunes:FMPS_Playcount"]
                        needsave = True

                elif format == "musepack":
                    audio = Musepack(path_normalizado)
                    if audio.has_key("FMPS_RATING"):
                        del audio["FMPS_RATING"]
                        needsave = True
                    if audio.has_key("FMPS_PLAYCOUNT"):
                        del audio["FMPS_PLAYCOUNT"]
                        needsave = True

                elif format == "oggspeex":
                    audio = OggSpeex(path_normalizado)
                    if audio.has_key("FMPS_RATING"):
                        del audio["FMPS_RATING"]
                        needsave = True
                    if audio.has_key("FMPS_PLAYCOUNT"):
                        del audio["FMPS_PLAYCOUNT"]
                        needsave = True

                if needsave:
                    audio.save()
                    self.num_cleaned += 1
                else:
                    self.num_already_done += 1

        except Exception, e:
            self.num_failed += 1
            print(e, path_normalizado)
开发者ID:phoolish,项目名称:saveTAGRating,代码行数:80,代码来源:__init__.py


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