Starting to add features from request #101
--jbop historyToday --jbop historyWeek --jbop historyMonth
This commit is contained in:
parent
aff964522b
commit
4bb37d0073
@ -118,7 +118,7 @@ user_lst = [x.title for x in plex.myPlexAccount().users()]
|
|||||||
section_lst = [x.title for x in plex.library.sections()]
|
section_lst = [x.title for x in plex.library.sections()]
|
||||||
playlist_lst = [x.title for x in plex.playlists()]
|
playlist_lst = [x.title for x in plex.playlists()]
|
||||||
today = datetime.datetime.now().date()
|
today = datetime.datetime.now().date()
|
||||||
|
weeknum = datetime.date(today.year, today.month, today.day).isocalendar()[1]
|
||||||
|
|
||||||
def actions():
|
def actions():
|
||||||
"""
|
"""
|
||||||
@ -134,7 +134,9 @@ def actions():
|
|||||||
def selectors():
|
def selectors():
|
||||||
"""Playlist selections and titles
|
"""Playlist selections and titles
|
||||||
"""
|
"""
|
||||||
selections = {'history': 'Aired Today {month}-{day}',
|
selections = {'historyToday':'Aired Today {month}-{day} in History',
|
||||||
|
'historyWeek': 'Aired This Week ({week}) in History',
|
||||||
|
'historyMonth': 'Aired in {month}',
|
||||||
'popularTv': 'Most Popular TV Shows ({days} days)',
|
'popularTv': 'Most Popular TV Shows ({days} days)',
|
||||||
'popularMovies': 'Most Popular Movies ({days} days)',
|
'popularMovies': 'Most Popular Movies ({days} days)',
|
||||||
'genre': '{title} Playlist',
|
'genre': '{title} Playlist',
|
||||||
@ -168,7 +170,7 @@ def get_home_stats(time_range, stats_count):
|
|||||||
sys.stderr.write("Tautulli API 'get_home_stats' request failed: {0}.".format(e))
|
sys.stderr.write("Tautulli API 'get_home_stats' request failed: {0}.".format(e))
|
||||||
|
|
||||||
|
|
||||||
def sort_by_dates(video):
|
def sort_by_dates(video, date_type):
|
||||||
"""Find air dates of content
|
"""Find air dates of content
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
@ -187,30 +189,39 @@ def sort_by_dates(video):
|
|||||||
ad_year = video.originallyAvailableAt.year
|
ad_year = video.originallyAvailableAt.year
|
||||||
ad_month = video.originallyAvailableAt.month
|
ad_month = video.originallyAvailableAt.month
|
||||||
ad_day = video.originallyAvailableAt.day
|
ad_day = video.originallyAvailableAt.day
|
||||||
ad_week = int(datetime.date(ad_year, ad_month, ad_day).strftime("%V"))
|
ad_week = int(datetime.date(ad_year, ad_month, ad_day).isocalendar()[1])
|
||||||
|
|
||||||
|
if date_type == 'historyToday':
|
||||||
if ad_month == today.month and ad_day == today.day:
|
if ad_month == today.month and ad_day == today.day:
|
||||||
# todo-me return object
|
|
||||||
return [[video.ratingKey] + [str(video.originallyAvailableAt)]]
|
return [[video.ratingKey] + [str(video.originallyAvailableAt)]]
|
||||||
|
if date_type == 'historyWeek':
|
||||||
|
if ad_week == weeknum:
|
||||||
|
return [[video.ratingKey] + [str(video.originallyAvailableAt)]]
|
||||||
|
if date_type == 'historyMonth':
|
||||||
|
if ad_month == today.month:
|
||||||
|
return [[video.ratingKey] + [str(video.originallyAvailableAt)]]
|
||||||
|
|
||||||
|
# todo-me return object
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# print(e)
|
# print(e)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def get_all_content(library_name):
|
def get_content(library_name, search, term):
|
||||||
"""Get all movies or episodes from LIBRARY_NAME
|
"""Get all movies or episodes from LIBRARY_NAME
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
library_name: list
|
library_name: list
|
||||||
list of library objects
|
list of library objects
|
||||||
|
search: str
|
||||||
|
jbop value for searching
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
-------
|
-------
|
||||||
list
|
list
|
||||||
Sorted list of Movie and episodes that
|
Sorted list of Movie and episodes that
|
||||||
aired on today's date.
|
aired on today's date.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
# todo-me expand function for keyword searching
|
# todo-me expand function for keyword searching
|
||||||
child_lst = []
|
child_lst = []
|
||||||
@ -218,13 +229,13 @@ def get_all_content(library_name):
|
|||||||
for library in library_name:
|
for library in library_name:
|
||||||
for child in plex.library.section(library).all():
|
for child in plex.library.section(library).all():
|
||||||
if child.type == 'movie':
|
if child.type == 'movie':
|
||||||
if sort_by_dates(child):
|
if sort_by_dates(child, search):
|
||||||
item_date = sort_by_dates(child)
|
item_date = sort_by_dates(child, search)
|
||||||
child_lst += item_date
|
child_lst += item_date
|
||||||
elif child.type == 'show':
|
elif child.type == 'show':
|
||||||
for episode in child.episodes():
|
for episode in child.episodes():
|
||||||
if sort_by_dates(episode):
|
if sort_by_dates(episode, search):
|
||||||
item_date = sort_by_dates(episode)
|
item_date = sort_by_dates(episode, search)
|
||||||
child_lst += item_date
|
child_lst += item_date
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
@ -261,14 +272,9 @@ def share_playlists(playlist_titles, users):
|
|||||||
|
|
||||||
def show_playlist(playlist_title, playlist_keys):
|
def show_playlist(playlist_title, playlist_keys):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
playlist_keys
|
playlist_keys
|
||||||
|
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
playlist_list = []
|
playlist_list = []
|
||||||
for key in playlist_keys:
|
for key in playlist_keys:
|
||||||
@ -278,27 +284,22 @@ def show_playlist(playlist_title, playlist_keys):
|
|||||||
title = "{}".format(episode._prettyfilename())
|
title = "{}".format(episode._prettyfilename())
|
||||||
playlist_list.append(title)
|
playlist_list.append(title)
|
||||||
else:
|
else:
|
||||||
title = "{} ({})".format(plex_obj.title, plex_obj.year)
|
title = u"{} ({})".format(plex_obj._prettyfilename(), plex_obj.year)
|
||||||
playlist_list.append(title)
|
playlist_list.append(title)
|
||||||
|
|
||||||
print("Contents of Playlist {title}:\n{playlist}".format(title=playlist_title,
|
print(u"Contents of Playlist {title}:\n{playlist}".format(title=playlist_title,
|
||||||
playlist=', '.join(playlist_list)))
|
playlist=', '.join(playlist_list)))
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
|
|
||||||
def create_playlist(playlist_title, playlist_keys, server, user):
|
def create_playlist(playlist_title, playlist_keys, server, user):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
playlist_title
|
playlist_title
|
||||||
playlist_keys
|
playlist_keys
|
||||||
server
|
server
|
||||||
user
|
user
|
||||||
|
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
playlist_list = []
|
playlist_list = []
|
||||||
for key in playlist_keys:
|
for key in playlist_keys:
|
||||||
@ -326,14 +327,9 @@ def create_playlist(playlist_title, playlist_keys, server, user):
|
|||||||
|
|
||||||
def delete_playlist(playlist_dict):
|
def delete_playlist(playlist_dict):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
playlist_dict
|
playlist_dict
|
||||||
|
|
||||||
Returns
|
|
||||||
-------
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
server = playlist_dict['server']
|
server = playlist_dict['server']
|
||||||
@ -344,11 +340,21 @@ def delete_playlist(playlist_dict):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
for playlist in server.playlists():
|
for playlist in server.playlists():
|
||||||
if jbop == 'history':
|
if jbop == 'historyToday':
|
||||||
if playlist.title.startswith('Aired Today'):
|
if playlist.title.startswith('Aired Today'):
|
||||||
playlist.delete()
|
playlist.delete()
|
||||||
print("...Deleted {playlist.title} for '{user}'."
|
print("...Deleted {playlist.title} for '{user}'."
|
||||||
.format(playlist=playlist, user=user))
|
.format(playlist=playlist, user=user))
|
||||||
|
elif jbop == 'historyWeek':
|
||||||
|
if playlist.title.startswith('Aired This Week'):
|
||||||
|
playlist.delete()
|
||||||
|
print("...Deleted {playlist.title} for '{user}'."
|
||||||
|
.format(playlist=playlist, user=user))
|
||||||
|
elif jbop == 'historyMonth':
|
||||||
|
if playlist.title.startswith('Aired in'):
|
||||||
|
playlist.delete()
|
||||||
|
print("...Deleted {playlist.title} for '{user}'."
|
||||||
|
.format(playlist=playlist, user=user))
|
||||||
elif jbop == 'popularMovies':
|
elif jbop == 'popularMovies':
|
||||||
if playlist.title == pop_movie:
|
if playlist.title == pop_movie:
|
||||||
playlist.delete()
|
playlist.delete()
|
||||||
@ -411,8 +417,10 @@ if __name__ == "__main__":
|
|||||||
pop_tv_title = selectors()['popularTv'].format(days=opts.days)
|
pop_tv_title = selectors()['popularTv'].format(days=opts.days)
|
||||||
|
|
||||||
playlist_dict = {'jbop': opts.jbop,
|
playlist_dict = {'jbop': opts.jbop,
|
||||||
|
'custom': opts.name,
|
||||||
'pop_tv': pop_tv_title,
|
'pop_tv': pop_tv_title,
|
||||||
'pop_movie': pop_movie_title}
|
'pop_movie': pop_movie_title,
|
||||||
|
'limit': opts.limit}
|
||||||
|
|
||||||
# Defining users
|
# Defining users
|
||||||
if opts.allUsers and not opts.user:
|
if opts.allUsers and not opts.user:
|
||||||
@ -450,13 +458,29 @@ if __name__ == "__main__":
|
|||||||
delete_playlist(playlist_dict)
|
delete_playlist(playlist_dict)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if opts.jbop == 'history':
|
if opts.jbop == 'historyToday':
|
||||||
try:
|
try:
|
||||||
keys_list = get_all_content(opts.libraries)
|
keys_list = get_content(opts.libraries, opts.jbop, '')
|
||||||
except TypeError as e:
|
except TypeError as e:
|
||||||
print("Libraries are not defined for {}. Use --libraries.".format(opts.jbop))
|
print("Libraries are not defined for {}. Use --libraries.".format(opts.jbop))
|
||||||
exit("Error: {}".format(e))
|
exit("Error: {}".format(e))
|
||||||
title = selectors()['history'].format(month=today.month, day=today.day)
|
title = selectors()['historyToday'].format(month=today.month, day=today.day)
|
||||||
|
|
||||||
|
if opts.jbop == 'historyWeek':
|
||||||
|
try:
|
||||||
|
keys_list = get_content(opts.libraries, opts.jbop, '')
|
||||||
|
except TypeError as e:
|
||||||
|
print("Libraries are not defined for {}. Use --libraries.".format(opts.jbop))
|
||||||
|
exit("Error: {}".format(e))
|
||||||
|
title = selectors()['historyWeek'].format(week=weeknum)
|
||||||
|
|
||||||
|
if opts.jbop == 'historyMonth':
|
||||||
|
try:
|
||||||
|
keys_list = get_content(opts.libraries, opts.jbop, '')
|
||||||
|
except TypeError as e:
|
||||||
|
print("Libraries are not defined for {}. Use --libraries.".format(opts.jbop))
|
||||||
|
exit("Error: {}".format(e))
|
||||||
|
title = selectors()['historyMonth'].format(month=today.strftime("%B"))
|
||||||
|
|
||||||
if opts.jbop == 'popularTv':
|
if opts.jbop == 'popularTv':
|
||||||
home_stats = get_home_stats(opts.days, opts.top)
|
home_stats = get_home_stats(opts.days, opts.top)
|
||||||
|
Loading…
Reference in New Issue
Block a user