Skip to content

Commit

Permalink
add Gensyn area (#92)
Browse files Browse the repository at this point in the history
* add gensyn area and update area selector
* don't show Ultra as kids items
* fix link item for isFolder
* bump version
* make cron job exit to home, and add gensyn test
  • Loading branch information
TermeHansen authored Mar 19, 2024
1 parent 401f746 commit fbf87de
Show file tree
Hide file tree
Showing 15 changed files with 102 additions and 20 deletions.
7 changes: 6 additions & 1 deletion addon.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<addon id="plugin.video.drnu" version="6.3.1" name="DR TV" provider-name="TermeHansen">
<addon id="plugin.video.drnu" version="6.4.0" name="DR TV" provider-name="TermeHansen">
<requires>
<import addon="xbmc.python" version="3.0.0"/>
<import addon="script.module.dateutil" version="2.8.2" />
Expand Down Expand Up @@ -32,6 +32,11 @@
<screenshot>resources/media/Screenshot3.jpg</screenshot>
<screenshot>resources/media/Screenshot4.jpg</screenshot>
</assets>
<news>[B]Version 6.4.0 - 2024-03-19[/B]
- add the new Gensyn area
- change Ultra area to not be kids area
- fix link item issue
</news>
<news>[B]Version 6.3.1 - 2024-03-05[/B]
- fix refresh token bug
- fix watchlist missing resume time bug
Expand Down
5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
[B]Version 6.4.0 - 2024-03-19[/B]
- add the new Gensyn area
- change Ultra area to not be kids area
- fix link item issue

[B]Version 6.3.1 - 2024-03-05[/B]
- fix refresh token bug
- fix watchlist missing resume time bug
Expand Down
Binary file added resources/icons/gensyn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/icons/ultra.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions resources/language/resource.language.da_dk/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ msgctxt "#30105"
msgid "Minisjang"
msgstr "Minisjang"

msgctxt "#30106"
msgid "Gensyn"
msgstr "Gensyn"

# SETTINGS
msgctxt "#30200"
Expand Down
4 changes: 4 additions & 0 deletions resources/language/resource.language.en_gb/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ msgctxt "#30105"
msgid "Minisjang"
msgstr ""

msgctxt "#30106"
msgid "Gensyn"
msgstr ""


# SETTINGS
msgctxt "#30200"
Expand Down
49 changes: 39 additions & 10 deletions resources/lib/addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def __init__(self, plugin_url, plugin_handle):
# Area Selector
self.area_item = xbmcgui.ListItem(tr(30101), offscreen=True)
self.area_item.setArt({'fanart': self.fanart_image, 'icon': str(resources_path/'icons/all.png')})
self.current_area = 'drtv'

setup_cronjob(addon_path, bool_setting, get_setting)
self._version_change_fixes()
Expand Down Expand Up @@ -138,6 +139,12 @@ def showAreaSelector(self):
pass
elif areaSelected == 'drtv':
self.showMainMenu()
elif areaSelected == 'gensyn':
self.current_area = 'gensyn'
self.list_entries('/gensyn')
elif areaSelected == 'ultra':
self.current_area = 'ultra'
self.list_entries('/ultra')
else:
items = self.api.get_children_front_items('dr-' + areaSelected)
self.listEpisodes(items)
Expand Down Expand Up @@ -168,6 +175,12 @@ def showSimpleAreaSelector(self):
'icon': str(resources_path/'media/button-ultra.png')})
item.addContextMenuItems(self.menuItems, False)
items.append((self._plugin_url + '?area=4', item, True))
# Gensyn
item = xbmcgui.ListItem('Gensyn', offscreen=True)
item.setArt({'fanart': str(resources_path/'media/gensyn.png'),
'icon': str(resources_path/'media/gensyn.png')})
item.addContextMenuItems(self.menuItems, False)
items.append((self._plugin_url + '?area=5', item, True))

xbmcplugin.addDirectoryItems(self._plugin_handle, items)
xbmcplugin.endOfDirectory(self._plugin_handle)
Expand Down Expand Up @@ -315,7 +328,7 @@ def search(self):
def kodi_item(self, item, is_season=False):
menuItems = list(self.menuItems)
isFolder = item['type'] not in ['program', 'episode']
if item['type'] == 'link':
if item.get('path','').startswith('/kanal/') and item['type'] == 'link':
isFolder = False
if item['type'] in ['ImageEntry', 'TextEntry'] or item['title'] == '':
return None
Expand All @@ -332,9 +345,14 @@ def kodi_item(self, item, is_season=False):
'fanart': item['images']['wallpaper']
})
else:
listItem.setArt({'fanart': self.fanart_image, 'icon': str(resources_path/'icons/star.png')})

log(title + ' -- ' + item['id'] + ' | ' + item['type'], level=2)
icon_file = str(resources_path/'icons/star.png')
if self.current_area == 'ultra':
icon_file = str(resources_path/'icons/ultra.png')
elif self.current_area == 'gensyn':
icon_file = str(resources_path/'icons/gensyn.png')
listItem.setArt({'fanart': self.fanart_image, 'icon': icon_file})

log(f'{title} -- {item["id"]} | {item["type"]} | {item.get("path")}', level=2)
if item.get('in_mylist', False):
runScript = f"RunPlugin(plugin://plugin.video.drnu/?delfavorite={item['id']})"
menuItems.append((tr(30010), runScript))
Expand Down Expand Up @@ -486,8 +504,8 @@ def playVideo(self, id, kids_channel, path):
player.showSubtitles(True)
else:
player.showSubtitles(False)
def resfresh_ui(self):
xbmc.executebuiltin(f'Container.Update({self._plugin_url})')
def resfresh_ui(self, params=''):
xbmc.executebuiltin(f'Container.Update({self._plugin_url + params})')

def login(self):
err = self.api.request_tokens()
Expand All @@ -502,7 +520,7 @@ def login(self):
self.displayError(err)
else:
xbmcgui.Dialog().ok(tr(30303), tr(30305))
self.resfresh_ui()
self.resfresh_ui('?area=1')

def displayError(self, message='n/a'):
heading = 'API error'
Expand Down Expand Up @@ -541,7 +559,10 @@ def route(self, query):
seasons = PARAMS.get('seasons', 'False') == 'True'
if PARAMS['listVideos'].startswith('ID_'):
items = self.api.get_list(PARAMS['listVideos'], PARAMS['list_param'])
self.listEpisodes(self.api.unfold_list(items, filter_kids=bool_setting('disable.kids')))
filter_kids = bool_setting('disable.kids')
if 'Ultra' in items['title']:
filter_kids = False
self.listEpisodes(self.api.unfold_list(items, filter_kids=filter_kids))
else:
self.list_entries(PARAMS['listVideos'], seasons)

Expand All @@ -552,8 +573,10 @@ def route(self, query):
self.api.add_to_mylist(PARAMS['addfavorite'])
elif 'delfavorite' in PARAMS:
self.api.delete_from_mylist(PARAMS['delfavorite'])
self.resfresh_ui('?show=mylist')
elif 'delwatched' in PARAMS:
self.api.delete_from_watched(PARAMS['delwatched'])
self.resfresh_ui('?show=continue')

elif 'loginnow' in PARAMS:
self.login()
Expand All @@ -565,6 +588,9 @@ def route(self, query):
self.api.recache_items(clear_expired=True, progress=progress)
progress.update(100)
progress.close()
if PARAMS['re-cache'] == 2:
xbmc.executebuiltin('ActivateWindow(Home)')

else:
area = int(get_setting('area'))
if 'area' in PARAMS:
Expand All @@ -580,8 +606,11 @@ def route(self, query):
items = self.api.get_children_front_items('dr-ramasjang')
self.listEpisodes(items)
elif area == 4:
items = self.api.get_children_front_items('dr-ultra')
self.listEpisodes(items)
self.current_area = 'ultra'
self.list_entries('/ultra')
elif area == 5:
self.current_area = 'gensyn'
self.list_entries('/gensyn')

except tvapi.ApiException as ex:
self.displayError(str(ex))
Expand Down
2 changes: 1 addition & 1 deletion resources/lib/cronjob.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"method": "Addons.ExecuteAddon",
"params": {
"addonid": "plugin.video.drnu",
"params": ["?reCache=1"]
"params": ["?reCache=2"]
},
"id": "1"
}
Expand Down
11 changes: 8 additions & 3 deletions resources/lib/tvapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,16 @@ def get_list(self, id, param, use_cache=True):
data = {'page_size': '24'}
if param != 'NoParam':
data['param'] = param
return self._request_get(url, params=data, use_cache=use_cache)
ret = self._request_get(url, params=data, use_cache=use_cache)
if len(ret['items']) == 0:
ret = self.get_recommendations(id, use_cache=use_cache, param=param)
return ret

def get_recommendations(self, id, use_cache=True):
def get_recommendations(self, id, use_cache=True, param=[]):
url = URL + f'/recommendations/{id}'
data = {'page_size': '24'}
if param:
data['param'] = param
headers = {"X-Authorization": f'Bearer {self.profile_token()}'}
return self._request_get(url, params=data, headers=headers, use_cache=use_cache)

Expand Down Expand Up @@ -357,7 +362,7 @@ def kids_item(self, item):
if item['classification']['code'] in ['DR-Ramasjang', 'DR-Minisjang']:
return True
if 'categories' in item:
for cat in ['dr minisjang', 'dr ramasjang', 'dr ultra']:
for cat in ['dr minisjang', 'dr ramasjang']:
if cat in item['categories']:
return True
return False
Expand Down
19 changes: 16 additions & 3 deletions resources/lib/tvgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,35 +60,48 @@ def __init__(self, tr, resources_path):
noFocusTexture=str(resources_path/'media/button-ultra.png')
)

self.gensynButton = xbmcgui.ControlButton(
int(1280/2 - 150), int(y_border + 100), 300, 150, "",
focusTexture=str(resources_path/'media/gensyn-focus.png'),
noFocusTexture=str(resources_path/'media/gensyn.png')
)


self.addControls([
background,
title,
self.drTvButton,
self.ramasjangButton,
self.minisjangButton,
self.ultraButton,
self.gensynButton,
])

self.drTvButton.controlRight(self.ramasjangButton)
self.drTvButton.controlRight(self.gensynButton)
self.drTvButton.controlDown(self.ramasjangButton)
self.drTvButton.controlLeft(self.ultraButton)

self.ramasjangButton.controlLeft(self.drTvButton)
self.ramasjangButton.controlUp(self.drTvButton)
self.ramasjangButton.controlUp(self.gensynButton)
self.ramasjangButton.controlRight(self.minisjangButton)

self.gensynButton.controlRight(self.ultraButton)
self.gensynButton.controlDown(self.ramasjangButton)
self.gensynButton.controlLeft(self.drTvButton)

self.minisjangButton.controlLeft(self.ramasjangButton)
self.minisjangButton.controlUp(self.ultraButton)
self.minisjangButton.controlRight(self.ultraButton)

self.ultraButton.controlLeft(self.minisjangButton)
self.ultraButton.controlLeft(self.gensynButton)
self.ultraButton.controlDown(self.minisjangButton)
self.ultraButton.controlRight(self.drTvButton)

self.setFocus(self.drTvButton)
self.areaSelected = 'drtv'

self.id_to_handle = {
self.gensynButton.getId(): 'gensyn',
self.drTvButton.getId(): 'drtv',
self.ramasjangButton.getId(): 'ramasjang',
self.minisjangButton.getId(): 'minisjang',
Expand Down
Binary file added resources/media/gensyn-focus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/media/gensyn.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<option label="30105">2</option>
<option label="30103">3</option>
<option label="30104">4</option>
<option label="30106">5</option>
</options>
</constraints>
<control type="spinner" format="string"/>
Expand Down
21 changes: 19 additions & 2 deletions tests/test_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
from resources.lib import addon

userdata = Path(addon.translatePath(addon.addon.getAddonInfo('profile')))
if (userdata/'favorites6.pickle').exists():
(userdata/'favorites6.pickle').unlink()

menudata = (userdata/'menudata')
menudata.mkdir(parents=True, exist_ok=True)
Expand Down Expand Up @@ -120,6 +118,25 @@ def test_ramasjang(capsys):
episodes = [iteminfo(item) for item in get_items().values()]
myEqual(len(episodes), 12)


def test_gensyn(capsys):
with capsys.disabled():
handle.route('?area=5')
items = [iteminfo(item) for item in get_items().values()]
# print(items[1])

# Årtier
handle.route(items[5]['url'])
items2 = [iteminfo(item) for item in get_items().values()]
# print(items2[4])

# 1990'erne
handle.route(items2[4]['url'])
episodes = [iteminfo(item) for item in get_items().values()]
# print(episodes[1])
assert episodes[1]['info']['title'] == 'Casper & Mandrilaftalen 1'


def test_a_aa(capsys):
with capsys.disabled():
# A - AA
Expand Down
Binary file modified tests/userdata/requests.cache.sqlite
Binary file not shown.

0 comments on commit fbf87de

Please sign in to comment.