Skip to content

Commit

Permalink
Add a menu item for updating a remote medialibrary
Browse files Browse the repository at this point in the history
  • Loading branch information
romanvm committed Apr 5, 2024
1 parent 8098308 commit 518ddfd
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 12 deletions.
28 changes: 21 additions & 7 deletions plugin.video.external.library/libs/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from urllib.parse import parse_qsl

import xbmcplugin
from xbmcgui import Dialog, ListItem
from xbmcgui import Dialog, ListItem, NOTIFICATION_ERROR

from libs.content_type_handlers import (
MoviesHandler,
Expand All @@ -31,7 +31,8 @@
RecentMusicVideosHandler,
)
from libs.exceptions import NoDataError, RemoteKodiError
from libs.kodi_service import ADDON, ADDON_ID, GettextEmulator, get_plugin_url
from libs.json_rpc_api import VideoLibraryScan
from libs.kodi_service import ADDON, ADDON_ID, ADDON_NAME, GettextEmulator, get_plugin_url
from libs.media_info_service import set_info, set_art
from libs.mem_storage import MemStorage

Expand Down Expand Up @@ -94,6 +95,10 @@ def root():
'thumb': 'DefaultRecentlyAddedMusicVideos.png'})
url = get_plugin_url(content_type='recent_music_videos')
xbmcplugin.addDirectoryItem(HANDLE, url, list_item, isFolder=True)
list_item = ListItem(_('Update remote videolibrary'))
list_item.setArt({'icon': 'DefaultAddonsUpdates.png', 'thumb': 'DefaultAddonsUpdates.png'})
url = get_plugin_url(action='update_library')
xbmcplugin.addDirectoryItem(HANDLE, url, list_item, isFolder=False)


def show_media_items(content_type, tvshowid=None, season=None, parent_category=None):
Expand All @@ -109,11 +114,12 @@ def show_media_items(content_type, tvshowid=None, season=None, parent_category=N
logger.exception('Unable to retrieve %s from the remote Kodi library',
content_type)
DIALOG.notification(ADDON_ID, _('Unable to retrieve data from the remote Kodi library!'),
icon='error')
icon=NOTIFICATION_ERROR)
return
except RemoteKodiError as exc:
logger.exception('Unable to connect to %s', str(exc))
DIALOG.notification(ADDON_ID, _('Unable to connect to the remote Kodi host!'), icon='error')
DIALOG.notification(ADDON_ID, _('Unable to connect to the remote Kodi host!'),
icon=NOTIFICATION_ERROR)
return
logger.debug('Creating a list of %s items...', content_type)
directory_items = []
Expand Down Expand Up @@ -145,16 +151,24 @@ def show_media_items(content_type, tvshowid=None, season=None, parent_category=N
logger.debug('Finished creating a list of %s items.', content_type)


def update_remote_library():
VideoLibraryScan().send_json_rpc()
DIALOG.ok(ADDON_NAME, _('Updating the remote videolibrary started.'))


def router(paramstring):
params = dict(parse_qsl(paramstring))
logger.debug('Called addon with params: %s', str(sys.argv))
if 'content_type' not in params:
root()
else:
if 'content_type' in params:
if (tvshowid := params.get('tvshowid')) is not None:
tvshowid = int(tvshowid)
if (season := params.get('season')) is not None:
season = int(season)
parent_category = params.get('parent_category')
show_media_items(params['content_type'], tvshowid, season, parent_category)
elif params.get('action') == 'update_library':
update_remote_library()
return
else:
root()
xbmcplugin.endOfDirectory(HANDLE)
14 changes: 10 additions & 4 deletions plugin.video.external.library/libs/json_rpc_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import logging
from pprint import pformat
from typing import List, Dict, Any
from typing import List, Dict, Any, Optional

from libs import simple_requests as requests
from libs.exceptions import NoDataError, RemoteKodiError
Expand All @@ -36,9 +36,11 @@ def send_json_rpc(self):
request = {
'jsonrpc': '2.0',
'method': self.method,
'params': self.get_params(),
'id': '1',
}
params = self.get_params()
if params is not None:
request['params'] = params
logger.debug('JSON-RPC request: %s', pformat(request))
auth = None
login = ADDON.getSetting('kodi_login')
Expand All @@ -53,9 +55,9 @@ def send_json_rpc(self):
logger.debug('JSON-RPC reply: %s', pformat(json_reply))
return json_reply

def get_params(self) -> Dict[str, Any]:
def get_params(self) -> Optional[Dict[str, Any]]:
"""Get params to send to Kodi JSON-RPC API"""
raise NotImplementedError
return None


class BaseMediaItemsRetriever(BaseJsonRpcApi):
Expand Down Expand Up @@ -261,6 +263,10 @@ class SetEpisodeDetails(SetMovieDetails):
method = 'VideoLibrary.SetEpisodeDetails'


class VideoLibraryScan(BaseJsonRpcApi):
method = 'VideoLibrary.Scan'


SET_DETAILS_API_MAP = {
'movieid': SetMovieDetails,
'episodeid': SetEpisodeDetails,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,11 @@ msgstr ""
msgctxt "#32029"
msgid "Use HTTPS"
msgstr ""

msgctxt "#32030"
msgid "Update remote videolibrary"
msgstr ""

msgctxt "#32031"
msgid "Updating the remote videolibrary started."
msgstr ""
2 changes: 1 addition & 1 deletion plugin.video.external.library/resources/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</setting>
<setting id="use_https" type="boolean" label="32029" help="">
<level>0</level>
<default>true</default>
<default>false</default>
<control type="toggle"/>
</setting>
<setting id="kodi_login" type="string" label="32013" help="">
Expand Down

0 comments on commit 518ddfd

Please sign in to comment.