Skip to content

Commit

Permalink
Fix my favorites menu (#1191)
Browse files Browse the repository at this point in the history
  • Loading branch information
mediaminister authored Oct 4, 2024
1 parent 804e86d commit 246920e
Show file tree
Hide file tree
Showing 10 changed files with 198 additions and 100 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/status.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
#- name: TEST Favorites
# run: python -m unittest -v test_favorites.TestFavorites.test_programs
- name: TEST ResumePoints
run: python -m unittest -v test_resumepoints.TestResumePoints.test_get_continue_episodes
run: python -m unittest -v test_api.TestApi.test_get_continue_episodes
if: always()
- name: TEST Search
run: python -m unittest -v test_search.TestSearch.test_search_journaal
Expand Down
10 changes: 7 additions & 3 deletions resources/language/resource.language.en_gb/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,15 @@ msgid "Documentaries"
msgstr ""

msgctxt "#30045"
msgid "All [I]one-off[/I] documentaries on VRT MAX"
msgid "All documentaries on VRT MAX"
msgstr ""

msgctxt "#30046"
msgid "Music"
msgstr ""

msgctxt "#30047"
msgid "All [I]one-off[/I] music on VRT MAX"
msgid "All music on VRT MAX"
msgstr ""

msgctxt "#30048"
Expand Down Expand Up @@ -512,7 +512,11 @@ msgid "from livestream cache"
msgstr ""

msgctxt "#30455"
msgid "Delete from this list"
msgid "Delete from this list (VRT MAX)"
msgstr ""

msgctxt "#30456"
msgid "Mark as watched (VRT MAX)"
msgstr ""


Expand Down
16 changes: 10 additions & 6 deletions resources/language/resource.language.nl_nl/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,16 @@ msgid "Documentaries"
msgstr "Documentaires"

msgctxt "#30045"
msgid "All [I]one-off[/I] documentaries on VRT MAX"
msgstr "Alle [I]one-off[/I] documentaires op VRT MAX"
msgid "All documentaries on VRT MAX"
msgstr "Alle documentaires op VRT MAX"

msgctxt "#30046"
msgid "Music"
msgstr "Muziek"

msgctxt "#30047"
msgid "All [I]one-off[/I] music on VRT MAX"
msgstr "Alle [I]one-off[/I] muziek op VRT MAX"
msgid "All music on VRT MAX"
msgstr "Alle muziek op VRT MAX"

msgctxt "#30048"
msgid "Most recent"
Expand Down Expand Up @@ -512,8 +512,12 @@ msgid "from livestream cache"
msgstr "uit de livestream-cache"

msgctxt "#30455"
msgid "Delete from this list"
msgstr "Verwijder uit deze lijst"
msgid "Delete from this list (VRT MAX)"
msgstr "Verwijder uit deze lijst (VRT MAX)"

msgctxt "#30456"
msgid "Mark as watched (VRT MAX)"
msgstr "Markeren als afgespeeld (VRT MAX)"


### SETTINGS
Expand Down
29 changes: 7 additions & 22 deletions resources/lib/addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,6 @@ def favorites_programs(end_cursor=''):
VRTPlayer().show_tvshow_menu(end_cursor=end_cursor, use_favorites=True)


@plugin.route('/favorites/docu')
def favorites_docu():
"""The favorites docu listing"""
from vrtplayer import VRTPlayer
VRTPlayer().show_favorites_docu_menu()


@plugin.route('/favorites/music')
def favorites_music():
"""The favorites music listing"""
from vrtplayer import VRTPlayer
VRTPlayer().show_favorites_music_menu()


@plugin.route('/favorites/recent')
@plugin.route('/favorites/recent')
@plugin.route('/favorites/recent/<end_cursor>')
Expand Down Expand Up @@ -132,16 +118,15 @@ def resumepoints_continue(end_cursor=''):
@plugin.route('/resumepoints/continue/delete/<episode_id>')
def resumepoints_continue_delete(episode_id):
"""The API interface to delete episodes from continue watching listing"""
from resumepoints import ResumePoints
ResumePoints().delete_continue(episode_id)
from api import delete_continue
delete_continue(episode_id)


@plugin.route('/resumepoints/refresh')
def resumepoints_refresh():
"""The API interface to refresh the resumepoints cache"""
from resumepoints import ResumePoints
ResumePoints().refresh(ttl=0)
notification(message=localize(30983))
@plugin.route('/resumepoints/continue/finish/<episode_id>')
def resumepoints_continue_finish(episode_id):
"""The API interface to finish episodes from continue watching listing"""
from api import finish_continue
finish_continue(episode_id)


@plugin.route('/programs/<program_name>')
Expand Down
77 changes: 76 additions & 1 deletion resources/lib/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ def get_context_menu(program_name, program_id, program_title, program_type, is_f
localize(30455), # Delete from this list
'RunPlugin(%s)' % url_for('resumepoints_continue_delete', episode_id=episode_id)
))
context_menu.append((
localize(30456), # Mark as watched (VRT MAX)
'RunPlugin(%s)' % url_for('resumepoints_continue_finish', episode_id=episode_id)
))
return context_menu


Expand Down Expand Up @@ -561,6 +565,7 @@ def get_seasons_data(program_name):

def set_resumepoint(video_id, title, position, total):
"""Set resumepoint"""
data_json = {}
# Respect resumepoint margins
if position and total:
if position < RESUMEPOINTS_MARGIN:
Expand All @@ -585,6 +590,76 @@ def set_resumepoint(video_id, title, position, total):
data = dumps(payload).encode('utf-8')
data_json = get_url_json(url='{}/{}'.format(RESUMEPOINTS_URL, video_id), cache=None, headers=headers, data=data, raise_errors='all')
log(3, '[Resumepoints] Updated resumepoint {data}', data=data_json)
return data_json


def delete_continue(episode_id):
"""Delete continue episode using GraphQL API"""
import base64
from json import dumps
graphql_query = """
mutation listDelete($input: ListDeleteActionInput!) {
setListDeleteActionItem(input: $input) {
title
active
action {
__typename
... on NoAction {
__typename
reason
}
... on ListTileDeletedAction {
__typename
listId
listName
id
}
}
__typename
}
}
"""
list_name = {
'listId': 'dynamic:/vrtnu.model.json@resume-list-video',
'listType': 'verderkijken',
}
encoded_list_name = base64.b64encode(dumps(list_name).encode('utf-8'))
operation_name = 'listDelete'
variables = {
'input': {
'id': episode_id,
'listName': encoded_list_name.decode('utf-8'),
},
}
return api_req(graphql_query, operation_name, variables)


def finish_continue(episode_id):
"""Finish continue episode using GraphQL API"""
graphql_query = """
mutation finishItem($input: FinishActionInput!) {
setFinishActionItem(input: $input) {
__typename
objectId
title
accessibilityLabel
action {
... on FinishAction {
id
__typename
}
__typename
}
}
}
"""
operation_name = 'finishItem'
variables = {
'input': {
'id': episode_id,
},
}
return api_req(graphql_query, operation_name, variables)


def get_paginated_episodes(list_id, page_size, end_cursor=''):
Expand Down Expand Up @@ -1256,7 +1331,7 @@ def api_req(graphql_query, operation_name, variables, client='WEB'):
'Authorization': 'Bearer ' + access_token,
'Content-Type': 'application/json',
'x-vrt-client-name': client,
'x-vrt-client-version': '1.5.0',
'x-vrt-client-version': '1.5.7',
}
data_json = get_url_json(url=GRAPHQL_URL, cache=None, headers=headers, data=data, raise_errors='all')
return data_json
Expand Down
48 changes: 48 additions & 0 deletions resources/lib/resumepoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ def delete_continue(self, episode_id):
self._delete_continue_graphql(episode_id)
container_refresh()

def finish_continue(self, episode_id):
"""Finish a continue item from continue menu"""
self._finish_continue_graphql(episode_id)
container_refresh()

def _delete_continue_graphql(self, episode_id):
"""Delete continue episode using GraphQL API"""
from tokenresolver import TokenResolver
Expand Down Expand Up @@ -229,6 +234,49 @@ def _delete_continue_graphql(self, episode_id):
result_json = get_url_json(url=self.GRAPHQL_URL, cache=None, headers=headers, data=data, raise_errors='all')
return result_json

def _finish_continue_graphql(self, episode_id):
"""Finish continue episode using GraphQL API"""
from tokenresolver import TokenResolver
from json import dumps
access_token = TokenResolver().get_token('vrtnu-site_profile_at')
result_json = {}
if access_token:
headers = {
'Authorization': 'Bearer ' + access_token,
'Content-Type': 'application/json',
'x-vrt-client-name': 'WEB',
'x-vrt-client-version': '1.5.0',
}
graphql_query = """
mutation finishItem($input: FinishActionInput!) {
setFinishActionItem(input: $input) {
__typename
objectId
title
accessibilityLabel
action {
... on FinishAction {
id
__typename
}
__typename
}
}
}
"""
payload = {
'operationName': 'finishItem',
'variables': {
'input': {
'id': episode_id,
},
},
'query': graphql_query,
}
data = dumps(payload).encode('utf-8')
result_json = get_url_json(url=self.GRAPHQL_URL, cache=None, headers=headers, data=data, raise_errors='all')
return result_json

def get_continue(self):
"""Get continue using GraphQL API"""
from tokenresolver import TokenResolver
Expand Down
8 changes: 2 additions & 6 deletions resources/lib/vrtplayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,15 @@ def show_favorites_menu(self):
if get_setting_bool('addmydocu', default=True):
favorites_items.append(
TitleItem(label=localize(30044), # My documentaries
path=url_for('favorites_docu'),
path=url_for('categories', category='docu'),
art_dict={'thumb': 'DefaultMovies.png'},
info_dict={'plot': localize(30045)})
)

if get_setting_bool('addmymusic', default=True):
favorites_items.append(
TitleItem(label=localize(30046), # My music
path=url_for('favorites_music'),
path=url_for('categories', category='muziek'),
art_dict={'thumb': 'DefaultAddonMusic.png'},
info_dict={'plot': localize(30047)})
)
Expand Down Expand Up @@ -270,10 +270,6 @@ def show_offline_menu(self, end_cursor='', use_favorites=False):

def show_continue_menu(self, end_cursor=''):
"""The VRT MAX add-on 'Continue waching' listing menu"""

# Continue watching menu may need more up-to-date favorites
self._favorites.refresh(ttl=ttl('direct'))
self._resumepoints.refresh(ttl=ttl('direct'))
episodes, sort, ascending, content = get_continue_episodes(end_cursor=end_cursor)
show_listing(episodes, category=30054, sort=sort, ascending=ascending, content=content, cache=False)

Expand Down
49 changes: 47 additions & 2 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

from __future__ import absolute_import, division, print_function, unicode_literals
import unittest
from api import (get_episodes, get_favorite_programs, get_latest_episode, get_next_info, get_online_categories,
get_offline_programs, get_programs, get_recent_episodes, get_search, get_single_episode, valid_categories)
from api import (delete_continue, finish_continue, get_continue_episodes, get_episodes, get_favorite_programs, get_latest_episode,
get_next_info, get_online_categories, get_offline_programs, get_programs, get_recent_episodes,
get_resumepoint_data, get_search, get_single_episode, set_resumepoint, valid_categories)
from data import CATEGORIES
from xbmcextra import kodi_to_ansi

Expand Down Expand Up @@ -123,6 +124,50 @@ def test_upnext(self):
self.assertTrue(next_episode)
print(next_episode)

def test_set_resumepoint(self):
"""Test setting resumepoint for episode wij--roger-raveel"""
video_id = 'vid-b643dbd8-03d1-4ceb-a738-262d6fa7c271'
position = 1337.242753
total = 3334.04
title = 'Wij, Roger Raveel'
response = set_resumepoint(video_id, title, position, total)
self.assertEqual(response.get('at'), int(position))

def test_get_resumepoint(self):
"""Test getting resumepoint for episode wij--roger-raveel"""
video_id = 'vid-b643dbd8-03d1-4ceb-a738-262d6fa7c271'
episode_id = '1615881736655'
media_id, _ = get_resumepoint_data(episode_id)
self.assertEqual(media_id, video_id)

def test_get_continue_episodes(self):
"""Test getting continue watching list"""

# Ensure a continue episode exists (Wij, Roger Raveel)
video_id = 'vid-b643dbd8-03d1-4ceb-a738-262d6fa7c271'
position = 1337.242753
total = 3334.04
title = 'Wij, Roger Raveel'
set_resumepoint(video_id, title, position, total)

episode_items, sort, ascending, content = get_continue_episodes()
self.assertTrue(episode_items)
self.assertEqual(sort, 'dateadded')
self.assertFalse(ascending)
self.assertEqual(content, 'episodes')

def test_finish_continue(self):
"""Test finish continue watching for episode wij--roger-raveel"""
episode_id = '1615881736655'
data = finish_continue(episode_id)
self.assertEqual(data.get('data').get('setFinishActionItem').get('title'), 'Afgespeeld')

def test_delete_continue(self):
"""Test delete continue watching for episode wij--roger-raveel"""
episode_id = '1615881736655'
data = delete_continue(episode_id)
self.assertEqual(data.get('data').get('setListDeleteActionItem').get('title'), 'Verwijderd')

def test_get_categories(self):
"""Test to ensure our local hardcoded categories conforms to online categories"""
# Remove thumbnails from scraped categories first
Expand Down
Loading

0 comments on commit 246920e

Please sign in to comment.