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


Python FLAC.items方法代码示例

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


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

示例1: copy_tags

# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import items [as 别名]
def copy_tags(filejoin, filenames):
    """ Copia los tags de filenames a join """
    extension = os.path.splitext(filejoin)[1]

    if extension == '.flac':
        tags_ori = FLAC(filenames[0])
        tags_joi = FLAC(filejoin)
    elif extension == '.ogg':
        tags_ori = OggVorbis(filenames[0])
        tags_joi = OggVorbis(filejoin)
    else:
        return

    for item in tags_ori.items():
        tags_joi[item[0]] = item[1]

    # falta añadir lo del título... pero primero lo borramos
    for ori in filenames[1:]:
        if extension == '.flac':
            tags_ori = FLAC(ori)
        elif extension == '.ogg':
            tags_ori = OggVorbis(ori)

        last_track = tags_ori['tracknumber']
        last_discnumber = tags_ori['discnumber']
        print tags_ori['title']
        tags_joi['title'] = tags_joi['title'] + tags_ori['title']

    tags_joi['gapless_join'] = str(len(filenames))
    tags_joi['gapless_last_track'] = last_track
    tags_joi['gapless_last_discnumber'] = last_discnumber

    tags_joi.save()
开发者ID:penicolas,项目名称:scripts,代码行数:35,代码来源:gapless.py

示例2: main

# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import items [as 别名]
def main(args):
    """
    """
    # This is nonsense, don't need to pass that argument twice
    scanner = scan.Scanner()

    if not scanner.scan_album(args.album):
        sys.stderr.write('Invalid Album!\n')
        sys.exit(1)

    # Construct an album representation
    # (This function will be moved to the lib)
    m = const.REGEX_ALBUM_FOLDER.match(args.album).groupdict()
    if not m:
        # A bit reduntant, but better safe than sorry
        sys.stderr.write("Could not read album folder\n")
        sys.exit(1)

    files = map(lambda fn: os.path.join(args.album, fn),
                sorted(filter(const.REGEX_TRACK_FILENAME.match,
                              os.listdir(args.album)
                       )
                )
    )
    show = ''
    for fn in files:
        audio = FLAC(fn)
        # Maybe create a util function for this purpose
        audio_dict = dict([(k,v[0]) for k,v in audio.items()])
        show += TPL_TRACK_SHOW.format(**audio_dict)
    head = TPL_ALBUM_SHOW.format(**audio_dict)
    show = head + TPL_SEPARATOR(len(head)-1) + show
    print show.strip('\n')
开发者ID:rseed42,项目名称:music-collection-tools,代码行数:35,代码来源:__init__.py

示例3: main

# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import items [as 别名]
def main():
    # get command line options
    options = get_options()
    bitrate = options.bitrate
    source_dir = re.sub('\/+$', '', options.flac_dir)

    # Process files in directory specified via -d option (not recursive).
    flac_meta = {}
    for file in glob.iglob("%s/*.flac" % source_dir):
        raw_flac_meta = FLAC(file)

        # meta data allows for multiple items per tag key; hence the
        # join()
        flac_meta = {}
        for k, v in raw_flac_meta.items():
            flac_meta[k] = ' '.join(v).encode(DEFAULT_ENCODING, 'replace')    

        create_ogg_vorbis(flac_meta, file, bitrate)
开发者ID:ryant71,项目名称:FLAC-to-Ogg-Vorbis-Converter,代码行数:20,代码来源:flac2ogg.py

示例4: TFLAC

# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import items [as 别名]
class TFLAC(TestCase):
    SAMPLE = os.path.join("tests", "data", "silence-44-s.flac")
    NEW = SAMPLE + ".new"
    def setUp(self):
        shutil.copy(self.SAMPLE, self.NEW)
        self.failUnlessEqual(open(self.SAMPLE).read(), open(self.NEW).read())
        self.flac = FLAC(self.NEW)

    def test_delete(self):
        self.failUnless(self.flac.tags)
        self.flac.delete()
        self.failIf(self.flac.tags)
        flac = FLAC(self.NEW)
        self.failIf(flac.tags)

    def test_module_delete(self):
        delete(self.NEW)
        flac = FLAC(self.NEW)
        self.failIf(flac.tags)

    def test_info(self):
        self.failUnlessAlmostEqual(FLAC(self.NEW).info.length, 3.7, 1)

    def test_keys(self):
        self.failUnlessEqual(self.flac.keys(), self.flac.tags.keys())

    def test_values(self):
        self.failUnlessEqual(self.flac.values(), self.flac.tags.values())

    def test_items(self):
        self.failUnlessEqual(self.flac.items(), self.flac.tags.items())

    def test_vc(self):
        self.failUnlessEqual(self.flac['title'][0], 'Silence')

    def test_write_nochange(self):
        f = FLAC(self.NEW)
        f.save()
        self.failUnlessEqual(open(self.SAMPLE).read(), open(self.NEW).read())

    def test_write_changetitle(self):
        f = FLAC(self.NEW)
        f["title"] = "A New Title"
        f.save()
        f = FLAC(self.NEW)
        self.failUnlessEqual(f["title"][0], "A New Title")

    def test_write_changetitle_unicode_value(self):
        f = FLAC(self.NEW)
        f["title"] = u"A Unicode Title \u2022"
        f.save()
        f = FLAC(self.NEW)
        self.failUnlessEqual(f["title"][0], u"A Unicode Title \u2022")

    def test_write_changetitle_unicode_key(self):
        f = FLAC(self.NEW)
        f[u"title"] = "A New Title"
        f.save()
        f = FLAC(self.NEW)
        self.failUnlessEqual(f[u"title"][0], "A New Title")

    def test_write_changetitle_unicode_key_and_value(self):
        f = FLAC(self.NEW)
        f[u"title"] = u"A Unicode Title \u2022"
        f.save()
        f = FLAC(self.NEW)
        self.failUnlessEqual(f[u"title"][0], u"A Unicode Title \u2022")

    def test_force_grow(self):
        f = FLAC(self.NEW)
        f["faketag"] = ["a" * 1000] * 1000
        f.save()
        f = FLAC(self.NEW)
        self.failUnlessEqual(f["faketag"], ["a" * 1000] * 1000)

    def test_force_shrink(self):
        self.test_force_grow()
        f = FLAC(self.NEW)
        f["faketag"] = "foo"
        f.save()
        f = FLAC(self.NEW)
        self.failUnlessEqual(f["faketag"], ["foo"])

    def test_add_vc(self):
        f = FLAC(os.path.join("tests", "data", "no-tags.flac"))
        self.failIf(f.tags)
        f.add_tags()
        self.failUnless(f.tags == [])
        self.failUnlessRaises(ValueError, f.add_tags)

    def test_add_vc_implicit(self):
        f = FLAC(os.path.join("tests", "data", "no-tags.flac"))
        self.failIf(f.tags)
        f["foo"] = "bar"
        self.failUnless(f.tags == [("foo", "bar")])
        self.failUnlessRaises(ValueError, f.add_tags)

    def test_ooming_vc_header(self):
        # issue 112: Malformed FLAC Vorbis header causes out of memory error
        # http://code.google.com/p/mutagen/issues/detail?id=112
#.........这里部分代码省略.........
开发者ID:andrewboie,项目名称:discogstool,代码行数:103,代码来源:test_flac.py

示例5: TFLAC

# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import items [as 别名]

#.........这里部分代码省略.........
        self.assertFalse(self.flac.tags)
        flac = FLAC(self.NEW)
        self.assertTrue(flac.tags is None)

    def test_delete_change_reload(self):
        self.flac.delete()
        self.flac.tags["FOO"] = ["BAR"]
        self.flac.save()
        assert FLAC(self.flac.filename)["FOO"] == ["BAR"]

        # same with delete failing due to IO etc.
        with pytest.raises(MutagenError):
            self.flac.delete(os.devnull)
        self.flac.tags["FOO"] = ["QUUX"]
        self.flac.save()
        assert FLAC(self.flac.filename)["FOO"] == ["QUUX"]

    def test_module_delete(self):
        delete(self.NEW)
        flac = FLAC(self.NEW)
        self.failIf(flac.tags)

    def test_info(self):
        self.failUnlessAlmostEqual(FLAC(self.NEW).info.length, 3.7, 1)

    def test_keys(self):
        self.failUnlessEqual(
            list(self.flac.keys()), list(self.flac.tags.keys()))

    def test_values(self):
        self.failUnlessEqual(
            list(self.flac.values()), list(self.flac.tags.values()))

    def test_items(self):
        self.failUnlessEqual(
            list(self.flac.items()), list(self.flac.tags.items()))

    def test_vc(self):
        self.failUnlessEqual(self.flac['title'][0], 'Silence')

    def test_write_nochange(self):
        f = FLAC(self.NEW)
        f.save()
        with open(self.SAMPLE, "rb") as a:
            with open(self.NEW, "rb") as b:
                self.failUnlessEqual(a.read(), b.read())

    def test_write_changetitle(self):
        f = FLAC(self.NEW)
        if PY3:
            self.assertRaises(
                TypeError, f.__setitem__, b'title', b"A New Title")
        else:
            f[b"title"] = b"A New Title"
            f.save()
            f = FLAC(self.NEW)
            self.failUnlessEqual(f[b"title"][0], b"A New Title")

    def test_write_changetitle_unicode_value(self):
        f = FLAC(self.NEW)
        if PY3:
            self.assertRaises(
                TypeError, f.__setitem__, b'title', u"A Unicode Title \u2022")
        else:
            f[b"title"] = u"A Unicode Title \u2022"
            f.save()
开发者ID:quodlibet,项目名称:mutagen,代码行数:70,代码来源:test_flac.py

示例6: FLAC

# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import items [as 别名]
          print "  Converting file  " + sFileBase + sFileExt + " to " + dDir
          command = "sox \"" +sFile + "\" \"" + dFile + "\""
          print "  " + command
          os.popen(command)

      #Read flac tags from FLAC file
        flacTags = FLAC(sFile)
        try:
          mp3 = MP3(dFile)
        except:
          print( dFile + "does not exist, or cannot be opened as mp3")
          break
        
        iso = 'iso-8859-1'
  
        for key, value in flacTags.items():
          if   key == 'album':        mp3['TALB']=mutagen.id3.TALB(encoding=3,text=[value[0]])
          elif key == 'artist':       mp3['TPE1']=mutagen.id3.TPE1(encoding=3,text=[value[0]])
          elif key == 'title':        mp3['TIT2']=mutagen.id3.TIT2(encoding=3,text=[value[0]])
          elif key == 'albumartist':  mp3['TPE2']=mutagen.id3.TPE2(encoding=3,text=[value[0]])
          elif key == 'album artist': mp3['TPE2']=mutagen.id3.TPE2(encoding=3,text=[value[0]])
          elif key == 'date':         mp3['TYER']=mutagen.id3.TYER(encoding=3,text=[value[0]])
          elif key == 'tracknumber':  mp3['TRCK']=mutagen.id3.TRCK(encoding=3,text=[value[0]])
          mp3.save() 
      
      # Get the picture tag from the flac file and store it
      # in the flac dir and the mp3 dir and the mp3 file.
        pictures = flacTags.pictures
        noOfPictures = 0
        for pic in pictures:
          noOfPictures = noOfPictures + 1
开发者ID:MiLeW,项目名称:syncflac,代码行数:33,代码来源:sync_flac.py

示例7: FLAC

# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import items [as 别名]
                value = first_track[org_key]
                album_meta_dict[new_key] = value

        # Let's generate some album-level YAML metadata files!
        album_yaml = yaml.dump(album_meta_dict)
        dst_album_meta_file_path = dst_album_dir_path / "directory.yml"
        with dst_album_meta_file_path.open(mode='w') as f:
            f.write(album_yaml)

        # For each FLAC file, read its tags
        track_meta_dicts = []
        for src_track_path in src_track_paths:
            track_file_name = src_track_path.name
            track = FLAC(str(src_track_path))
            track_meta_dict = {}
            for tag, value in track.items():
                # Skip album level tags
                if tag in album_tags:
                    continue
                # Skip ignored tags
                if tag in ignored:
                    continue
                if tag in track_tag_renames:
                    tag = track_tag_renames[tag]
                track_meta_dict[tag] = value
            track_meta_dicts.append(track_meta_dict)

            dst_track_file_path = dst_album_dir_path / track_file_name
            dst_track_file_path.touch(exist_ok=True)

        tracks_yaml = yaml.dump(track_meta_dicts)
开发者ID:ThatsGobbles,项目名称:tigz,代码行数:33,代码来源:yaml_generator.py


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