Exemplo n.º 1
0
def doPostProcessing(albumid, albumpath, release, tracks, downloaded_track_list):

    logger.info('Starting post-processing for: %s - %s' % (release['ArtistName'], release['AlbumTitle']))
    #start enconding
    if headphones.MUSIC_ENCODER:
        downloaded_track_list=music_encoder.encode(albumpath)
    
    album_art_path = albumart.getAlbumArt(albumid)
    
    if headphones.EMBED_ALBUM_ART or headphones.ADD_ALBUM_ART:
        artwork = urllib.urlopen(album_art_path).read()
        if len(artwork) < 100:
            logger.info("No suitable album art found from Amazon. Checking Last.FM....")
            artwork = albumart.getCachedArt(albumid)
            if not artwork or len(artwork) < 100:
                artwork = False
                logger.info("No suitable album art found from Last.FM. Not adding album art")
    
    if headphones.EMBED_ALBUM_ART and artwork:
        embedAlbumArt(artwork, downloaded_track_list)
    
    if headphones.CLEANUP_FILES:
        cleanupFiles(albumpath)
        
    if headphones.ADD_ALBUM_ART and artwork:
        addAlbumArt(artwork, albumpath)
        
    if headphones.CORRECT_METADATA:
        correctMetadata(albumid, release, downloaded_track_list)
        
    if headphones.EMBED_LYRICS:
        embedLyrics(downloaded_track_list)
        
    if headphones.RENAME_FILES:
        renameFiles(albumpath, downloaded_track_list, release)
    
    if headphones.MOVE_FILES and headphones.DESTINATION_DIR:
        albumpaths = moveFiles(albumpath, release, tracks)
    
    if headphones.MOVE_FILES and not headphones.DESTINATION_DIR:
        logger.error('No DESTINATION_DIR has been set. Set "Destination Directory" to the parent directory you want to move the files to')
        pass
        
    myDB = db.DBConnection()
    myDB.action('UPDATE albums SET status = "Downloaded" WHERE AlbumID=?', [albumid])
    myDB.action('UPDATE snatched SET status = "Processed" WHERE AlbumID=?', [albumid])
        
    # Update the have tracks for all created dirs:
    for albumpath in albumpaths:
        librarysync.libraryScan(dir=albumpath, append=True, ArtistID=release['ArtistID'], ArtistName=release['ArtistName'])
    
    logger.info('Post-processing for %s - %s complete' % (release['ArtistName'], release['AlbumTitle']))
    
    if headphones.PROWL_ENABLED:
        pushmessage = release['ArtistName'] + ' - ' + release['AlbumTitle']
        logger.info(u"Prowl request")
        prowl = notifiers.PROWL()
        prowl.notify(pushmessage,"Download and Postprocessing completed")
        
    if headphones.XBMC_ENABLED:
        xbmc = notifiers.XBMC()
        if headphones.XBMC_UPDATE:
            xbmc.update()
        if headphones.XBMC_NOTIFY:
            xbmc.notify(release['ArtistName'], release['AlbumTitle'], album_art_path)
            
    if headphones.NMA_ENABLED:
        nma = notifiers.NMA()
        nma.notify(release['ArtistName'], release['AlbumTitle'])

    if headphones.SYNOINDEX_ENABLED:
        syno = notifiers.Synoindex()
        for albumpath in albumpaths:
            syno.notify(albumpath)
Exemplo n.º 2
0
         
     # Need to update the downloaded track list with the new location. 
     # Could probably just throw in the "headphones-modified" folder,
     # but this is good to make sure we're not counting files that may have failed to move
     downloaded_track_list = []
     downloaded_cuecount = 0
         
     for r,d,f in os.walk(albumpath):
         for files in f:
             if any(files.lower().endswith('.' + x.lower()) for x in headphones.MEDIA_FORMATS):
                 downloaded_track_list.append(os.path.join(r, files))    
             elif files.lower().endswith('.cue'):
                 downloaded_cuecount += 1
 #start encoding
 if headphones.MUSIC_ENCODER:
     downloaded_track_list=music_encoder.encode(albumpath)
    
     if not downloaded_track_list:
         return
 
 album_art_path = albumart.getAlbumArt(albumid)
 
 if headphones.EMBED_ALBUM_ART or headphones.ADD_ALBUM_ART:
     if album_art_path:
         artwork = urllib.urlopen(album_art_path).read()
     if not album_art_path or len(artwork) < 100:
         logger.info("No suitable album art found from Amazon. Checking Last.FM....")
         artwork = albumart.getCachedArt(albumid)
         if not artwork or len(artwork) < 100:
             artwork = False
             logger.info("No suitable album art found from Last.FM. Not adding album art")
Exemplo n.º 3
0
    if headphones.KEEP_TORRENT_FILES and Kind == "torrent":
        new_folder = os.path.join(os.path.dirname(albumpath),
                                  ('temp' + release['AlbumTitle'][:8]).encode(
                                      headphones.SYS_ENCODING, 'replace'))
        new_folder = new_folder.strip()
        try:
            shutil.copytree(albumpath, new_folder)
            albumpath = new_folder
        except Exception, e:
            logger.warn("Cannot copy/move files to temp folder: " +
                        new_folder.decode(headphones.SYS_ENCODING, 'replace') +
                        ". Not continuing. Error: " + str(e))
            return
    #start encoding
    if headphones.MUSIC_ENCODER:
        downloaded_track_list = music_encoder.encode(albumpath)

        if not downloaded_track_list:
            return

    album_art_path = albumart.getAlbumArt(albumid)

    if headphones.EMBED_ALBUM_ART or headphones.ADD_ALBUM_ART:
        if album_art_path:
            artwork = urllib.urlopen(album_art_path).read()
        if not album_art_path or len(artwork) < 100:
            logger.info(
                "No suitable album art found from Amazon. Checking Last.FM...."
            )
            artwork = albumart.getCachedArt(albumid)
            if not artwork or len(artwork) < 100:
Exemplo n.º 4
0
def doPostProcessing(albumid, albumpath, release, tracks,
                     downloaded_track_list):

    logger.info('Starting post-processing for: %s - %s' %
                (release['ArtistName'], release['AlbumTitle']))
    #start encoding
    if headphones.MUSIC_ENCODER:
        downloaded_track_list = music_encoder.encode(albumpath)

        if not downloaded_track_list:
            return

    album_art_path = albumart.getAlbumArt(albumid)

    if headphones.EMBED_ALBUM_ART or headphones.ADD_ALBUM_ART:
        if album_art_path:
            artwork = urllib.urlopen(album_art_path).read()
        if not album_art_path or len(artwork) < 100:
            logger.info(
                "No suitable album art found from Amazon. Checking Last.FM...."
            )
            artwork = albumart.getCachedArt(albumid)
            if not artwork or len(artwork) < 100:
                artwork = False
                logger.info(
                    "No suitable album art found from Last.FM. Not adding album art"
                )

    if headphones.EMBED_ALBUM_ART and artwork:
        embedAlbumArt(artwork, downloaded_track_list)

    if headphones.CLEANUP_FILES:
        cleanupFiles(albumpath)

    if headphones.ADD_ALBUM_ART and artwork:
        addAlbumArt(artwork, albumpath)

    if headphones.CORRECT_METADATA:
        correctMetadata(albumid, release, downloaded_track_list)

    if headphones.EMBED_LYRICS:
        embedLyrics(downloaded_track_list)

    if headphones.RENAME_FILES:
        renameFiles(albumpath, downloaded_track_list, release)

    if headphones.MOVE_FILES and not headphones.DESTINATION_DIR:
        logger.error(
            'No DESTINATION_DIR has been set. Set "Destination Directory" to the parent directory you want to move the files to'
        )
        albumpaths = [albumpath]
    elif headphones.MOVE_FILES and headphones.DESTINATION_DIR:
        albumpaths = moveFiles(albumpath, release, tracks)
    else:
        albumpaths = [albumpath]

    myDB = db.DBConnection()
    myDB.action('UPDATE albums SET status = "Downloaded" WHERE AlbumID=?',
                [albumid])
    myDB.action('UPDATE snatched SET status = "Processed" WHERE AlbumID=?',
                [albumid])

    # Update the have tracks for all created dirs:
    for albumpath in albumpaths:
        librarysync.libraryScan(dir=albumpath,
                                append=True,
                                ArtistID=release['ArtistID'],
                                ArtistName=release['ArtistName'])

    logger.info(u'Post-processing for %s - %s complete' %
                (release['ArtistName'], release['AlbumTitle']))

    if headphones.PROWL_ENABLED:
        pushmessage = release['ArtistName'] + ' - ' + release['AlbumTitle']
        logger.info(u"Prowl request")
        prowl = notifiers.PROWL()
        prowl.notify(pushmessage, "Download and Postprocessing completed")

    if headphones.XBMC_ENABLED:
        xbmc = notifiers.XBMC()
        if headphones.XBMC_UPDATE:
            xbmc.update()
        if headphones.XBMC_NOTIFY:
            xbmc.notify(release['ArtistName'], release['AlbumTitle'],
                        album_art_path)

    if headphones.NMA_ENABLED:
        nma = notifiers.NMA()
        nma.notify(release['ArtistName'], release['AlbumTitle'])

    if headphones.SYNOINDEX_ENABLED:
        syno = notifiers.Synoindex()
        for albumpath in albumpaths:
            syno.notify(albumpath)
Exemplo n.º 5
0
def doPostProcessing(albumid, albumpath, release, tracks, downloaded_track_list):

    logger.info('Starting post-processing for: %s - %s' % (release['ArtistName'], release['AlbumTitle']))
    #start enconding
    if headphones.MUSIC_ENCODER:
        downloaded_track_list=music_encoder.encode(albumpath)
    
    album_art_path = albumart.getAlbumArt(albumid)
    
    if headphones.EMBED_ALBUM_ART or headphones.ADD_ALBUM_ART:
        artwork = urllib.urlopen(album_art_path).read()
        if len(artwork) < 100:
            artwork = False
            logger.info("No suitable album art found. Not adding album art")
    
    if headphones.EMBED_ALBUM_ART and artwork:
        embedAlbumArt(artwork, downloaded_track_list)
    
    if headphones.CLEANUP_FILES:
        cleanupFiles(albumpath)
        
    if headphones.ADD_ALBUM_ART and artwork:
        addAlbumArt(artwork, albumpath)
        
    if headphones.CORRECT_METADATA:
        correctMetadata(albumid, release, downloaded_track_list)
        
    if headphones.EMBED_LYRICS:
        embedLyrics(downloaded_track_list)
        
    if headphones.RENAME_FILES:
        renameFiles(albumpath, downloaded_track_list, release)
    
    if headphones.MOVE_FILES and headphones.DESTINATION_DIR:
        albumpath = moveFiles(albumpath, release, tracks)
    
    if headphones.MOVE_FILES and not headphones.DESTINATION_DIR:
        logger.error('No DESTINATION_DIR has been set. Set "Destination Directory" to the parent directory you want to move the files to')
        pass
        
    myDB = db.DBConnection()
    # There's gotta be a better way to update the have tracks - sqlite
    
    trackcount = myDB.select('SELECT HaveTracks from artists WHERE ArtistID=?', [release['ArtistID']])
    
    if not trackcount[0][0]:
        cur_track_count = 0
    else:
        cur_track_count = trackcount[0][0]
        
    new_track_count = cur_track_count + len(downloaded_track_list)
    myDB.action('UPDATE artists SET HaveTracks=? WHERE ArtistID=?', [new_track_count, release['ArtistID']])
    myDB.action('UPDATE albums SET status = "Downloaded" WHERE AlbumID=?', [albumid])
    myDB.action('UPDATE snatched SET status = "Processed" WHERE AlbumID=?', [albumid])
    updateHave(albumpath)
    
    logger.info('Post-processing for %s - %s complete' % (release['ArtistName'], release['AlbumTitle']))
    
    if headphones.PROWL_ONSNATCH:
        pushmessage = release['ArtistName'] + ' - ' + release['AlbumTitle']
        logger.info(u"Prowl request")
        prowl = notifiers.PROWL()
        prowl.notify(pushmessage,"Download and Postprocessing completed")
        
    if headphones.XBMC_ENABLED:
        xbmc = notifiers.XBMC()
        if headphones.XBMC_UPDATE:
            xbmc.update()
        if headphones.XBMC_NOTIFY:
            xbmc.notify(release['ArtistName'], release['AlbumTitle'], album_art_path)
            
    if headphones.NMA_ENABLED:
        nma = notifiers.NMA()
        nma.notify(release['ArtistName'], release['AlbumTitle'])

    if headphones.SYNOINDEX_ENABLED:
        syno = notifiers.Synoindex()
        syno.notify(albumpath)
Exemplo n.º 6
0
def doPostProcessing(albumid, albumpath, release, tracks, downloaded_track_list):

	logger.info('Starting post-processing for: %s - %s' % (release['ArtistName'], release['AlbumTitle']))
	#start enconding
	if headphones.MUSIC_ENCODER:
		downloaded_track_list=music_encoder.encode(albumpath)
	
	album_art_path = albumart.getAlbumArt(albumid)
	
	if headphones.EMBED_ALBUM_ART or headphones.ADD_ALBUM_ART:
		artwork = urllib.urlopen(album_art_path).read()
		if len(artwork) < 100:
			artwork = False
			logger.info("No suitable album art found. Not adding album art")
	
	if headphones.EMBED_ALBUM_ART and artwork:
		embedAlbumArt(artwork, downloaded_track_list)
	
	if headphones.CLEANUP_FILES:
		cleanupFiles(albumpath)
		
	if headphones.ADD_ALBUM_ART and artwork:
		addAlbumArt(artwork, albumpath)
		
	if headphones.CORRECT_METADATA:
		correctMetadata(albumid, release, downloaded_track_list)
		
	if headphones.EMBED_LYRICS:
		embedLyrics(downloaded_track_list)
		
	if headphones.RENAME_FILES:
		renameFiles(albumpath, downloaded_track_list, release)
	
	if headphones.MOVE_FILES and headphones.DESTINATION_DIR:
		albumpath = moveFiles(albumpath, release, tracks)
	
	if headphones.MOVE_FILES and not headphones.DESTINATION_DIR:
		logger.error('No DESTINATION_DIR has been set. Set "Destination Directory" to the parent directory you want to move the files to')
		pass
		
	myDB = db.DBConnection()
	# There's gotta be a better way to update the have tracks - sqlite
	
	trackcount = myDB.select('SELECT HaveTracks from artists WHERE ArtistID=?', [release['ArtistID']])
	
	if not trackcount[0][0]:
		cur_track_count = 0
	else:
		cur_track_count = trackcount[0][0]
		
	new_track_count = cur_track_count + len(downloaded_track_list)
	myDB.action('UPDATE artists SET HaveTracks=? WHERE ArtistID=?', [new_track_count, release['ArtistID']])
	myDB.action('UPDATE albums SET status = "Downloaded" WHERE AlbumID=?', [albumid])
	myDB.action('UPDATE snatched SET status = "Processed" WHERE AlbumID=?', [albumid])
	updateHave(albumpath)
	
	logger.info('Post-processing for %s - %s complete' % (release['ArtistName'], release['AlbumTitle']))
	
	if headphones.PROWL_ONSNATCH:
		pushmessage = release['ArtistName'] + ' - ' + release['AlbumTitle']
		logger.info(u"Prowl request")
		prowl = notifiers.PROWL()
		prowl.notify(pushmessage,"Download and Postprocessing completed")
		
	if headphones.XBMC_ENABLED:
		xbmc = notifiers.XBMC()
		if headphones.XBMC_UPDATE:
			xbmc.update()
		if headphones.XBMC_NOTIFY:
			xbmc.notify(release['ArtistName'], release['AlbumTitle'], album_art_path)
			
	if headphones.NMA_ENABLED:
		nma = notifiers.NMA()
		nma.notify(release['ArtistName'], release['AlbumTitle'])