Exemplo n.º 1
0
def verify(albumid, albumpath, Kind=None, forced=False):

    myDB = db.DBConnection()
    release = myDB.action('SELECT * from albums WHERE AlbumID=?', [albumid]).fetchone()
    tracks = myDB.select('SELECT * from tracks WHERE AlbumID=?', [albumid])

    if not release or not tracks:
        #the result of a manual post-process on an album that hasn't been inserted
        #from an RSS feed or etc
        #TODO: This should be a call to a class method.. copied it out of importer with only minor changes
        #TODO: odd things can happen when there are diacritic characters in the folder name, need to translate them?
        import mb
        
        release_list = None
        
        try:    
            release_list = mb.getReleaseGroup(albumid)
        except Exception, e:
            logger.info('Unable to get release information for manual album with rgid: %s. Error: %s' % (albumid, e))
            return
            
        if not release_list:
            logger.info('Unable to get release information for manual album with rgid: %s' % albumid)
            return

        # Since we're just using this to create the bare minimum information to insert an artist/album combo, use the first release
        releaseid = release_list[0]['id']

        release_dict = mb.getRelease(releaseid)

        logger.info(u"Now adding/updating artist: " + release_dict['artist_name'])
        
        if release_dict['artist_name'].startswith('The '):
            sortname = release_dict['artist_name'][4:]
        else:
            sortname = release_dict['artist_name']
            
    
        controlValueDict = {"ArtistID":     release_dict['artist_id']}
        newValueDict = {"ArtistName":       release_dict['artist_name'],
                        "ArtistSortName":   sortname,
                        "DateAdded":        helpers.today(),
                        "Status":           "Paused"}
                        
        logger.info("ArtistID: " + release_dict['artist_id'] + " , ArtistName: " + release_dict['artist_name'])

        if headphones.INCLUDE_EXTRAS:
            newValueDict['IncludeExtras'] = 1
            newValueDict['Extras'] = headphones.EXTRAS
        
        myDB.upsert("artists", newValueDict, controlValueDict)

        logger.info(u"Now adding album: " + release_dict['title'])
        controlValueDict = {"AlbumID":  albumid}
        
        newValueDict = {"ArtistID":         release_dict['artist_id'],
                        "ArtistName":       release_dict['artist_name'],
                        "AlbumTitle":       release_dict['title'],
                        "AlbumASIN":        release_dict['asin'],
                        "ReleaseDate":      release_dict['date'],
                        "DateAdded":        helpers.today(),
                        "Type":             release_dict['rg_type'],
                        "Status":           "Snatched"
                        }

        myDB.upsert("albums", newValueDict, controlValueDict)
    
        # Delete existing tracks associated with this AlbumID since we're going to replace them and don't want any extras
        myDB.action('DELETE from tracks WHERE AlbumID=?', [albumid])
        for track in release_dict['tracks']:
        
            controlValueDict = {"TrackID":  track['id'],
                                "AlbumID":  albumid}
                                
            newValueDict = {"ArtistID":     release_dict['artist_id'],
                        "ArtistName":       release_dict['artist_name'],
                        "AlbumTitle":       release_dict['title'],
                        "AlbumASIN":        release_dict['asin'],
                        "TrackTitle":       track['title'],
                        "TrackDuration":    track['duration'],
                        "TrackNumber":      track['number']
                        }
        
            myDB.upsert("tracks", newValueDict, controlValueDict)
            
        controlValueDict = {"ArtistID":     release_dict['artist_id']}
        newValueDict = {"Status":           "Paused"}
        
        myDB.upsert("artists", newValueDict, controlValueDict)
        logger.info(u"Addition complete for: " + release_dict['title'] + " - " + release_dict['artist_name'])

        release = myDB.action('SELECT * from albums WHERE AlbumID=?', [albumid]).fetchone()
        tracks = myDB.select('SELECT * from tracks WHERE AlbumID=?', [albumid])
Exemplo n.º 2
0
def verify(albumid, albumpath):

	myDB = db.DBConnection()
	release = myDB.action('SELECT * from albums WHERE AlbumID=?', [albumid]).fetchone()
	tracks = myDB.select('SELECT * from tracks WHERE AlbumID=?', [albumid])

	if not release or not tracks:
		#the result of a manual post-process on an album that hasn't been inserted
		#from an RSS feed or etc
		#TODO: This should be a call to a class method.. copied it out of importer with only minor changes
		#TODO: odd things can happen when there are diacritic characters in the folder name, need to translate them?
		import mb
		
		release_dict = None
		
		try:	
			release_dict = mb.getReleaseGroup(albumid)
		except Exception, e:
			logger.info('Unable to get release information for manual album with rgid: %s. Error: %s' % (albumid, e))
			return
			
		if not release_dict:
			logger.info('Unable to get release information for manual album with rgid: %s' % albumid)
			return

		logger.info(u"Now adding/updating artist: " + release_dict['artist_name'])
		
		if release_dict['artist_name'].startswith('The '):
			sortname = release_dict['artist_name'][4:]
		else:
			sortname = release_dict['artist_name']
			
	
		controlValueDict = {"ArtistID": 	release_dict['artist_id']}
		newValueDict = {"ArtistName": 		release_dict['artist_name'],
						"ArtistSortName": 	sortname,
						"DateAdded": 		helpers.today(),
						"Status": 			"Paused"}
		logger.info("ArtistID:ArtistName: " + release_dict['artist_id'] + " : " + release_dict['artist_name'])

		if headphones.INCLUDE_EXTRAS:
			newValueDict['IncludeExtras'] = 1
		
		myDB.upsert("artists", newValueDict, controlValueDict)

		logger.info(u"Now adding album: " + release_dict['title'])
		controlValueDict = {"AlbumID": 	albumid}
		
		newValueDict = {"ArtistID":			release_dict['artist_id'],
						"ArtistName": 		release_dict['artist_name'],
						"AlbumTitle":		release_dict['title'],
						"AlbumASIN":		release_dict['asin'],
						"ReleaseDate":		release_dict['releasedate'],
						"DateAdded":		helpers.today(),
						"Type":				release_dict['type'],
						"Status":			"Snatched"
						}

		myDB.upsert("albums", newValueDict, controlValueDict)
		
		# I changed the albumid from releaseid -> rgid, so might need to delete albums that have a releaseid
		for rel in release_dict['releaselist']:
			myDB.action('DELETE from albums WHERE AlbumID=?', [rel['releaseid']])
			myDB.action('DELETE from tracks WHERE AlbumID=?', [rel['releaseid']])
		
		myDB.action('DELETE from tracks WHERE AlbumID=?', [albumid])
		for track in release_dict['tracks']:
		
			controlValueDict = {"TrackID": 	track['id'],
								"AlbumID":	albumid}
			newValueDict = {"ArtistID":		release_dict['artist_id'],
						"ArtistName": 		release_dict['artist_name'],
						"AlbumTitle":		release_dict['title'],
						"AlbumASIN":		release_dict['asin'],
						"TrackTitle":		track['title'],
						"TrackDuration":	track['duration'],
						"TrackNumber":		track['number']
						}
		
			myDB.upsert("tracks", newValueDict, controlValueDict)
			
		controlValueDict = {"ArtistID": 	release_dict['artist_id']}
		newValueDict = {"Status":			"Paused"}
		
		myDB.upsert("artists", newValueDict, controlValueDict)
		logger.info(u"Addition complete for: " + release_dict['title'] + " - " + release_dict['artist_name'])

		release = myDB.action('SELECT * from albums WHERE AlbumID=?', [albumid]).fetchone()
		tracks = myDB.select('SELECT * from tracks WHERE AlbumID=?', [albumid])
Exemplo n.º 3
0
def verify(albumid, albumpath):

    myDB = db.DBConnection()
    release = myDB.action('SELECT * from albums WHERE AlbumID=?',
                          [albumid]).fetchone()
    tracks = myDB.select('SELECT * from tracks WHERE AlbumID=?', [albumid])

    if not release or not tracks:
        #the result of a manual post-process on an album that hasn't been inserted
        #from an RSS feed or etc
        #TODO: This should be a call to a class method.. copied it out of importer with only minor changes
        #TODO: odd things can happen when there are diacritic characters in the folder name, need to translate them?
        import mb

        release_list = None

        try:
            release_list = mb.getReleaseGroup(albumid)
        except Exception, e:
            logger.info(
                'Unable to get release information for manual album with rgid: %s. Error: %s'
                % (albumid, e))
            return

        if not release_list:
            logger.info(
                'Unable to get release information for manual album with rgid: %s'
                % albumid)
            return

        # Since we're just using this to create the bare minimum information to insert an artist/album combo, use the first release
        releaseid = release_list[0]['id']

        release_dict = mb.getRelease(releaseid)

        logger.info(u"Now adding/updating artist: " +
                    release_dict['artist_name'])

        if release_dict['artist_name'].startswith('The '):
            sortname = release_dict['artist_name'][4:]
        else:
            sortname = release_dict['artist_name']

        controlValueDict = {"ArtistID": release_dict['artist_id']}
        newValueDict = {
            "ArtistName": release_dict['artist_name'],
            "ArtistSortName": sortname,
            "DateAdded": helpers.today(),
            "Status": "Paused"
        }

        logger.info("ArtistID: " + release_dict['artist_id'] +
                    " , ArtistName: " + release_dict['artist_name'])

        if headphones.INCLUDE_EXTRAS:
            newValueDict['IncludeExtras'] = 1
            newValueDict['Extras'] = headphones.EXTRAS

        myDB.upsert("artists", newValueDict, controlValueDict)

        logger.info(u"Now adding album: " + release_dict['title'])
        controlValueDict = {"AlbumID": albumid}

        newValueDict = {
            "ArtistID": release_dict['artist_id'],
            "ArtistName": release_dict['artist_name'],
            "AlbumTitle": release_dict['title'],
            "AlbumASIN": release_dict['asin'],
            "ReleaseDate": release_dict['date'],
            "DateAdded": helpers.today(),
            "Type": release_dict['rg_type'],
            "Status": "Snatched"
        }

        myDB.upsert("albums", newValueDict, controlValueDict)

        # Delete existing tracks associated with this AlbumID since we're going to replace them and don't want any extras
        myDB.action('DELETE from tracks WHERE AlbumID=?', [albumid])
        for track in release_dict['tracks']:

            controlValueDict = {"TrackID": track['id'], "AlbumID": albumid}

            newValueDict = {
                "ArtistID": release_dict['artist_id'],
                "ArtistName": release_dict['artist_name'],
                "AlbumTitle": release_dict['title'],
                "AlbumASIN": release_dict['asin'],
                "TrackTitle": track['title'],
                "TrackDuration": track['duration'],
                "TrackNumber": track['number']
            }

            myDB.upsert("tracks", newValueDict, controlValueDict)

        controlValueDict = {"ArtistID": release_dict['artist_id']}
        newValueDict = {"Status": "Paused"}

        myDB.upsert("artists", newValueDict, controlValueDict)
        logger.info(u"Addition complete for: " + release_dict['title'] +
                    " - " + release_dict['artist_name'])

        release = myDB.action('SELECT * from albums WHERE AlbumID=?',
                              [albumid]).fetchone()
        tracks = myDB.select('SELECT * from tracks WHERE AlbumID=?', [albumid])