#141 separate title creation to a function.
Now update action will allow updating custom names or random selector
This commit is contained in:
parent
88f775e646
commit
4c014cfc24
@ -372,42 +372,11 @@ def build_playlist(jbop, libraries=None, days=None, top=None, filters=None, sear
|
|||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
key_list, title
|
key_list
|
||||||
|
|
||||||
"""
|
"""
|
||||||
keys_list = []
|
keys_list = []
|
||||||
title = ''
|
|
||||||
if jbop == 'historyToday':
|
|
||||||
title = selectors()['historyToday'].format(month=today.month, day=today.day)
|
|
||||||
|
|
||||||
elif jbop == 'historyWeek':
|
|
||||||
title = selectors()['historyWeek'].format(week=weeknum)
|
|
||||||
|
|
||||||
elif jbop == 'historyMonth':
|
|
||||||
title = selectors()['historyMonth'].format(month=today.strftime("%B"))
|
|
||||||
|
|
||||||
elif jbop == 'custom':
|
|
||||||
if search and not filters:
|
|
||||||
title = ' '.join(search.values()).capitalize()
|
|
||||||
elif filters and not search:
|
|
||||||
title = ' '.join(filters.values()).capitalize()
|
|
||||||
elif search and filters:
|
|
||||||
search_title = ' '.join(search.values()).capitalize()
|
|
||||||
filters_title = ' '.join(filters.values()).capitalize()
|
|
||||||
title = filters_title + ' ' + search_title
|
|
||||||
title = selectors()['custom'].format(custom=title)
|
|
||||||
|
|
||||||
elif jbop == 'random':
|
|
||||||
if not limit:
|
|
||||||
print("Random selector needs a limit. Use --limit.")
|
|
||||||
exit()
|
|
||||||
title = selectors()['random'].format(count=limit, libraries='/'.join(libraries.values()))
|
|
||||||
|
|
||||||
if jbop in ['popularTv', 'popularMovies']:
|
if jbop in ['popularTv', 'popularMovies']:
|
||||||
if jbop == 'popularTv':
|
|
||||||
title = selectors()['popularTv'].format(days=days)
|
|
||||||
if jbop == 'popularMovies':
|
|
||||||
title = selectors()['popularMovies'].format(days=days)
|
|
||||||
home_stats = get_home_stats(days, top)
|
home_stats = get_home_stats(days, top)
|
||||||
for stat in home_stats:
|
for stat in home_stats:
|
||||||
if stat['stat_id'] in ['popular_tv', 'popular_movies']:
|
if stat['stat_id'] in ['popular_tv', 'popular_movies']:
|
||||||
@ -420,7 +389,7 @@ def build_playlist(jbop, libraries=None, days=None, top=None, filters=None, sear
|
|||||||
print("Libraries are not defined for {}. Use --libraries.".format(jbop))
|
print("Libraries are not defined for {}. Use --libraries.".format(jbop))
|
||||||
exit("Error: {}".format(e))
|
exit("Error: {}".format(e))
|
||||||
|
|
||||||
return keys_list, title
|
return keys_list
|
||||||
|
|
||||||
|
|
||||||
def share_playlists(playlist_titles, users):
|
def share_playlists(playlist_titles, users):
|
||||||
@ -505,7 +474,7 @@ def create_playlist(playlist_title, playlist_keys, server, user):
|
|||||||
print("...Added Playlist: {title} to '{user}'.".format(title=playlist_title, user=user))
|
print("...Added Playlist: {title} to '{user}'.".format(title=playlist_title, user=user))
|
||||||
|
|
||||||
|
|
||||||
def delete_playlist(playlist_dict, jbop, libraries=None, limit=None):
|
def delete_playlist(playlist_dict, title):
|
||||||
"""
|
"""
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
@ -513,54 +482,56 @@ def delete_playlist(playlist_dict, jbop, libraries=None, limit=None):
|
|||||||
"""
|
"""
|
||||||
server = playlist_dict['server']
|
server = playlist_dict['server']
|
||||||
user = playlist_dict['user']
|
user = playlist_dict['user']
|
||||||
pop_movie = playlist_dict['pop_movie']
|
|
||||||
pop_tv = playlist_dict['pop_tv']
|
|
||||||
user_selected = playlist_dict['user_selected']
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# todo-me this needs improvement
|
# todo-me this needs improvement
|
||||||
for playlist in server.playlists():
|
for playlist in server.playlists():
|
||||||
if jbop == 'historyToday':
|
|
||||||
if playlist.title.startswith('Aired Today'):
|
|
||||||
playlist.delete()
|
|
||||||
print("...Deleted Playlist: {playlist.title} for '{user}'."
|
|
||||||
.format(playlist=playlist, user=user))
|
|
||||||
elif jbop == 'historyWeek':
|
|
||||||
if playlist.title.startswith('Aired This Week'):
|
|
||||||
playlist.delete()
|
|
||||||
print("...Deleted Playlist: {playlist.title} for '{user}'."
|
|
||||||
.format(playlist=playlist, user=user))
|
|
||||||
elif jbop == 'historyMonth':
|
|
||||||
if playlist.title.startswith('Aired in'):
|
|
||||||
playlist.delete()
|
|
||||||
print("...Deleted Playlist: {playlist.title} for '{user}'."
|
|
||||||
.format(playlist=playlist, user=user))
|
|
||||||
elif jbop == 'popularMovies':
|
|
||||||
if playlist.title == pop_movie:
|
|
||||||
playlist.delete()
|
|
||||||
print("...Deleted Playlist: {playlist.title} for '{user}'."
|
|
||||||
.format(playlist=playlist, user=user))
|
|
||||||
elif jbop == 'popularTv':
|
|
||||||
if playlist.title == pop_tv:
|
|
||||||
playlist.delete()
|
|
||||||
print("...Deleted Playlist: {playlist.title} for '{user}'."
|
|
||||||
.format(playlist=playlist, user=user))
|
|
||||||
elif jbop == 'random':
|
|
||||||
title = selectors()['random'].format(count=limit, libraries='/'.join(libraries.values()))
|
|
||||||
if playlist.title == title:
|
if playlist.title == title:
|
||||||
playlist.delete()
|
playlist.delete()
|
||||||
print("...Deleted Playlist: {playlist.title} for '{user}'."
|
print("...Deleted Playlist: {playlist.title} for '{user}'."
|
||||||
.format(playlist=playlist, user=user))
|
.format(playlist=playlist, user=user))
|
||||||
elif playlist.title in user_selected:
|
|
||||||
playlist.delete()
|
|
||||||
print("...Deleted Playlist: {playlist.title} for '{user}'."
|
|
||||||
.format(playlist=playlist, user=user))
|
|
||||||
|
|
||||||
except:
|
except:
|
||||||
# print("Playlist not found on '{user}' account".format(user=user))
|
# print("Playlist not found on '{user}' account".format(user=user))
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def create_title(jbop, libraries, days, filters, search, limit):
|
||||||
|
title = ''
|
||||||
|
if jbop == 'historyToday':
|
||||||
|
title = selectors()['historyToday'].format(month=today.month, day=today.day)
|
||||||
|
|
||||||
|
elif jbop == 'historyWeek':
|
||||||
|
title = selectors()['historyWeek'].format(week=weeknum)
|
||||||
|
|
||||||
|
elif jbop == 'historyMonth':
|
||||||
|
title = selectors()['historyMonth'].format(month=today.strftime("%B"))
|
||||||
|
|
||||||
|
elif jbop == 'custom':
|
||||||
|
if search and not filters:
|
||||||
|
title = ' '.join(search.values()).capitalize()
|
||||||
|
elif filters and not search:
|
||||||
|
title = ' '.join(filters.values()).capitalize()
|
||||||
|
elif search and filters:
|
||||||
|
search_title = ' '.join(search.values()).capitalize()
|
||||||
|
filters_title = ' '.join(filters.values()).capitalize()
|
||||||
|
title = filters_title + ' ' + search_title
|
||||||
|
title = selectors()['custom'].format(custom=title)
|
||||||
|
|
||||||
|
elif jbop == 'random':
|
||||||
|
if not limit:
|
||||||
|
print("Random selector needs a limit. Use --limit.")
|
||||||
|
exit()
|
||||||
|
title = selectors()['random'].format(count=limit, libraries='/'.join(libraries.values()))
|
||||||
|
|
||||||
|
if jbop in ['popularTv', 'popularMovies']:
|
||||||
|
if jbop == 'popularTv':
|
||||||
|
title = selectors()['popularTv'].format(days=days)
|
||||||
|
if jbop == 'popularMovies':
|
||||||
|
title = selectors()['popularMovies'].format(days=days)
|
||||||
|
|
||||||
|
return title
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="Create, share, and clean Playlists for users.",
|
parser = argparse.ArgumentParser(description="Create, share, and clean Playlists for users.",
|
||||||
@ -614,8 +585,6 @@ if __name__ == "__main__":
|
|||||||
playlists = []
|
playlists = []
|
||||||
keys_list = []
|
keys_list = []
|
||||||
playlist_dict = {'data': []}
|
playlist_dict = {'data': []}
|
||||||
pop_movie_title = selectors()['popularMovies'].format(days=opts.days)
|
|
||||||
pop_tv_title = selectors()['popularTv'].format(days=opts.days)
|
|
||||||
|
|
||||||
if opts.search:
|
if opts.search:
|
||||||
search = dict([opts.search])
|
search = dict([opts.search])
|
||||||
@ -651,17 +620,13 @@ if __name__ == "__main__":
|
|||||||
'server': user_server,
|
'server': user_server,
|
||||||
'user': user,
|
'user': user,
|
||||||
'user_selected': user_selected,
|
'user_selected': user_selected,
|
||||||
'all_playlists': all_playlists,
|
'all_playlists': all_playlists})
|
||||||
'pop_tv': pop_tv_title,
|
|
||||||
'pop_movie': pop_movie_title})
|
|
||||||
|
|
||||||
if opts.self or not users:
|
if opts.self or not users:
|
||||||
playlist_dict['data'].append({'server': plex,
|
playlist_dict['data'].append({'server': plex,
|
||||||
'user': 'admin',
|
'user': 'admin',
|
||||||
'user_selected': selected_playlists,
|
'user_selected': selected_playlists,
|
||||||
'all_playlists': playlist_lst,
|
'all_playlists': playlist_lst})
|
||||||
'pop_tv': pop_tv_title,
|
|
||||||
'pop_movie': pop_movie_title})
|
|
||||||
|
|
||||||
if not opts.jbop and opts.action == 'show':
|
if not opts.jbop and opts.action == 'show':
|
||||||
print("Displaying the user's playlist(s)...")
|
print("Displaying the user's playlist(s)...")
|
||||||
@ -671,15 +636,16 @@ if __name__ == "__main__":
|
|||||||
print("{}'s current playlist(s): {}".format(user, ', '.join(playlists)))
|
print("{}'s current playlist(s): {}".format(user, ', '.join(playlists)))
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
|
if libraries:
|
||||||
|
title = create_title(opts.jbop, libraries, opts.days, filters, search, opts.limit)
|
||||||
|
|
||||||
|
keys_list = build_playlist(opts.jbop, libraries, opts.days, opts.top, filters, search, opts.limit)
|
||||||
|
else:
|
||||||
# Remove or build playlists
|
# Remove or build playlists
|
||||||
if opts.action == 'remove':
|
if opts.action == 'remove':
|
||||||
print("Deleting the playlist(s)...")
|
print("Deleting the playlist(s)...")
|
||||||
for data in playlist_dict['data']:
|
for data in playlist_dict['data']:
|
||||||
delete_playlist(data, opts.jbop, libraries, opts.limit)
|
delete_playlist(data, title)
|
||||||
|
|
||||||
else:
|
|
||||||
if libraries:
|
|
||||||
keys_list, title = build_playlist(opts.jbop, libraries, opts.days, opts.top, filters, search, opts.limit)
|
|
||||||
else:
|
else:
|
||||||
print('This function requires libraries to be listed.')
|
print('This function requires libraries to be listed.')
|
||||||
exit()
|
exit()
|
||||||
@ -701,7 +667,7 @@ if __name__ == "__main__":
|
|||||||
if opts.action == 'update':
|
if opts.action == 'update':
|
||||||
print("Deleting the playlist(s)...")
|
print("Deleting the playlist(s)...")
|
||||||
for data in playlist_dict['data']:
|
for data in playlist_dict['data']:
|
||||||
delete_playlist(data, opts.jbop, libraries, opts.limit)
|
delete_playlist(data, title)
|
||||||
print('Creating playlist(s)...')
|
print('Creating playlist(s)...')
|
||||||
for data in playlist_dict['data']:
|
for data in playlist_dict['data']:
|
||||||
create_playlist(title, keys_list, data['server'], data['user'])
|
create_playlist(title, keys_list, data['server'], data['user'])
|
||||||
|
Loading…
Reference in New Issue
Block a user