Exemplo n.º 1
0
    def Sync( self, options ):
        self._ProcessData( options )

        if self.processed_data == None:
            return

        tags = {}

        for key in self.processed_data.keys():
            tags[key.upper().encode( "utf-8" )] = self.processed_data.getall( key )

        cover_art = self.release.art

        if options["clear-tags"]:
            self.file.delete()

        if cover_art != None:
            self.file.clear_pictures();
            picture = mutagen.flac.Picture()
            picture.data = cover_art[4]
            picture.mime = "image/jpeg"
            picture.desc = ""
            picture.type = 3
            self.file.add_picture( picture )

        self.file.update( tags )

        utils.safeprint( u"  {}".format( self.file[u"title"][0] ) )
Exemplo n.º 2
0
    def Sync( self, options ):
        self._ProcessData( options )

        if self.processed_data == None:
            return

        tags = {}

        for key in self.processed_data.keys():
            tags[key.upper().encode( "utf-8" )] = self.processed_data.getall( key )

        cover_art = self.release.art

        if options["clear-tags"]:
            self.file.delete()

        if cover_art != None:

            if u"METADATA_BLOCK_PICTURE" in self.file:
                self.file[u"METADATA_BLOCK_PICTURE"] = []

            picture = mutagen.flac.Picture()
            picture.data = cover_art[4]
            picture.mime = "image/jpeg"
            picture.desc = ""
            picture.type = 3
            tags.setdefault( u"METADATA_BLOCK_PICTURE", [] ).append( base64.standard_b64encode( picture.write() ) )

        self.file.update( tags )

        utils.safeprint( u"  {}".format( self.file[u"title"][0] ) )
Exemplo n.º 3
0
def LoadPlugins():
    for directory, directories, filenames in os.walk( "./Warp/plugins" ):
        for filename in filenames:
            file_minus_ext, ext = os.path.splitext( filename )
            if ext == ".py":
                info = imp.find_module( file_minus_ext, ["./Warp/plugins"] )
                utils.safeprint( u"Found module {}".format( info ) )
                imp.load_module( "plugins." + file_minus_ext, *info )
Exemplo n.º 4
0
def LoadPlugins():
    for directory, directories, filenames in os.walk("./Warp/plugins"):
        for filename in filenames:
            file_minus_ext, ext = os.path.splitext(filename)
            if ext == ".py":
                info = imp.find_module(file_minus_ext, ["./Warp/plugins"])
                utils.safeprint(u"Found module {}".format(info))
                imp.load_module("plugins." + file_minus_ext, *info)
Exemplo n.º 5
0
    def Sync( self, options ):
        if self.data is None:
            return

        utils.safeprint( u"Updating {} by {}...".format( self.processed_data["album"], self.processed_data["albumartist"] ) )

        for song in self.songs:
            song.inc_count()
            song.Sync( options )
            song.Save( options )

        return
Exemplo n.º 6
0
    def _ProcessData( self, options ):
        if self.release is None:
            utils.safeprint( "ERROR: Release is not set!" )
            self.processed_data = None
            return

        # Copy the general release metadata into the track-specific metadata
        self.processed_data.copy( self.release.processed_data )

        # Get the recording info for the song.
        self._FindRecordingData()

        if self.errors:
            utils.safeprint( "ERROR: Couldn't identify track on release!" )
            self.processed_data = None
            return

        recording = self.matched_medium_track[1]["recording"]
        self.processed_data.add( "discnumber", unicode( self.matched_medium_track[0]["position"], "ascii" ) )
        self.processed_data.add( "tracknumber", unicode( self.matched_medium_track[1]["position"], "ascii" ) )
        self.processed_data.add( "totaltracks", unicode( len( self.matched_medium_track[0]["track-list"] ) ) )

        if "format" in self.matched_medium_track[0]:
            self.processed_data.add( "media", unicode( self.matched_medium_track[0]["format"], "ascii" ) )

        for key, value in recording.items():

            if key in self.MetadataTags:
                self.processed_data.add( self.MetadataTags[key], value )

            elif key == "artist-credit":
                i = 0
                artist_sort_name = u""
                artist_credit = u""
                for c in value:
                    if i == 0:  # artist
                        if options["use_standard_artist_names"] or ( "name" not in c ):
                            artist_credit += c["artist"]["name"]
                        else:
                            artist_credit += c["name"]

                        artist_sort_name += c["artist"]["sort-name"]
                        self.processed_data.add( "musicbrainz_artistid", c["artist"]["id"] )
                    else:  # join phrase
                        artist_sort_name += c
                        artist_credit += c
                    i ^= 1
                self.processed_data.add( "artistsort", artist_sort_name )
                self.processed_data.add( "artist", artist_credit )

        run_track_metadata_processors( None, self.processed_data, None, recording )
        return
Exemplo n.º 7
0
    def Sync(self, options):
        if self.data is None:
            return

        utils.safeprint(u"Updating {} by {}...".format(
            self.processed_data["album"], self.processed_data["albumartist"]))

        for song in self.songs:
            song.inc_count()
            song.Sync(options)
            song.Save(options)

        return
Exemplo n.º 8
0
    def Fetch( self, options ):
        if not self.valid:
            return

        self.fetch_attempts += 1

        # Get the song metadata from MB Web Service - invalid release if this fails
        try:
            self.data = ws.get_release_by_id( self.id, ["artist-credits", "recordings", "labels", "release-groups", "media"] )["release"]
        except ws.musicbrainz.ResponseError:
            utils.safeprint ( u"Connection Error!" )
            self.data = None
            return
        except ws.musicbrainz.NetworkError:
            utils.safeprint ( u"Connection Error!" )
            self.data = None
            return

        self.__ProcessData( options )

        # Get cover art for release - no CA if this fails
        try:
            cover = urllib2.urlopen( "http://coverartarchive.org/release/" + self.id + "/front-500", None, 10 )
        except urllib2.HTTPError:
            utils.safeprint( u"No cover art in CAA for \"{}\".".format( self.processed_data["album"] ) )
            self.art = None
        except ( urllib2.URLError, socket.timeout ):
            utils.safeprint( u"Connection Error!" )
            self.art = None
        else:
            self.art = self.__PackageCoverArt( cover.read() )

        # Successfully retrieved data
        self.fetched = True
        return self.id
Exemplo n.º 9
0
    def Save( self, options ):
        if self.processed_data is None:
            return

        Track.num_processed += 1
        try:
            self.SaveFunc( options )
        except ValueError:
            for key, value in self.processed_data.items():
                if value[0] is None:
                    utils.safeprint( u"{} : {}".format( key, value ) )

        self._handle_filesystem_options( options )

        self.PostSave( options )
Exemplo n.º 10
0
 def __init__( self, id_ ):
     self.songs = list()
     self.fetched = False
     self.valid = True
     self.art = None
     self.data = None
     self.processed_data = metadata.Metadata()
     self.fetch_attempts = 0
     Release.num_loaded += 1
     try:
         uuid.UUID( id_ )
     except ValueError:
         utils.safeprint( u"Corrupt UUID in file." )
         self.valid = False
     else:
         self.id = id_
Exemplo n.º 11
0
 def __init__(self, id_):
     self.songs = list()
     self.fetched = False
     self.valid = True
     self.art = None
     self.data = None
     self.processed_data = metadata.Metadata()
     self.fetch_attempts = 0
     Release.num_loaded += 1
     try:
         uuid.UUID(id_)
     except ValueError:
         utils.safeprint(u"Corrupt UUID in file.")
         self.valid = False
     else:
         self.id = id_
Exemplo n.º 12
0
 def _rename( self, options ):
     self.filename, ext = os.path.splitext( self._make_filename( options ) )
     if self.file.filename != self.filename + ext:
         new_dirname = os.path.dirname( self.filename )
         if not os.path.isdir( utils.encode_filename( new_dirname ) ):
             os.makedirs( new_dirname )
         tmp_filename = self.filename
         i = 1
         while ( not utils.pathcmp( self.file.filename, self.filename + ext ) and os.path.exists( utils.encode_filename( self.filename + ext ) ) ):
             self.filename = u"{} ({})".format( tmp_filename, i )
             i += 1
         self.filename = self.filename + ext
         common = os.path.commonprefix( list( ( os.path.dirname( self.file.filename ), os.path.dirname( self.filename ) ) ) )
         utils.safeprint( u"{} -> {}".format( os.path.relpath( self.file.filename, common ), os.path.relpath( self.filename, common ) ) )
         shutil.move( utils.encode_filename( self.file.filename ), utils.encode_filename( self.filename ) )
         return self.filename
     else:
         return self.file.filename
Exemplo n.º 13
0
    def Sync( self, options ):
        self._ProcessData( options )

        if self.processed_data == None:
            return

        tags = compatid3.CompatID3()

        for key in self.processed_data.keys():
            value = self.processed_data.get( key )
            if key in MP3Track.TranslationTable:
                tags.add( getattr( mutagen.id3, MP3Track.TranslationTable[key] )( encoding=MP3Track.id3encoding, text=value ) )
            elif key in MP3Track.TranslateTextField:
                tags.add( mutagen.id3.TXXX( encoding=MP3Track.id3encoding, desc=MP3Track.TranslateTextField[key], text=value ) )
            elif key == "discnumber":
                tags.add( mutagen.id3.TPOS( encoding=0, text=value + "/" + self.processed_data["totaldiscs"] ) )
            elif key == "tracknumber":
                tags.add( mutagen.id3.TRCK( encoding=0, text=value + "/" + self.processed_data["totaltracks"] ) )
            elif key == "musicbrainz_trackid":
                tags.add( mutagen.id3.UFID( owner='http://musicbrainz.org', data=value ) )

        if self.release.art != None:
            self.file.delall( "APIC" )
            tags.add( mutagen.id3.APIC( encoding=0, mime="image/jpeg", type=3, desc="", data=self.release.art[4] ) )

        if options["clear-tags"]:
            self.file.delete()
        else:
            for tag in MP3Track.TagsToRemove:
                if tag in self.file:
                    del self.file[tag]

        self.file.update( tags )

        if options["id3version"] == "2.3":
            self.file.update_to_v23()
        elif options["id3version"] == "2.4":
            self.file.update_to_v24()

        utils.safeprint( u"  {}".format( self.file[MP3Track.TranslationTable["title"]].text[0] ) )
Exemplo n.º 14
0
    def Fetch(self, options):
        if not self.valid:
            return

        self.fetch_attempts += 1

        # Get the song metadata from MB Web Service - invalid release if this fails
        try:
            self.data = ws.get_release_by_id(self.id, [
                "artist-credits", "recordings", "labels", "release-groups",
                "media"
            ])["release"]
        except ws.musicbrainz.ResponseError:
            utils.safeprint(u"Connection Error!")
            self.data = None
            return
        except ws.musicbrainz.NetworkError:
            utils.safeprint(u"Connection Error!")
            self.data = None
            return

        self.__ProcessData(options)

        # Get cover art for release - no CA if this fails
        try:
            cover = urllib2.urlopen(
                "http://coverartarchive.org/release/" + self.id + "/front-500",
                None, 10)
        except urllib2.HTTPError:
            utils.safeprint(u"No cover art in CAA for \"{}\".".format(
                self.processed_data["album"]))
            self.art = None
        except (urllib2.URLError, socket.timeout):
            utils.safeprint(u"Connection Error!")
            self.art = None
        else:
            self.art = self.__PackageCoverArt(cover.read())

        # Successfully retrieved data
        self.fetched = True
        return self.id