2019-09-12 12:41:25 +01:00
|
|
|
from spotframework.net.network import Network
|
|
|
|
from spotframework.net.user import NetworkUser
|
|
|
|
from spotframework.engine.playlistengine import PlaylistEngine
|
|
|
|
|
|
|
|
import os
|
|
|
|
import logging
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger('spotframework')
|
|
|
|
|
|
|
|
log_format = '%(asctime)s %(levelname)s %(name)s - %(funcName)s - %(message)s'
|
|
|
|
|
2019-09-13 16:31:40 +01:00
|
|
|
file_handler = logging.FileHandler(".spot/sort_playlist.log")
|
2019-09-12 12:41:25 +01:00
|
|
|
formatter = logging.Formatter(log_format)
|
|
|
|
file_handler.setFormatter(formatter)
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
logger.addHandler(stream_handler)
|
|
|
|
|
|
|
|
|
|
|
|
def go(playlist_name):
|
|
|
|
|
|
|
|
net = Network(NetworkUser(os.environ['SPOTCLIENT'],
|
|
|
|
os.environ['SPOTSECRET'],
|
|
|
|
os.environ['SPOTREFRESH']))
|
2019-10-01 19:20:22 +01:00
|
|
|
net.user.refresh_access_token()
|
2019-09-12 12:41:25 +01:00
|
|
|
|
|
|
|
engine = PlaylistEngine(net)
|
2019-09-24 10:34:02 +01:00
|
|
|
engine.reorder_playlist_by_added_date(playlist_name)
|
2019-09-12 12:41:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if len(sys.argv) > 1:
|
|
|
|
name = sys.argv[1]
|
|
|
|
if len(sys.argv) > 2:
|
|
|
|
for i in sys.argv[2:]:
|
|
|
|
name += ' ' + i
|
|
|
|
go(sys.argv[1])
|
|
|
|
else:
|
|
|
|
name = input('enter playlist name: ')
|
|
|
|
if name == '':
|
|
|
|
exit()
|
|
|
|
go(name)
|