Skip to content
This repository has been archived by the owner on Mar 18, 2022. It is now read-only.

Commit

Permalink
Fix home lists after recent API changes (#191)
Browse files Browse the repository at this point in the history
* New retrieve method for home lists

* too many blank lines fix

* Add exclusion list to addCat, a method to prevent some indexes to be listed.
Automatically generate exclusion list for home lists to prevent double listing
of watchlist and continue watchlist.
Watchlist and continue watching from home lists would be cached so would
not work correctly.

* Version and changelog update

* Fix exclude_index iteration if None

* Fix language new home lists
  • Loading branch information
arvvoid authored Apr 23, 2021
1 parent 5cfc672 commit 2193bcd
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 24 deletions.
9 changes: 5 additions & 4 deletions addon.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<addon id="plugin.video.hbogoeu" name="hGO EU" provider-name="arvvoid" version="2.6.3">
<addon id="plugin.video.hbogoeu" name="hGO EU" provider-name="arvvoid" version="2.7.0">
<requires>
<import addon="xbmc.python" version="2.26.0" />
<import addon="script.module.kodi-six" version="0.1.0" />
Expand Down Expand Up @@ -44,9 +44,10 @@ If an official app is available for your platform, use it instead of this.
<source>https://github.com/arvvoid/plugin.video.hbogoeu</source>
<website>https://arvvoid.github.io/plugin.video.hbogoeu</website>
<news>
- Fix minor subtitle offset (sp/no handler)
- Translations updates
- Minor fixes and optimizations
- Hot Fix: new retrieve method for home lists [EU region]
- This fix avoid the "a new version of the application should be used" error message coming from HBO Go
- The additional home lists (recommendation, featured, various editor lists, ecc... are fully functional again)
- Minor fixes
</news>
<assets>
<icon>resources/icon.png</icon>
Expand Down
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
v.2.7.0
- Hot Fix: new retrieve method for home lists [EU region]
- This fix avoid the "a new version of the application should be used" error message coming from HBO Go
- The additional home lists (recommendation, featured, various editor lists, ecc... are fully functional again)
- Minor fixes

v.2.6.3
- Fix minor subtitle offset (sp/no handler)
- Translations updates
Expand Down
15 changes: 14 additions & 1 deletion hbogolib/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def router(self, arguments):
content_id = None
mode = None
vote = None
exclude_list = None

try:
url = unquote(params["url"])
Expand Down Expand Up @@ -128,14 +129,26 @@ def router(self, arguments):
xbmc.log("[" + str(self.addon_id) + "] " + "ROUTER - vote warning: " + traceback.format_exc(),
xbmc.LOGDEBUG)

try:
exclude_list = str(params["exclude"])
exclude_list = [int(e) if e.isdigit() else e for e in exclude_list.split(',')]
except KeyError:
pass
except Exception:
xbmc.log("[" + str(self.addon_id) + "] " + "ROUTER - exclude list warning: " + traceback.format_exc(),
xbmc.LOGDEBUG)

if mode is None or url is None or len(url) < 1:
self.start()
self.handler.categories()

elif mode == HbogoConstants.ACTION_LIST:
self.start()
self.handler.setDispCat(name)
self.handler.list(url)
if exclude_list is None:
self.handler.list(url)
else:
self.handler.list(url, False, exclude_list)

elif mode == HbogoConstants.ACTION_SEASON:
self.start()
Expand Down
2 changes: 1 addition & 1 deletion hbogolib/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ def login(self):
def categories(self):
pass

def list(self, url, simple=False):
def list(self, url, simple=False, exclude_list=None):
pass

def season(self, url):
Expand Down
71 changes: 55 additions & 16 deletions hbogolib/handlereu.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def __init__(self, handle, base_url, country, forceeng=False):
self.API_URL_CUSTOMER_GROUP = ""
self.API_URL_GROUP = ""
self.API_URL_GROUPS = ""
self.API_URL_MENU = ""
self.API_URL_CONTENT = ""
self.API_URL_PURCHASE = ""
self.API_URL_SEARCH = ""
Expand All @@ -79,6 +80,8 @@ def __init__(self, handle, base_url, country, forceeng=False):
self.HistoryGroupId = ""
self.ContinueWatchingGroupId = ""
self.KidsGroupId = ""
self.homeGroupUrlEng = ""
self.homeGroupUrl = ""
self.loggedin_headers = {}
self.JsonHis = ""

Expand Down Expand Up @@ -143,6 +146,7 @@ def init_api(self, country, forceeng=False):
self.API_URL_CUSTOMER_GROUP = 'https://' + self.API_HOST + '/v8/CustomerGroup/json/' + self.LANGUAGE_CODE + '/' + self.API_PLATFORM + '/'
self.API_URL_GROUP = 'https://' + self.API_HOST + '/v8/Group/json/' + self.LANGUAGE_CODE + '/ANMO/'
self.API_URL_GROUPS = 'https://' + self.API_HOST + '/v8/Groups/json/' + self.LANGUAGE_CODE + '/ANMO/0/True'
self.API_URL_MENU = 'https://' + self.API_HOST + '/v8/Menu/json/ENG/APTV/0/False'
self.API_URL_CONTENT = 'https://' + self.API_HOST + '/v8/Content/json/' + self.LANGUAGE_CODE + '/' + self.API_PLATFORM + '/'
self.API_URL_PURCHASE = 'https://' + self.API_HOST + '/v8/Purchase/Json/' + self.LANGUAGE_CODE + '/' + self.API_PLATFORM
self.API_URL_SEARCH = 'https://' + self.API_HOST + '/v8/Search/Json/' + self.LANGUAGE_CODE + '/' + self.API_PLATFORM + '/'
Expand Down Expand Up @@ -823,7 +827,6 @@ def categories(self):
xbmcgui.Dialog().ok(self.LB_ERROR, self.language(30004))
return

position_home = -1
position_series = -1
position_movies = -1

Expand All @@ -832,13 +835,11 @@ def categories(self):
# Find key categories positions
try:
for cat in jsonrsp['Items']:
if py2_encode(cat["Tracking"]['Name']) == "Home":
position_home = position
if py2_encode(cat["Tracking"]['Name']) == "Series":
position_series = position
if py2_encode(cat["Tracking"]['Name']) == "Movies":
position_movies = position
if position_home > -1 and position_series > -1 and position_movies > -1:
if position_series > -1 and position_movies > -1:
break
position += 1
except Exception:
Expand All @@ -863,25 +864,61 @@ def categories(self):
if self.addon.getSetting('show_kids') == 'true':
self.addCat(py2_encode(self.language(30729)), self.API_URL_GROUP + self.KidsGroupId + '/0/0/0/0/0/0/True', self.get_media_resource('kids.png'), HbogoConstants.ACTION_LIST)

if position_home != -1:
if self.addon.getSetting('group_home') == 'true':
self.addCat(py2_encode(self.language(30733)),
jsonrsp['Items'][position_home]['ObjectUrl'].replace('/0/{sort}/{pageIndex}/{pageSize}/0/0', '/0/0/1/1024/0/0'),
self.get_media_resource('DefaultFolder.png'), HbogoConstants.ACTION_LIST)
else:
self.list(jsonrsp['Items'][position_home]['ObjectUrl'].replace('/0/{sort}/{pageIndex}/{pageSize}/0/0', '/0/0/1/1024/0/0'), True)
jsonrsp = self.get_from_hbogo(self.API_URL_MENU)
# Find key home
try:
for cat in jsonrsp['Items']:
if py2_encode(cat['Name']) == "Home":
self.homeGroupUrlEng = cat['ObjectUrl']
self.homeGroupUrl = cat['ObjectUrl']
if self.LANGUAGE_CODE != "ENG":
self.homeGroupUrl = self.homeGroupUrl.replace("ENG", self.LANGUAGE_CODE)
break
except Exception:
self.log("Unexpected error in find key in menu for home: " + traceback.format_exc())

jsonrsp = self.get_from_hbogo(self.homeGroupUrlEng)
excludeindex_home = []
if jsonrsp is False:
pass
else:
self.log("No Home Category found")
try:
if jsonrsp['ErrorMessage']:
self.log("Get home list exclude index Error: " + py2_encode(jsonrsp['ErrorMessage']))
pass
except KeyError:
pass # all is ok no error message just pass
except Exception:
self.log("Unexpected error: " + traceback.format_exc())
pass
# find watchlist and continue watching positions for exclusion
if len(jsonrsp['Container']) > 1:
for container_index in range(0, len(jsonrsp['Container'])):
container_item = jsonrsp['Container'][container_index]
if py2_encode(container_item['Name']) == "Watchlist" or py2_encode(container_item['Name']) == "Continue Watching":
excludeindex_home.append(container_index)
if len(excludeindex_home) > 1:
break

if self.addon.getSetting('group_home') == 'true':
self.addCat(py2_encode(self.language(30733)),
self.homeGroupUrl,
self.get_media_resource('DefaultFolder.png'), HbogoConstants.ACTION_LIST, ','.join(str(e) for e in excludeindex_home))
else:
self.list(self.homeGroupUrl, True, excludeindex_home)

KodiUtil.endDir(self.handle, None, True)

def list(self, url, simple=False):
def list(self, url, simple=False, excludeindex=None):
if not self.chk_login():
self.login()
self.log("List: " + str(url))

self.reset_media_type_counters()

if excludeindex is None:
excludeindex = []

jsonrsp = self.get_from_hbogo(url)
if jsonrsp is False:
return
Expand All @@ -904,8 +941,9 @@ def list(self, url, simple=False):
if len(jsonrsp['Container']) > 1:
for container_index in range(0, len(jsonrsp['Container'])):
container_item = jsonrsp['Container'][container_index]
self.addCat(py2_encode(container_item['Name']), container_item['ObjectUrl'],
self.get_media_resource('DefaultFolder.png'), HbogoConstants.ACTION_LIST)
if container_index not in excludeindex:
self.addCat(py2_encode(container_item['Name']), container_item['ObjectUrl'],
self.get_media_resource('DefaultFolder.png'), HbogoConstants.ACTION_LIST)
else:
for title in jsonrsp['Container'][0]['Contents']['Items']:
# 1=MOVIE/EXTRAS, 2=SERIES(serial), 3=SERIES(episode)
Expand Down Expand Up @@ -1507,11 +1545,12 @@ def addDir(self, item, mode, media_type):
liz.addContextMenuItems(items=self.genContextMenu(cid, media_id, HbogoConstants.CONTEXT_MODE_DEFAULT))
xbmcplugin.addDirectoryItem(handle=self.handle, url=directory_url, listitem=liz, isFolder=True)

def addCat(self, name, url, icon, mode):
def addCat(self, name, url, icon, mode, exclude=''): # exclude optional index of item to skip in list add
category_url = '%s?%s' % (self.base_url, urlencode({
'url': url,
'mode': mode,
'name': name,
'exclude': exclude
}))
liz = xbmcgui.ListItem(name)
liz.setArt({'fanart': self.get_resource("fanart.jpg"), 'thumb': icon, 'icon': icon})
Expand Down
2 changes: 1 addition & 1 deletion hbogolib/handlersp.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def list_pages(self, url, max_items=200, offset=0):
self.log('List pages calling next page... max: ' + str(max_items) + ' offset: ' + str(offset + max_items))
self.list_pages(url, max_items, offset + max_items)

def list(self, url, simple=False):
def list(self, url, simple=False, exclude_list=None):
if not self.chk_login():
self.login()
self.log("List: " + str(url))
Expand Down
2 changes: 1 addition & 1 deletion resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<setting label="30732" type="bool" id="show_continue" default="true"/>
<setting label="30729" type="bool" id="show_kids" default="true"/>
<setting label="30737" type="bool" id="enforce_kids" default="false"/>
<setting label="30697" type="bool" id="group_home" default="false"/>
<setting label="30697" type="bool" id="group_home" default="true"/>
</category>
<!-- Streaming -->
<category label="30660">
Expand Down

0 comments on commit 2193bcd

Please sign in to comment.