Skip to content

Commit

Permalink
extended getnewshows
Browse files Browse the repository at this point in the history
  • Loading branch information
sualfred committed Jul 18, 2019
1 parent 3af42bf commit 42f2206
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 32 deletions.
9 changes: 7 additions & 2 deletions resources/language/resource.language.de_de/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ msgstr "Vorschläge basierend auf zufälligen Genre"

#: /resources/lib/plugin_listing.py
msgctxt "#32010"
msgid "Mix of recently added episodes and shows"
msgstr "Mischung aus kürzlich hinzugefügten Episoden und Serien"
msgid "Recently added episodes and shows"
msgstr "Kürzlich hinzugefügte Episoden und Serien"

#: /resources/lib/plugin_listing.py
msgctxt "#32011"
Expand All @@ -88,3 +88,8 @@ msgstr "Weiterschauen"
msgctxt "#32014"
msgid "Suggestions based on the last watched item"
msgstr "Vorschläge basierend auf dem zuletzt gesehenen Video"

#: /resources/lib/plugin_listing.py
msgctxt "#32015"
msgid "Recently added unwatched episodes and shows"
msgstr "Kürzlich hinzugefügte ungesehene Episoden und Serien"
7 changes: 6 additions & 1 deletion resources/language/resource.language.en_gb/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ msgstr ""

#: /resources/lib/plugin_listing.py
msgctxt "#32010"
msgid "Mix of recently added episodes and shows"
msgid "Recently added episodes and shows"
msgstr ""

#: /resources/lib/plugin_listing.py
Expand All @@ -81,3 +81,8 @@ msgstr ""
msgctxt "#32014"
msgid "Suggestions based on the last watched item"
msgstr ""

#: /resources/lib/plugin_listing.py
msgctxt "#32015"
msgid "Recently added unwatched episodes and shows"
msgstr ""
8 changes: 8 additions & 0 deletions resources/lib/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import xbmcgui
import json
import time
import datetime
import os

########################
Expand Down Expand Up @@ -65,6 +66,13 @@ def remove_quotes(label):
return label


def get_date(date_time):
date_time_obj = datetime.datetime.strptime(date_time, '%Y-%m-%d %H:%M:%S')
date_obj = date_time_obj.date()

return date_obj


def execute(cmd):
log('Execute: %s' % cmd)
xbmc.executebuiltin(cmd, DEBUG)
Expand Down
86 changes: 60 additions & 26 deletions resources/lib/plugin_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,19 @@ def getnextup(self):
append_items(self.li,episode_details,type='episode')


# get mixed recently added tvshows/episodes
# get recently added episodes of unwatched shows
def getnewshows(self):

filters = [self.unplayed_filter]
if self.tag:
filters.append(self.tag_filter)
filter = {'and': filters}
show_all = True if self.params.get('showall') == 'true' else False

if show_all:
filter = self.tag_filter if self.tag else None

else:
filters = [self.unplayed_filter]
if self.tag:
filters.append(self.tag_filter)
filter = {'and': filters}

json_query = json_call('VideoLibrary.GetTVShows',
properties=tvshow_properties,
Expand All @@ -329,36 +335,64 @@ def getnewshows(self):
return

for tvshow in json_query:
try:
unwatchedepisodes = get_unwatched(tvshow['episode'],tvshow['watchedepisodes'])

if show_all:
''' All recently added episodes. Watched state is ignored and only items added of the same date
will be grouped.
'''
episode_query = json_call('VideoLibrary.GetEpisodes',
properties=episode_properties,
sort=self.sort_recent, limit=2,
params={'tvshowid': int(tvshow['tvshowid'])}
)

unwatchedepisodes = get_unwatched(tvshow['episode'],tvshow['watchedepisodes'])
episode_query = episode_query['result']['episodes']

if unwatchedepisodes == 1:
episode_query = json_call('VideoLibrary.GetEpisodes',
properties=episode_properties,
sort=self.sort_recent,limit=1,
query_filter=self.unplayed_filter,
params={'tvshowid': int(tvshow['tvshowid'])}
)
try:
if not get_date(episode_query[0]['dateadded']) == get_date(episode_query[1]['dateadded']):
raise Exception
append_tvshow = True

except Exception:
append_tvshow = False
append_items(self.li,[episode_query[0]],type='episode')

elif unwatchedepisodes == 1:
''' Recently added episodes based on unwatched or in progress TV shows. Episodes will be grouped
if more than one unwatched episode is available.
'''
episode_query = json_call('VideoLibrary.GetEpisodes',
properties=episode_properties,
sort=self.sort_recent,limit=1,
query_filter=self.unplayed_filter,
params={'tvshowid': int(tvshow['tvshowid'])}
)

try:
episode_query = episode_query['result']['episodes']
except Exception:
log('Get new media: Error fetching by episode details')
else:

append_tvshow = False
append_items(self.li,episode_query,type='episode')

else:
tvshow_query = json_call('VideoLibrary.GetTVShowDetails',
properties=tvshow_properties,
params={'tvshowid': int(tvshow['tvshowid'])}
)
try:
tvshow_query = tvshow_query['result']['tvshowdetails']
except Exception:
log('Get new media: Error fetching by TV show details')
else:
append_tvshow = True

''' Group episodes to show if more than one valid episode is available
'''
if append_tvshow:
tvshow_query = json_call('VideoLibrary.GetTVShowDetails',
properties=tvshow_properties,
params={'tvshowid': int(tvshow['tvshowid'])}
)

tvshow_query = tvshow_query['result']['tvshowdetails']
append_items(self.li,[tvshow_query],type='tvshow')

except Exception as error:
log('Get new media: Not able to parse data for show %s - %s' % (tvshow,error))
pass


# media by genre
def getbygenre(self):
Expand Down
8 changes: 5 additions & 3 deletions resources/lib/plugin_listing.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
tvshows = [
{'name': ADDON.getLocalizedString(32013), 'action': 'getinprogress'},
{'name': ADDON.getLocalizedString(32008), 'action': 'getnextup'},
{'name': ADDON.getLocalizedString(32010), 'action': 'getnewshows'},
{'name': ADDON.getLocalizedString(32015), 'action': 'getnewshows'},
{'name': ADDON.getLocalizedString(32010), 'action': 'getnewshows', 'showall': 'true'},
{'name': ADDON.getLocalizedString(32007), 'action': 'getsimilar'},
{'name': ADDON.getLocalizedString(32014), 'action': 'getsimilar', 'pos': '0'},
{'name': ADDON.getLocalizedString(32009), 'action': 'getbygenre'},
Expand All @@ -61,7 +62,8 @@
emby_tvshows = [
{'name': ADDON.getLocalizedString(32013), 'action': 'getinprogress'},
{'name': ADDON.getLocalizedString(32008), 'action': 'getnextup'},
{'name': ADDON.getLocalizedString(32010), 'action': 'getnewshows'},
{'name': ADDON.getLocalizedString(32015), 'action': 'getnewshows'},
{'name': ADDON.getLocalizedString(32010), 'action': 'getnewshows', 'showall': 'true'},
{'name': ADDON.getLocalizedString(32007), 'action': 'getsimilar'},
{'name': ADDON.getLocalizedString(32014), 'action': 'getsimilar', 'pos': '0'},
{'name': ADDON.getLocalizedString(32009), 'action': 'getbygenre'},
Expand Down Expand Up @@ -118,7 +120,7 @@ def widgets(self):


def _get_url(self,widget):
return self._encode_url(info=widget['action'], type=self.cat_type, tag=self.tag, pos=widget.get('pos',''), filter_args=widget.get('filter',''), sort_args=widget.get('sort',''), limit=widget.get('limit',''))
return self._encode_url(info=widget['action'], type=self.cat_type, tag=self.tag, pos=widget.get('pos',''), filter_args=widget.get('filter',''), sort_args=widget.get('sort',''), limit=widget.get('limit',''), showall=widget.get('showall',''))


def _encode_url(self,**kwargs):
Expand Down

0 comments on commit 42f2206

Please sign in to comment.