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


Python FLAC.add_picture方法代码示例

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


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

示例1: test_get_images

# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import add_picture [as 别名]
    def test_get_images(self):
        pic = Picture()
        pic.data = _get_jpeg()
        pic.type = APICType.COVER_FRONT
        b64pic_cover = base64.b64encode(pic.write())

        # metadata_block_picture
        song = FLAC(self.filename)
        song["metadata_block_picture"] = [b64pic_cover]
        song.save()

        song = FLACFile(self.filename)
        self.assertEqual(len(song.get_images()), 1)
        self.assertEqual(song.get_images()[0].type, APICType.COVER_FRONT)

        # flac Picture
        song = FLAC(self.filename)
        pic = Picture()
        pic.data = _get_jpeg()
        pic.type = APICType.COVER_BACK
        song.add_picture(pic)
        song.save()

        song = FLACFile(self.filename)
        self.assertEqual(len(song.get_images()), 2)
        self.assertEqual(song.get_images()[-1].type, APICType.COVER_BACK)
开发者ID:mistotebe,项目名称:quodlibet,代码行数:28,代码来源:test_formats_xiph.py

示例2: test_add_picture

# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import add_picture [as 别名]
 def test_add_picture(self):
     f = FLAC(self.NEW)
     c = len(f.pictures)
     f.add_picture(Picture())
     f.save()
     f = FLAC(self.NEW)
     self.failUnlessEqual(len(f.pictures), c + 1)
开发者ID:andrewboie,项目名称:discogstool,代码行数:9,代码来源:test_flac.py

示例3: set_image

# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import add_picture [as 别名]
    def set_image(self, image):
        """Replaces all embedded images by the passed image"""

        with translate_errors():
            tag = FLAC(self["~filename"])

        try:
            data = image.read()
        except EnvironmentError as e:
            raise AudioFileError(e)

        pic = Picture()
        pic.data = data
        pic.type = APICType.COVER_FRONT
        pic.mime = image.mime_type
        pic.width = image.width
        pic.height = image.height
        pic.depth = image.color_depth

        tag.add_picture(pic)

        with translate_errors():
            tag.save()

        # clear vcomment tags
        super(FLACFile, self).clear_images()

        self.has_images = True
开发者ID:zsau,项目名称:quodlibet,代码行数:30,代码来源:xiph.py

示例4: setImage

# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import add_picture [as 别名]
	def setImage(self, song):
		audio = FLAC(song.get("~filename", ""))
		if len(self.imgFiles) <= 0:
			return

		for p in self.imgFiles:
			try:
				audio.add_picture(p)
			except:
				printError()
				return False
		audio.save()
		## and now count the images
		count = "0"
		## if file has no images -> set to 0
		if (audio.pictures is None) or (len(audio.pictures) <= 0):
			pass
		else:
			count = str(len(audio.pictures))

		if not "pictures" in song:
			song["pictures"] = count

		if song["pictures"] <> count:
			song["pictures"] = count
		app.window.emit("artwork-changed", [song])
		return
开发者ID:claw-strophobic,项目名称:dacapo,代码行数:29,代码来源:addImage.py

示例5: test_largest_valid

# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import add_picture [as 别名]
 def test_largest_valid(self):
     f = FLAC(self.filename)
     pic = Picture()
     pic.data = b"\x00" * (2 ** 24 - 1 - 32)
     self.assertEqual(len(pic.write()), 2 ** 24 - 1)
     f.add_picture(pic)
     f.save()
开发者ID:quodlibet,项目名称:mutagen,代码行数:9,代码来源:test_flac.py

示例6: on_save

# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import add_picture [as 别名]
	def on_save(self):
		audio = FLAC(self.song.get("~filename", ""))
		## if file has no images -> leave
		if (audio.pictures is None) or (len(audio.pictures) <= 0):
			return
		## first,clear all pictures, then add the images in order
		try:
			audio.clear_pictures()
		except:
			self.printError()
			return False
		for row in self.liststore:
			img = row[1]
			try:
				audio.add_picture(img)
			except:
				self.printError()
				return False
		audio.save()
		count = 0
		if (audio.pictures is None) or (len(audio.pictures) <= 0):
			pass
		else:
			count = str(len(audio.pictures))

		self.song["pictures"] = count
		app.window.emit("artwork-changed", [self.song])
		del self.coverlist[:]
		self.liststore.clear()
		self.start_search()
		return True
开发者ID:claw-strophobic,项目名称:dacapo,代码行数:33,代码来源:displayImages.py

示例7: test_write_tags

# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import add_picture [as 别名]
def test_write_tags(tmpdir):
    """Test writing tags from a FLAC to mp3 file."""
    # Prepare.
    flac = tmpdir.mkdir('flac').join('song.flac').ensure(file=True)
    mp3 = tmpdir.mkdir('mp3').join('song.mp3').ensure(file=True)
    with open(os.path.join(os.path.dirname(__file__), '1khz_sine.flac'), 'rb') as f:
        flac.write(f.read(), 'wb')
    with open(os.path.join(os.path.dirname(__file__), '1khz_sine.mp3'), 'rb') as f:
        mp3.write(f.read(), 'wb')
    flac, mp3 = str(flac.realpath()), str(mp3.realpath())
    tags = FLAC(flac)
    tags.update(dict(artist='Artist2', date='2012', album='Album', tracknumber='01', title='Title', unsyncedlyrics='L'))
    image = Picture()
    image.type, image.mime = 3, 'image/jpeg'
    with open(os.path.join(os.path.dirname(__file__), '1_album_art.jpg'), 'rb') as f:
        image.data = f.read()
    tags.add_picture(image)
    tags.save()
    # Test.
    ConvertFiles.write_tags(flac, mp3)
    # Check.
    id3 = ID3(mp3)
    assert 'Artist2' == id3['TPE1']
    assert '2012' == id3['TDRC']
    assert 'Album' == id3['TALB']
    assert '01' == id3['TRCK']
    assert 'Title' == id3['TIT2']
    assert 'L' == id3["USLT:Lyrics:'eng'"].text
    with open(os.path.join(os.path.dirname(__file__), '1_album_art.jpg'), 'rb') as f:
        assert f.read() == id3['APIC:'].data
    assert ({}, [], [], []) == find_files(str(tmpdir.join('flac')), str(tmpdir.join('mp3')))
开发者ID:Robpol86,项目名称:general,代码行数:33,代码来源:test_convertfiles_write_tags.py

示例8: export_digital

# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import add_picture [as 别名]
def export_digital(item):
    """ Export and/or split digital files for an item (parallelized) """
    logging.warning('{0} -> {1}'.format(item.name, DIGITAL_FOLDER))
    if 'std' in item.option:        
        if JUST_ADD_TAGS:
            if item.digital_ext == 'mp3':
                mutagen_audio = EasyID3(item.digital_file_path)    
            elif item.digital_ext == 'flac':
                mutagen_audio = FLAC(item.digital_file_path)
            else:
                raise Exception('Format {0} not recognized for item {1}.'.format(item.digital_ext, item.name))
            mutagen_audio['title'] = item.album
            mutagen_audio['artist'] = item.artist
            mutagen_audio['albumartist'] = item.artist
            mutagen_audio['album'] = item.album
            mutagen_audio.save()
        else:
            # Export audio file
            digital_file = AudioSegment.from_wav(item.path)
            digital_file.export(out_f=item.digital_file_path, format=item.digital_ext, bitrate='192k', tags={
                'title':(item.album or item.artist), 'artist':item.artist, 'albumartist':item.artist, 'album':(item.album or item.artist)})
        # Add cover art
        if item.thumb and (item.digital_ext == 'mp3'):
            mutagen_audio = MP3(item.digital_file_path, ID3=ID3)
            try:
                # Add ID3 tag if it doesn't exist
                mutagen_audio.add_tags()
            except error:
                pass
            mutagen_audio.tags.add(
                APIC(
                    encoding=3, # 3 is for utf-8
                    mime='image/jpeg', # image/jpeg or image/png
                    type=3, # 3 is for the cover image
                    desc=u'Cover',
                    data=open(item.thumb_path, 'rb').read()
                )
            )            
            mutagen_audio.save()
        elif item.thumb and (item.digital_ext == 'flac'):
            mutagen_audio = File(item.digital_file_path)
            flac_image = Picture()
            flac_image.type = 3
            mime = 'image/jpeg'
            flac_image.desc = 'Cover'
            with open(item.thumb_path, 'rb') as f:
                flac_image.data = f.read()
            mutagen_audio.add_picture(flac_image)
            mutagen_audio.save()
        else:
            logging.warning('No cover found for item {0}'.format(item.name))
        if JUST_ADD_TAGS:
            os.rename(item.digital_file_path, item.digital_rename_path)
        if DROPBOX_COPY:
            # Copy finished digital file to Dropbox order folder
            shutil.copy2(item.digital_file_path, item.dropbox_order_folder)
    # Deluxe / 45
    else:        
        split.split_item(item, DIGITAL_FOLDER, DROPBOX_COPY)
开发者ID:broxeph,项目名称:ameryn,代码行数:61,代码来源:print-labels-5+-+tweaks.py

示例9: handle_audio_file

# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import add_picture [as 别名]
def handle_audio_file(audio_file):
    print('Handling audio file', audio_file)
    extension = os.path.splitext(os.path.basename(audio_file))[1]
    if extension == '.mp3':
        mp3 = MP3(audio_file, ID3=ID3)
        print(list(dict(mp3).keys()))
        if not regex_list(dict(mp3).keys(), re.compile('[Aa][Pp][Ii][Cc].*')):
            artist = mp3['TPE1'][0]
            album = mp3['TALB'][0]
            cover_data = open(get_cover_art(artist, album, audio_file), mode='rb')
            apic = APIC()
            apic.encoding = 3
            apic.mime = 'image/jpg'
            apic.type = PictureType.COVER_FRONT
            apic.desc = u'Cover'
            apic.data = cover_data.read()
            cover_data.close()
            print('Adding cover art', cover_data.name, '->', audio_file)
            mp3['APIC'] = apic
            mp3.save()
        else:
            print(audio_file, 'already has cover artwork.')
    elif extension == '.m4a' or extension is '.aac':
        m4a = MP4(audio_file)
        print(list(dict(m4a).keys()))
        if 'covr' not in m4a:
            artist = m4a['\xa9ART'][0]
            album = m4a['\xa9alb'][0]
            cover_data = open(get_cover_art(artist, album, audio_file), mode='rb')
            covr = MP4Cover()
            covr.imageformat = AtomDataType.JPEG
            covr.data = cover_data.read()
            cover_data.close()
            print('Adding cover art', cover_data.name, '->', audio_file)
            m4a['covr'] = [covr]
            m4a.save()
        else:
            print(audio_file, 'already has cover artwork.')
    elif extension == '.flac':
        flac = FLAC(audio_file)
        print(list(dict(flac).keys()))
        if not flac.pictures:
            artist = flac['artist'][0]
            album = flac['album'][0]
            cover_data = open(get_cover_art(artist, album, audio_file), mode='rb')
            picture = Picture()
            picture.type = 3
            picture.mime = 'image/jpg'
            picture.desc = u'Cover'
            picture.data = cover_data.read()
            cover_data.close()
            print('Adding cover artwork', cover_data.name, '->', audio_file)
            flac.add_picture(picture)
            flac.save()
        else:
            print(audio_file, 'already has cover artwork.')
    move_or_overwrite(audio_file, dest_audio, os.path.join(dest_audio, os.path.basename(audio_file)))
开发者ID:maximberezin97,项目名称:AutoMoveFiles,代码行数:59,代码来源:AutoMoveFiles.py

示例10: embed_cover_art

# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import add_picture [as 别名]
    def embed_cover_art(self, audio_file, cover_file):
        """Embeds cover art into an audio file.

		Arguments:
			audio_file (str): The path to the audio file to embed the artwork in.
			cover_file (str): The path to the artwork file to embed.
		"""
        if path.isfile(audio_file) and path.isfile(cover_file):
            mimetype = "image/png" if cover_file.endswith("png") else "image/jpeg"
            artwork = open(cover_file, "rb").read()
            desc = u"Cover Art"

            # Determine which filetype we're handling
            if audio_file.endswith("m4a"):
                audio = MP4(audio_file)

                covr = []
                if cover_file.endswith("png"):
                    covr.append(MP4Cover(artwork, MP4Cover.FORMAT_PNG))
                else:
                    covr.append(MP4Cover(artwork, MP4Cover.FORMAT_JPEG))

                audio.tags["covr"] = covr
            elif audio_file.endswith("mp3"):
                audio = MP3(audio_file, ID3=ID3)

                # Add ID3 tags if they don't exist
                try:
                    audio.add_tags()
                except error:
                    pass

                audio.tags.add(
                    APIC(
                        encoding=3,  # 3 is UTF-8
                        mime=mimetype,
                        type=3,  # 3 is for cover artwork
                        desc=desc,
                        data=artwork,
                    )
                )
            elif audio_file.endswith("flac"):
                audio = FLAC(audio_file)

                image = Picture()
                image.type = 3  # 3 is for cover artwork
                image.mime = mimetype
                image.desc = desc
                image.data = artwork

                audio.clear_pictures()  # Clear existing pictures
                audio.add_picture(image)

                # Save the audio file
        audio.save()
开发者ID:nejsan,项目名称:sound_bubble,代码行数:57,代码来源:musicgen.py

示例11: test_get_image

# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import add_picture [as 别名]
    def test_get_image(self):
        data = b"abc"
        song = FLAC(self.filename)
        pic = Picture()
        pic.data = data
        song.add_picture(pic)
        song.save()

        song = FLACFile(self.filename)
        self.failUnless(song("~picture"))
        fn = song.get_primary_image().file
        self.failUnlessEqual(fn.read(), pic.data)
开发者ID:bernd-wechner,项目名称:quodlibet,代码行数:14,代码来源:test_formats_xiph.py

示例12: test_picture

# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import add_picture [as 别名]
    def test_picture(self):
        data = "abc"
        song = FLAC(self.filename)
        pic = Picture()
        pic.data = data
        song.add_picture(pic)
        song.save()

        song = FLACFile(self.filename)
        self.failUnless(song("~picture"))
        fn = song.find_cover()
        self.failUnlessEqual(fn.read(), pic.data)
开发者ID:silkecho,项目名称:glowing-silk,代码行数:14,代码来源:test_formats_xiph.py

示例13: test_clear_images

# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import add_picture [as 别名]
    def test_clear_images(self):
        data = "abc"
        song = FLAC(self.filename)
        pic = Picture()
        pic.data = data
        song.add_picture(pic)
        song.save()

        song = FLACFile(self.filename)
        self.assertTrue(song.get_primary_image())
        song.clear_images()
        song.clear_images()
        song = FLACFile(self.filename)
        self.assertFalse(song.get_primary_image())
开发者ID:mistotebe,项目名称:quodlibet,代码行数:16,代码来源:test_formats_xiph.py

示例14: AddImages

# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import add_picture [as 别名]
    def AddImages(self):
        MadeUrls = []
        MadeUrlsResults = []
        QueriedImagesKeys = self.QueriedImages.keys()
        QueriedImagesKeys.sort()
        for flacPath in QueriedImagesKeys:
            index = -1
            for Query in self.QueriedImages[flacPath]:
                try:
                    index = MadeUrls.index(Query)
                except ValueError:
                    #print ' filling --- cache %s:%s' % (Query,flacPath)
                    #print MadeUrls
                    try:
                        #print "Query=%s,%s" % (Query,type(Query))

                        data = urllib2.urlopen(Query  )
                    except urllib2.URLError:
                        print "Could not open URL: %s for file : %s" % (Query,flacPath)
                        continue
                    MadeUrls.append(Query)
                    MadeUrlsResults.append(data.read())
                    index = MadeUrls.index(Query)
            if index == -1:
                # we had succesfull urls for this file
                continue
            if len(MadeUrlsResults[index]) == 0:
                # we had no data
                continue
            #print ' have %s for %s' % (Query,flacPath)
            try:
                metadata = FLAC(flacPath)
            except FLACNoHeaderError as (strerror):
                print strerror
                continue
            if pict_test(metadata):
                print "Already has cover are:%s" % (flacPath)
                continue
            image = Picture()
            image.type = 3
            image.desc = 'front cover'
            if Query.endswith('png'):
                mime = 'image/png'
            if Query.endswith('jpg'):
                mime = 'image/jpeg'
            image.data = MadeUrlsResults[index]
            metadata.add_picture(image)
            metadata.save()
开发者ID:osynge,项目名称:mutart,代码行数:50,代码来源:mutart.py

示例15: test_art_lyrics

# 需要导入模块: from mutagen.flac import FLAC [as 别名]
# 或者: from mutagen.flac.FLAC import add_picture [as 别名]
def test_art_lyrics(tmpdir):
    """Test when everything is valid."""
    flac_dir = tmpdir.mkdir('flac')
    flac = flac_dir.join('Artist2 - 2012 - Album - 01 - Title.flac').ensure(file=True)
    with open(os.path.join(os.path.dirname(__file__), '1khz_sine.flac'), 'rb') as f:
        flac.write(f.read(), 'wb')
    tags = FLAC(str(flac.realpath()))
    tags.update(dict(artist='Artist2', date='2012', album='Album', tracknumber='01', title='Title', unsyncedlyrics='L'))
    image = Picture()
    image.type, image.mime = 3, 'image/jpeg'
    with open(os.path.join(os.path.dirname(__file__), '1_album_art.jpg'), 'rb') as f:
        image.data = f.read()
    tags.add_picture(image)
    tags.save()
    a_messages = find_inconsistent_tags([str(flac.realpath())], False, False)
    assert {} == a_messages
开发者ID:Robpol86,项目名称:general,代码行数:18,代码来源:test_find_inconsistent_tags.py


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