Esempio n. 1
0
def _audio_tmed(atuple):
    audio, atag, advanced, _, _ = atuple
    if advanced:
        param = ast.literal_eval(atag)
        audio.add(TMED(3, param[1]))
    else:
        audio.add(TMED(3, atag))
Esempio n. 2
0
 def __init_id3_tags(id3, major=3):
     """
     Attributes:
         id3 ID3 Tag object
         major ID3 major version, e.g.: 3 for ID3v2.3
     """
     from mutagen.id3 import TRCK, TPOS, TXXX, TPUB, TALB, UFID, TPE2, \
         TSO2, TMED, TIT2, TPE1, TSRC, IPLS, TORY, TDAT, TYER
     id3.add(TRCK(encoding=major, text="1/10"))
     id3.add(TPOS(encoding=major, text="1/1"))
     id3.add(
         TXXX(encoding=major,
              desc="MusicBrainz Release Group Id",
              text="e00305af-1c72-469b-9a7c-6dc665ca9adc"))
     id3.add(TXXX(encoding=major, desc="originalyear", text="2011"))
     id3.add(
         TXXX(encoding=major, desc="MusicBrainz Album Type", text="album"))
     id3.add(
         TXXX(encoding=major,
              desc="MusicBrainz Album Id",
              text="e7050302-74e6-42e4-aba0-09efd5d431d8"))
     id3.add(TPUB(encoding=major, text="J&R Adventures"))
     id3.add(TXXX(encoding=major, desc="CATALOGNUMBER", text="PRAR931391"))
     id3.add(TALB(encoding=major, text="Don\'t Explain"))
     id3.add(
         TXXX(encoding=major,
              desc="MusicBrainz Album Status",
              text="official"))
     id3.add(TXXX(encoding=major, desc="SCRIPT", text="Latn"))
     id3.add(
         TXXX(encoding=major,
              desc="MusicBrainz Album Release Country",
              text="US"))
     id3.add(TXXX(encoding=major, desc="BARCODE", text="804879313915"))
     id3.add(
         TXXX(encoding=major,
              desc="MusicBrainz Album Artist Id",
              text=[
                  "3fe817fc-966e-4ece-b00a-76be43e7e73c",
                  "984f8239-8fe1-4683-9c54-10ffb14439e9"
              ]))
     id3.add(TPE2(encoding=major, text="Beth Hart & Joe Bonamassa"))
     id3.add(TSO2(encoding=major, text="Hart, Beth & Bonamassa, Joe"))
     id3.add(TXXX(encoding=major, desc="ASIN", text="B005NPEUB2"))
     id3.add(TMED(encoding=major, text="CD"))
     id3.add(
         UFID(encoding=major,
              owner="http://musicbrainz.org",
              data=b"f151cb94-c909-46a8-ad99-fb77391abfb8"))
     id3.add(TIT2(encoding=major, text="Sinner's Prayer"))
     id3.add(
         TXXX(encoding=major,
              desc="MusicBrainz Artist Id",
              text=[
                  "3fe817fc-966e-4ece-b00a-76be43e7e73c",
                  "984f8239-8fe1-4683-9c54-10ffb14439e9"
              ]))
     id3.add(TPE1(encoding=major, text=["Beth Hart & Joe Bonamassa"]))
     id3.add(
         TXXX(encoding=major,
              desc="Artists",
              text=["Beth Hart", "Joe Bonamassa"]))
     id3.add(TSRC(encoding=major, text=["NLB931100460", "USMH51100098"]))
     id3.add(
         TXXX(encoding=major,
              desc="MusicBrainz Release Track Id",
              text="d062f484-253c-374b-85f7-89aab45551c7"))
     id3.add(
         IPLS(encoding=major,
              people=[["engineer", "James McCullagh"],
                      ["engineer",
                       "Jared Kvitka"], ["arranger", "Jeff Bova"],
                      ["producer", "Roy Weisman"], ["piano", "Beth Hart"],
                      ["guitar", "Blondie Chaplin"],
                      ["guitar", "Joe Bonamassa"],
                      ["percussion", "Anton Fig"], ["drums", "Anton Fig"],
                      ["keyboard", "Arlan Schierbaum"],
                      ["bass guitar", "Carmine Rojas"],
                      ["orchestra", "The Bovaland Orchestra"],
                      ["vocals", "Beth Hart"], ["vocals",
                                                "Joe Bonamassa"]])),
     id3.add(TORY(encoding=major, text="2011"))
     id3.add(TYER(encoding=major, text="2011"))
     id3.add(TDAT(encoding=major, text="2709"))
Esempio n. 3
0
def copyTagsToTranscodedFileMp3(losslessFile, lossyFile):
    #
    # Copy the tags from the losslessFile (.flac) to the lossyFile.
    # All previous tags from the lossyFile will be deleted before the
    # tags from the losslessFile are copied.
    #
    from mutagen.flac import FLAC
    from mutagen.id3 import ID3

    # Read all tags from the flac file
    flacFile = FLAC(losslessFile)
    flacFileTags = flacFile.tags  # Returns a dictionary containing the flac tags

    # Only mp3 files with ID3 headers can be openend.
    # So be sure to add some tags during encoding .wav. to mp3

    # Mapping from Vorbis comments field recommendations to id3v2_4_0
    # For more information about vorbis field recommendations: http://reactor-core.org/ogg-tagging.html
    # For more information about id3v2_4_0 frames: http://www.id3.org/id3v2.4.0-frames
    #
    # Single value tags:
    #  ALBUM              -> TALB
    #  ARTIST             -> TPE1
    #  PUBLISHER          -> TPUB
    #  COPYRIGHT          -> WCOP
    #  DISCNUMBER         -> TPOS
    #  ISRC               -> TSRC
    #  EAN/UPN
    #  LABEL
    #  LABELNO
    #  LICENSE             -> TOWN
    #  OPUS                -> TIT3
    #  SOURCEMEDIA         -> TMED
    #  TITLE               -> TIT2
    #  TRACKNUMBER         -> TRCK
    #  VERSION
    #  ENCODED-BY          -> TENC
    #  ENCODING
    # Multiple value tags:
    #  COMPOSER            -> TCOM
    #  ARRANGER
    #  LYRICIST            -> TEXT
    #  AUTHOR              -> TEXT
    #  CONDUCTOR           -> TPE3
    #  PERFORMER           ->
    #  ENSEMBLE            -> TPE2
    #  PART                -> TIT1
    #  PARTNUMBER          -> TIT1
    #  GENRE               -> TCON
    #  DATE                -> TDRC
    #  LOCATION
    #  COMMENT             -> COMM
    # Other vorbis tags are mapped to TXXX tags

    mp3File = ID3(lossyFile)
    mp3File.delete()

    for key, value in flacFileTags.items():
        if key == 'title':
            # Map to TIT2 frame
            from mutagen.id3 import TIT2
            mp3File.add(TIT2(encoding=3, text=value))
        elif key == 'album':
            # Map to TALB frame
            from mutagen.id3 import TALB
            mp3File.add(TALB(encoding=3, text=value))
        elif key == 'artist':
            # Map to TPE1 frame
            from mutagen.id3 import TPE1
            mp3File.add(TPE1(encoding=3, text=value))
        elif key == 'tracknumber':
            # Map to TRCK frame
            from mutagen.id3 import TRCK
            mp3File.add(TRCK(encoding=3, text=value))
        elif key == 'date':
            # Map to TDRC frame
            from mutagen.id3 import TDRC
            mp3File.add(TDRC(encoding=3, text=value))
        elif key == 'genre':
            # Map to TCON frame
            from mutagen.id3 import TCON
            mp3File.add(TCON(encoding=3, text=value))
        elif key == 'discnumber':
            # Map to TPOS frame
            from mutagen.id3 import TPOS
            mp3File.add(TPOS(encoding=3, text=value))
        elif key == 'composer':
            # Map to TCOM frame
            from mutagen.id3 import TCOM
            mp3File.add(TCOM(encoding=3, text=value))
        elif key == 'conductor':
            # Map to TPE3 frame
            from mutagen.id3 import TPE3
            mp3File.add(TPE3(encoding=3, text=value))
        elif key == 'ensemble':
            # Map to TPE2 frame
            from mutagen.id3 import TPE2
            mp3File.add(TPE2(encoding=3, text=value))
        elif key == 'comment':
            # Map to COMM frame
            from mutagen.id3 import COMM
            mp3File.add(COMM(encoding=3, text=value))
        elif key == 'publisher':
            # Map to TPUB frame
            from mutagen.id3 import TPUB
            mp3File.add(TPUB(encoding=3, text=value))
        elif key == 'opus':
            # Map to TIT3 frame
            from mutagen.id3 import TIT3
            mp3File.add(TIT3(encoding=3, text=value))
        elif key == 'sourcemedia':
            # Map to TMED frame
            from mutagen.id3 import TMED
            mp3File.add(TMED(encoding=3, text=value))
        elif key == 'isrc':
            # Map to TSRC frame
            from mutagen.id3 import TSRC
            mp3File.add(TSRC(encoding=3, text=value))
        elif key == 'license':
            # Map to TOWN frame
            from mutagen.id3 import TOWN
            mp3File.add(TOWN(encoding=3, text=value))
        elif key == 'copyright':
            # Map to WCOP frame
            from mutagen.id3 import WCOP
            mp3File.add(WCOP(encoding=3, text=value))
        elif key == 'encoded-by':
            # Map to TENC frame
            from mutagen.id3 import TENC
            mp3File.add(TENC(encoding=3, text=value))
        elif (key == 'part' or key == 'partnumber'):
            # Map to TIT3 frame
            from mutagen.id3 import TIT3
            mp3File.add(TIT3(encoding=3, text=value))
        elif (key == 'lyricist' or key == 'textwriter'):
            # Map to TEXT frame
            from mutagen.id3 import TIT3
            mp3File.add(TIT3(encoding=3, text=value))
        else:  #all other tags are mapped to TXXX frames
            # Map to TXXX frame
            from mutagen.id3 import TXXX
            mp3File.add(TXXX(encoding=3, text=value, desc=key))

        mp3File.update_to_v24()
        mp3File.save()

    return
Esempio n. 4
0
    def metadata_mp3_mutagen(self, path, media):

        from mutagen.mp3 import MP3
        from mutagen.id3 import ID3, TRCK, TIT2, TPE1, TALB, TCON, TXXX, UFID, TSRC, TPUB, TMED, TRCK, TDRC, APIC

        try:
            tags = ID3(path)
        except Exception:
            """
            kindf of hackish - mutagen does complain if no id3 headers - so just create some
            """
            audio = MP3(path)
            audio["TIT2"] = TIT2(encoding=3, text=["Empty Title"])
            audio.save()
            tags = ID3(path)

        # reset tags
        tags.delete()

        # user data
        if INCLUDE_USER and self.user:
            tags.add(
                TXXX(encoding=3,
                     desc='open broadcast user',
                     text=u'%s' % self.user.email))

        # track-level metadata
        tags.add(TIT2(encoding=3, text=u'%s' % media.name))
        tags.add(
            UFID(encoding=3,
                 owner='https://openbroadcast.org',
                 data=u'%s' % media.uuid))

        tags.add(
            TXXX(encoding=3,
                 desc='open broadcast API',
                 text=u'https://%s%s' %
                 (self.current_site.domain, media.get_api_url())))
        # remove genre
        tags.add(TCON(encoding=3, text=u''))
        tags.add(TMED(encoding=3, text=u'Digital Media'))
        if media.tracknumber:
            tags.add(TRCK(encoding=3, text=u'%s' % media.tracknumber))
        if media.isrc:
            tags.add(TSRC(encoding=3, text=u'%s' % media.isrc))

        if uuid_by_object(media, 'musicbrainz'):
            tags.add(
                UFID(encoding=3,
                     owner='http://musicbrainz.org',
                     data=u'%s' % uuid_by_object(media, 'musicbrainz')))

        # release-level metadata
        if media.release:
            tags.add(TALB(encoding=3, text=u'%s' % media.release.name))
            if media.release.catalognumber:
                tags.add(
                    TXXX(encoding=3,
                         desc='CATALOGNUMBER',
                         text=u'%s' % media.release.catalognumber))
            if media.release.releasedate:
                tags.add(
                    TDRC(encoding=3,
                         text=u'%s' % media.release.releasedate.year))
            if media.release.release_country:
                tags.add(
                    TXXX(encoding=3,
                         desc='MusicBrainz Album Release Country',
                         text=u'%s' % media.release.release_country.iso2_code))
            if media.release.totaltracks and media.tracknumber:
                tags.add(
                    TRCK(encoding=3,
                         text=u'%s/%s' %
                         (media.tracknumber, media.release.totaltracks)))
            if media.release.releasedate:
                tags.add(
                    TDRC(encoding=3,
                         text=u'%s' % media.release.releasedate.year))
            if uuid_by_object(media.release, 'musicbrainz'):
                tags.add(
                    TXXX(encoding=3,
                         desc='MusicBrainz Album Id',
                         text=u'%s' %
                         uuid_by_object(media.release, 'musicbrainz')))

            if media.release and media.release.main_image and os.path.exists(
                    media.release.main_image.path):

                opt = dict(size=(300, 300), crop=True, bw=False, quality=80)

                try:
                    image = get_thumbnailer(
                        media.release.main_image).get_thumbnail(opt)
                    tags.add(
                        APIC(encoding=3,
                             mime='image/jpeg',
                             type=3,
                             desc=u'Cover',
                             data=open(image.path).read()))
                except:
                    pass

        # artist-level metadata
        if media.artist:
            tags.add(TPE1(encoding=3, text=u'%s' % media.artist.name))
            if uuid_by_object(media.artist, 'musicbrainz'):
                tags.add(
                    TXXX(encoding=3,
                         desc='MusicBrainz Artist Id',
                         text=u'%s' %
                         uuid_by_object(media.artist, 'musicbrainz')))

        # label-level metadata
        if media.release and media.release.label:
            tags.add(TPUB(encoding=3, text=u'%s' % media.release.label.name))

        tags.save(v1=0)

        return
Esempio n. 5
0
def CopyTagsToTranscodedFileMp3(losslessFile, lossyFile):  
    # Because the input flac file is decoded to wav, all metadata is lost. We have to extract this metadata from 
    # the flac file and put it directly into the generated mp3 file.
    from mutagen.flac import FLAC
    from mutagen.id3 import ID3   
    
    flacFile = FLAC(losslessFile)
    flacFileTags = flacFile.tags 
          
    mp3File = ID3(lossyFile)    
    mp3File.delete()    
        
    for key,value in flacFileTags.items():
        if key == 'title': 
            from mutagen.id3 import TIT2
            mp3File.add(TIT2(encoding=3, text=value)) 
        elif key == 'album': 
            from mutagen.id3 import TALB
            mp3File.add(TALB(encoding=3, text=value))
        elif key == 'artist': 
            from mutagen.id3 import TPE1
            mp3File.add(TPE1(encoding=3, text=value)) 
        elif key == 'tracknumber': 
            from mutagen.id3 import TRCK
            mp3File.add(TRCK(encoding=3, text=value))
        elif key == 'date': 
            from mutagen.id3 import TDRC
            mp3File.add(TDRC(encoding=3, text=value))
        elif key == 'genre': 
            from mutagen.id3 import TCON
            mp3File.add(TCON(encoding=3, text=value))
        elif key == 'discnumber': 
            from mutagen.id3 import TPOS
            mp3File.add(TPOS(encoding=3, text=value))
        elif key == 'composer': 
            from mutagen.id3 import TCOM
            mp3File.add(TCOM(encoding=3, text=value))
        elif key == 'conductor': 
            from mutagen.id3 import TPE3
            mp3File.add(TPE3(encoding=3, text=value))
        elif key == 'ensemble': 
            from mutagen.id3 import TPE2
            mp3File.add(TPE2(encoding=3, text=value))      
        elif key == 'comment': 
            from mutagen.id3 import COMM
            mp3File.add(COMM(encoding=3, text=value))
        elif key == 'publisher': 
            from mutagen.id3 import TPUB
            mp3File.add(TPUB(encoding=3, text=value))
        elif key == 'opus': 
            from mutagen.id3 import TIT3
            mp3File.add(TIT3(encoding=3, text=value))
        elif key == 'sourcemedia': 
            from mutagen.id3 import TMED
            mp3File.add(TMED(encoding=3, text=value))
        elif key == 'isrc': 
            from mutagen.id3 import TSRC
            mp3File.add(TSRC(encoding=3, text=value))
        elif key == 'license': 
            from mutagen.id3 import TOWN
            mp3File.add(TOWN(encoding=3, text=value))
        elif key == 'copyright': 
            from mutagen.id3 import WCOP
            mp3File.add(WCOP(encoding=3, text=value))
        elif key == 'encoded-by': 
            from mutagen.id3 import TENC
            mp3File.add(TENC(encoding=3, text=value))
        elif (key == 'part' or key == 'partnumber'): 
            from mutagen.id3 import TIT3
            mp3File.add(TIT3(encoding=3, text=value))
        elif (key == 'lyricist' or key == 'textwriter'): 
            from mutagen.id3 import TIT3
            mp3File.add(TIT3(encoding=3, text=value))
        else: 
            from mutagen.id3 import TXXX
            mp3File.add(TXXX(encoding=3, text=value, desc=key))        
      
        mp3File.update_to_v24()
        mp3File.save() 
      
    return