Skip to content

Commit

Permalink
Video library cleaning support
Browse files Browse the repository at this point in the history
  • Loading branch information
AkariDN committed Jul 25, 2018
1 parent cdb3d5a commit 10e4f9f
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 23 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ NOTE: If you are using plugin url for video source with options string or in fol
Parameters:
* mode: "movies" or "tvshows" - display movies or tvshows from database
* id, sid, eid - movie, tv show or episode id (the same as tag "id" from database)
* noinfo=1 - do not set any information except title and season and episode numbers
* noinfo=1 - do not set any information except title and season/episode numbers
* kodi_action=refresh_info - reload item at specified path and return it as directory contents
* kodi_action=check_exists - check if any item exists at specified path

To strip folder mode and mixed mode different paths are used:
* /mode/ - mixed mode
Expand Down Expand Up @@ -60,7 +61,7 @@ plugin://plugin.video.testlib/tvshows/?sid=123
Refresh episode:
```
plugin://plugin.video.testlib/?mode=tvshows&sid=123&eid=456&kodi_action=refresh_info
plugin://plugin.video.testlib/lib/tvshows/123/456?kodi_action=refresh_info
plugin://plugin.video.testlib/lib/tvshows/123/456/?kodi_action=refresh_info
plugin://plugin.video.testlib/tvshows/?sid=123&eid=456&kodi_action=refresh_info
```
Play movie:
Expand Down
11 changes: 9 additions & 2 deletions addon.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.testlib" name="Demo video library" version="0.1.0" provider-name="AkariDN">
<addon id="plugin.video.testlib" name="Demo video library" version="0.2.0" provider-name="AkariDN">
<requires>
<import addon="xbmc.python" version="2.25.0"/>
</requires>
<extension point="xbmc.python.pluginsource" library="default.py">
<provides>video</provides>
<medialibraryscanpath content="movies">movies/</medialibraryscanpath>
<medialibraryscanpath content="movies">lib/movies/</medialibraryscanpath>
<medialibraryscanpath content="movies">lib_noinfo/movies/</medialibraryscanpath>
<medialibraryscanpath content="tvshows">tvshows/</medialibraryscanpath>
<medialibraryscanpath content="tvshows">lib/tvshows/</medialibraryscanpath>
<medialibraryscanpath content="tvshows">lib_noinfo/tvshows/</medialibraryscanpath>
</extension>
<extension point="xbmc.addon.metadata">
<platform>all</platform>
<language>en</language>
<reuselanguageinvoker>true</reuselanguageinvoker>
<summary lang="en">Kodi video plugin for testing media library</summary>
<description lang="en">This plugin provides demo video content (movies and tv shows). Use it for test Kodi media library scanning and updating.</description>
<disclaimer></disclaimer>
<news>v0.1.0 - Initial release</news>
<news>v0.2.0 - Video library cleaning support</news>
<license>GNU Affero General Public License, v3</license>
<forum></forum>
<website>https://kodi.tv/</website>
Expand Down
4 changes: 3 additions & 1 deletion default.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ def parse_args():
set_arg(ret, 'noinfo', True)
elif k == 'kodi_action' and v == 'refresh_info':
ret['refresh'] = True
elif k == 'kodi_action' and v == 'check_exists':
ret['check'] = True
if 'id2' in ret and not 'id1' in ret:
raise ValueError('Invalid URL')
return ret if 'mode' in ret else {}
Expand Down Expand Up @@ -125,7 +127,7 @@ def plugin_main():

if args:
from library import main
main(args.get('urltype', 0), args['mode'], args.get('id1'), args.get('id2'), args.get('refresh', False), args.get('noinfo', False))
main(args.get('urltype', 0), args['mode'], args.get('id1'), args.get('id2'), args.get('refresh', False), args.get('check', False), args.get('noinfo', False), int(sys.argv[1]))
else:
show_menu()

Expand Down
63 changes: 45 additions & 18 deletions library.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import os
import sys
import hashlib
import xml.etree.ElementTree as ET
try:
Expand Down Expand Up @@ -212,7 +211,7 @@ def mkitem(data, mediatype, url, noinfo):
for i in data.get('ratings', []):
li.setRating(i[0], i[1], i[2], i[3])
for i in data.get('thumbs', []):
li.addAvailableThumb(i[0], i[1], season=i[2])
li.addAvailableArtwork(i[0], i[1], season=i[2])
if 'fanart' in data:
li.setAvailableFanart(data['fanart'])
if 'uniqueids' in data:
Expand All @@ -224,8 +223,7 @@ def mkitem(data, mediatype, url, noinfo):
li.setArt(data['art'])
return li

def list_videos(data, mediatype, url, noinfo, hash_url=None):
handle = int(sys.argv[1])
def list_videos(handle, data, mediatype, url, noinfo, hash_url=None):
xbmcplugin.setContent(handle, mediatype+'s')
isfolder = mediatype == 'tvshow'
for d in data:
Expand All @@ -235,25 +233,32 @@ def list_videos(data, mediatype, url, noinfo, hash_url=None):
path = url.format(vid)
li = mkitem(d, mediatype, path, noinfo)
if hash_url and 'episodes' in d:
found = False
m = hashlib.md5()
for e in d['episodes']:
if 'id' in e:
m.update(hash_url.format(vid, quote_plus(e['id'])).encode('utf-8'))
li.setProperty('hash', m.hexdigest().upper())
found = True
li.setProperty('hash', m.hexdigest().upper() if found else '')
xbmcplugin.addDirectoryItem(handle, path, li, isfolder)
xbmcplugin.endOfDirectory(handle)

def play_video(data, mediatype, url, noinfo):
def play_video(handle, data, mediatype, url, noinfo):
if not data:
return
handle = int(sys.argv[1])
xbmcplugin.setContent(handle, mediatype+'s')
li = mkitem(data, mediatype, url, noinfo)
li.setPath(get_path('profile', 'test.mp4'))
li.setProperty('original_listitem_url', url)
li.setProperty('get_stream_details_from_player', 'true')
xbmcplugin.setResolvedUrl(handle, True, li)

def reply(handle, ret):
xbmcplugin.setResolvedUrl(handle, ret, xbmcgui.ListItem())

def check_exists(handle, data):
reply(handle, data != None)

def quote(arg):
return arg if arg[:1] == '{' and arg[-1:] == '}' and arg[1:-1].isdigit() else quote_plus(arg)

Expand Down Expand Up @@ -297,45 +302,67 @@ def get_subdatalist(data, i):
return [ret] if ret != None else []


def main(urltype, mode, id1, id2, refresh, noinfo):
def main(urltype, mode, id1, id2, refresh, check, noinfo, handle):
data = load_database(mode)
if not data:
reply(handle, False)
return
if mode == 'movies':
if id1:
url = mkurl(urltype, mode, id1, None, noinfo)
if refresh:
log('Refresh movie {0}'.format(id1))
list_videos(get_subdatalist(data, id1), 'movie', url, noinfo)
list_videos(handle, get_subdatalist(data, id1), 'movie', url, noinfo)
elif check:
log('Check movie {0}'.format(id1))
check_exists(handle, get_subdata(data, id1))
else:
log('Play movie {0}'.format(id1))
play_video(get_subdata(data, id1), 'movie', url, noinfo)
play_video(handle, get_subdata(data, id1), 'movie', url, noinfo)
else:
log('List movies')
list_videos(data, 'movie', mkurl(urltype, mode, '{0}', None, noinfo), noinfo)
if check:
log('Check movies')
reply(handle, True)
else:
log('List movies')
list_videos(handle, data, 'movie', mkurl(urltype, mode, '{0}', None, noinfo), noinfo)
elif mode == 'tvshows':
if id1:
if id2:
data = get_subdata(data, id1)
if not data or not 'episodes' in data:
reply(handle, False)
return
data = data['episodes']
url = mkurl(urltype, mode, id1, id2, noinfo)
if refresh:
log('Refresh tvshow {0} episode {1}'.format(id1, id2))
list_videos(get_subdatalist(data, id2), 'episode', url, noinfo)
list_videos(handle, get_subdatalist(data, id2), 'episode', url, noinfo)
elif check:
log('Check tvshow {0} episode {1}'.format(id1, id2))
check_exists(handle, get_subdata(data, id2))
else:
log('Play tvshow {0} episode {1}'.format(id1, id2))
play_video(get_subdata(data, id2), 'episode', url, noinfo)
play_video(handle, get_subdata(data, id2), 'episode', url, noinfo)
else:
if refresh:
log('Refresh tvshow {0}'.format(id1))
list_videos(get_subdatalist(data, id1), 'tvshow', mkurl(urltype, mode, id1, None, noinfo), noinfo)
list_videos(handle, get_subdatalist(data, id1), 'tvshow', mkurl(urltype, mode, id1, None, noinfo), noinfo)
elif check:
log('Check tvshow {0}'.format(id1))
check_exists(handle, get_subdata(data, id1))
else:
data = get_subdata(data, id1)
if data and 'episodes' in data:
log('List tvshow {0} episodes'.format(id1))
list_videos(data['episodes'], 'episode', mkurl(urltype, mode, id1, '{0}', noinfo), noinfo)
list_videos(handle, data['episodes'], 'episode', mkurl(urltype, mode, id1, '{0}', noinfo), noinfo)
else:
reply(handle, False)
else:
log('List tvshows')
list_videos(data, 'tvshow', mkurl(urltype, mode, '{0}', None, noinfo), noinfo, mkurl(urltype, mode, '{0}', '{1}', noinfo))
if check:
log('Check tvshows')
reply(handle, True)
else:
log('List tvshows')
list_videos(handle, data, 'tvshow', mkurl(urltype, mode, '{0}', None, noinfo), noinfo, mkurl(urltype, mode, '{0}', '{1}', noinfo))

0 comments on commit 10e4f9f

Please sign in to comment.