trim backup script, check artists for uri during export

This commit is contained in:
aj 2020-07-01 10:42:39 +01:00
parent 498c873050
commit 232551bcb0
2 changed files with 11 additions and 28 deletions

View File

@ -11,23 +11,20 @@ if __name__ == '__main__':
logger = logging.getLogger('spotframework')
log_format = '%(asctime)s %(levelname)s %(name)s:%(funcName)s - %(message)s'
file_handler = logging.FileHandler(".spot/backup.log")
formatter = logging.Formatter(log_format)
file_handler.setFormatter(formatter)
file_handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s %(name)s:%(funcName)s - %(message)s'))
logger.addHandler(file_handler)
stream_log_format = '%(levelname)s %(name)s:%(funcName)s - %(message)s'
stream_formatter = logging.Formatter(stream_log_format)
stream_handler = logging.StreamHandler()
stream_handler.setFormatter(stream_formatter)
stream_handler.setFormatter(logging.Formatter('%(levelname)s %(name)s:%(funcName)s - %(message)s'))
logger.addHandler(stream_handler)
# try:
datepath = str(datetime.datetime.now()).split(' ')[0].replace('-', '/')
totalpath = os.path.join(sys.argv[1], datepath)
if not os.path.exists(totalpath):
logger.info(f'creating path {totalpath}')
os.makedirs(totalpath)
network = Network(NetworkUser(client_id=os.environ['SPOT_CLIENT'],
client_secret=os.environ['SPOT_SECRET'],
@ -39,23 +36,9 @@ if __name__ == '__main__':
for playlist in playlists:
try:
playlist.tracks = network.get_playlist_tracks(playlist.uri)
csvwrite.export_playlist(playlist, totalpath)
except SpotifyNetworkException:
logger.exception(f'error occured during {playlist.name} track retrieval')
path = sys.argv[1]
datepath = str(datetime.datetime.now()).split(' ')[0].replace('-', '/')
totalpath = os.path.join(path, datepath)
pathdir = os.path.dirname(totalpath)
if not os.path.exists(totalpath):
os.makedirs(totalpath)
for play in playlists:
csvwrite.export_playlist(play, totalpath)
except SpotifyNetworkException:
logger.exception('error occured during user playlist retrieval')
# except Exception as e:
# logger.exception(f'exception occured')
logger.exception('error occured during user playlists retrieval')

View File

@ -28,7 +28,7 @@ def export_playlist(playlist, path, name=None):
'added': track.added_at,
'track id': track.track.uri.object_id if track.track.uri is not None else 'none',
'album id': track.track.album.uri.object_id if track.track.album.uri is not None else 'none',
'artist id': ', '.join(x.uri.object_id for x in track.track.artists),
'artist id': ', '.join(x.uri.object_id for x in track.track.artists if x.uri is not None),
'added by': track.added_by.id,
'album artist': ', '.join(x.name for x in track.track.album.artists),
'artist': ', '.join(x.name for x in track.track.artists)