コード例 #1
0
def validateArtwork(track):
    #print "DEBUG: validateArtwork in 1"
    #sys.stdout.flush()
    artworkCollection = track.Artwork
    if artworkCollection.Count == 0:
        return
    #print "DEBUG: validateArtwork in 2"
    #sys.stdout.flush()

    artwork = artworkCollection.Item(1)
    #print "DEBUG: validateArtwork in 2.1"
    if artwork.IsDownloadedArtwork:
        return
    #print "DEBUG: validateArtwork in 2.2"

    albumId = id3.getMusicBrainzId(track.Location)
    if albumId == None:
        print "DEBUG: no albumId available for %s" % prettyTrack(track)
        return
    #print "DEBUG: validateArtwork in 3"
    #sys.stdout.flush()
    
    release = mbcache.getReleaseByAlbumId(albumId)
    #print "DEBUG: validateArtwork in 4"
    #sys.stdout.flush()
    asin = release.getAsin()
    #print "DEBUG: validateArtwork in 5"
    #sys.stdout.flush()
    if not asin == None:
        if amazon.isBadArtwork(asin):
            print "Bad artwork in %s" % prettyTrack(track)
            artwork.Delete()
コード例 #2
0
def checkArtwork(track):
    if not hasattr(track, 'Artwork'):
        print "DEBUG: no artwork attribute for %s" % prettyTrack(track)
        return

    artworkCollection = track.Artwork
    if not FIND_BAD_COVER_ART and artworkCollection.Count > 0:
        # album already has art
        return

    albumId = id3.getMusicBrainzId(track.Location)
    if albumId == None:
        print "DEBUG: no albumId available for %s" % prettyTrack(track)
        return

    try:
        release = mbcache.getReleaseByAlbumId(albumId)
    except:
        print "DEBUG: MusicBrainz lookup error for %s" % prettyTrack(track)
        return

    asin = release.getAsin()
    if asin == None:
        print "DEBUG: no amazon ID for %s" % prettyTrack(track)
        return

    imageFile = amazon.getArtwork(asin)
    if imageFile == None:
        print "DEBUG: bad art for %s" % prettyTrack(track)
        #if artworkCollection.Count > 0:
        #    print "DEBUG: consider deleting this file's artwork"
        return

    if FIND_BAD_COVER_ART and artworkCollection.Count > 0:
        if artworkCollection.Count > 1:
            print "DEBUG: findBadCoverArt - too many items for %s" % prettyTrack(track)
            return

        artwork = artworkCollection.Item(1)
        artwork.SaveArtworkToFile(TEMP_ART_FILE)
        #print "DEBUG: saved %s to %s" % (prettyTrack(track), TEMP_ART_FILE)

        oldFileStat = os.stat(TEMP_ART_FILE)
        newFileStat = os.stat(imageFile)

        if oldFileStat[ST_SIZE] == newFileStat[ST_SIZE] or filecmp.cmp(TEMP_ART_FILE, imageFile):
            #print "DEBUG: findBadCoverArt - no change needed for %s" % prettyTrack(track)
            return

        if oldFileStat[ST_SIZE] > newFileStat[ST_SIZE]:
            print "DEBUG: findBadCoverArt - old file is bigger than new file (%d vs %d) for %s" % (oldFileStat[ST_SIZE], newFileStat[ST_SIZE], prettyTrack(track))
            #return

        if DELETE_BAD_ART:
            print "DEBUG: findBadCoverArt - deleting art from %s" % prettyTrack(track)
            artwork.Delete()
        else:
            print "DEBUG: findBadCoverArt - should delete art from %s" % prettyTrack(track)
            return

        
    print "DEBUG: Adding artwork from %s" % (imageFile)
    track.AddArtworkFromFile(imageFile)
    print "Added artwork for %s (%s)" % (prettyTrack(track), albumId)
コード例 #3
0
def syncFile(targetFile):
    (root, ext) = os.path.splitext(targetFile)
    if ext.lower() != ".mp3":
        return

    print "DEBUG: syncFile in for %s" % targetFile
    changedFile = False

    tag = id3.parse(targetFile)
    if tag == None:
        print "DEBUG: no tag available for %s" % targetFile
        return
    
    albumId = id3.getMusicBrainzId(targetFile, tag)
    if albumId == None:
        print "DEBUG: no albumId available for %s" % targetFile
        return

    try:
        release = mbcache.getReleaseByAlbumId(albumId)
    except:
        print "DEBUG: MusicBrainz lookup error for %s" % targetFile
        return

    trackNum = tag.getTrackNum()[0]
    if trackNum == None:
        print "DEBUG: couldn't find track number for %s" % targetFile
        return

    releaseTrack = release.getTracks()[trackNum - 1]
    if releaseTrack == None:
        print "DEBUG: couldn't find release track for %s" % targetFile
        return

    releaseArtist = releaseTrack.getArtist()
    if releaseArtist == None:
        releaseArtist = release.getArtist()
    if releaseArtist == None:
        print "DEBUG: couldn't find release artist for %s" % targetFile
    else:
        #print "DEBUG: releaseArtist is %s" % dir(releaseArtist)
        
        releaseArtist = translateArtist(releaseArtist)
        tagArtist = tag.getArtist()

        if releaseArtist == "":
            print "DEBUG: release artist is empty"
        elif releaseArtist != tagArtist:
            print "Tag artist:     %s" % tagArtist.encode('utf-8')
            print "Release artist: %s" % releaseArtist.encode('utf-8')
            tag.setArtist(releaseArtist)
            changedFile = True


    releaseDate = release.getEarliestReleaseDate()
    if releaseDate != None:
        # TODO - consider setting month/day in tag?
        (releaseYear, _, _) = releaseDate.partition('-')
        tagYear = tag.getYear()

        if releaseYear != tagYear:
            print "Tag year:       %s" % tagYear
            print "Release year:   %s" % releaseYear
            tag.setDate(year = releaseYear)
            changedFile = True


    releaseSongTitle = releaseTrack.getTitle()
    tagSongTitle = tag.getTitle()

    if releaseSongTitle != tagSongTitle and releaseSongTitle != "":
        print "Tag title:     %s" % tagSongTitle.encode('utf-8')
        print "Release title: %s" % releaseSongTitle.encode('utf-8')
        tag.setTitle(releaseSongTitle)
        changedFile = True

    releaseAlbum = release.getTitle()
    tagAlbum = tag.getAlbum()

    if releaseAlbum != tagAlbum and releaseAlbum != "":
        print "Tag album:     %s" % tagAlbum.encode('utf-8')
        print "Release album: %s" % releaseAlbum.encode('utf-8')
        tag.setAlbum(releaseAlbum)
        changedFile = True

    if changedFile:
        if ALLOW_COMMIT:
            id3.save(tag)
            print "DEBUG: Wrote to %s" % targetFile
        else:
            print "DEBUG: (commits disabled) Pending changes for %s" % targetFile
        sys.stdout.flush()