Implemented 'search video on selected instance' functionality
This commit is contained in:
parent
0f11b12350
commit
ac976ab8cf
|
@ -1,5 +1,5 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
<addon id="plugin.video.peertube" name="PeerTube" version="0.1.1" provider-name="Cyrille Bollu">
|
<addon id="plugin.video.peertube" name="PeerTube" version="0.2.0" provider-name="Cyrille Bollu">
|
||||||
<requires>
|
<requires>
|
||||||
<import addon="xbmc.python" version="2.25.0"/>
|
<import addon="xbmc.python" version="2.25.0"/>
|
||||||
<import addon="script.module.addon.signals" version="0.0.3"/>
|
<import addon="script.module.addon.signals" version="0.0.3"/>
|
||||||
|
@ -20,6 +20,8 @@
|
||||||
<email>cyrille.bollu2@gmail.com</email>
|
<email>cyrille.bollu2@gmail.com</email>
|
||||||
<source>https://github.com/StCyr/plugin.video.peertube</source>
|
<source>https://github.com/StCyr/plugin.video.peertube</source>
|
||||||
<news>
|
<news>
|
||||||
|
0.2.0
|
||||||
|
Implemented navigation in 'browse selected instance' menu
|
||||||
0.1.1
|
0.1.1
|
||||||
4th PoC.
|
4th PoC.
|
||||||
First functional PoC with background download
|
First functional PoC with background download
|
||||||
|
|
79
peertube.py
79
peertube.py
|
@ -9,6 +9,7 @@
|
||||||
# - When downloaded torrents are kept, do we want to seed them all the time,
|
# - When downloaded torrents are kept, do we want to seed them all the time,
|
||||||
# or only when the addon is running, or only when kodi is playing one,...?
|
# or only when the addon is running, or only when kodi is playing one,...?
|
||||||
# - Do sanity checks on received data
|
# - Do sanity checks on received data
|
||||||
|
# - Handle languages better (with .po files)
|
||||||
|
|
||||||
import time, sys
|
import time, sys
|
||||||
import urllib2, json
|
import urllib2, json
|
||||||
|
@ -51,21 +52,15 @@ class PeertubeAddon():
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def list_videos(self, start):
|
def create_videos_list(self, videos)
|
||||||
"""
|
"""
|
||||||
Create the list of playable videos in the Kodi interface.
|
Create an array of xmbcgui.ListIten's to be displayed as a folder in Kodi's UI
|
||||||
:param start: string
|
:param videos: dict
|
||||||
:return: None
|
:result listing: dict
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# Get the list of videos published by the instance
|
# Create a list for our items
|
||||||
# TODO: Handle failures
|
listing = []
|
||||||
# Make count configurable
|
|
||||||
# Set up pagination
|
|
||||||
xbmc.log('PeertubeAddon: Listing videos from instance ' + self.selected_inst, xbmc.LOGDEBUG)
|
|
||||||
req = self.selected_inst + '/api/v1/videos?count=' + str(self.items_per_page) + '&start=' + start
|
|
||||||
resp = urllib2.urlopen(req)
|
|
||||||
videos = json.load(resp)
|
|
||||||
|
|
||||||
# Return when no videos are found
|
# Return when no videos are found
|
||||||
if videos['total'] == 0:
|
if videos['total'] == 0:
|
||||||
|
@ -74,10 +69,8 @@ class PeertubeAddon():
|
||||||
else:
|
else:
|
||||||
xbmc.log('PeertubeAddon: Found ' + str(videos['total']) + ' videos', xbmc.LOGDEBUG)
|
xbmc.log('PeertubeAddon: Found ' + str(videos['total']) + ' videos', xbmc.LOGDEBUG)
|
||||||
|
|
||||||
# Create a list for our items
|
|
||||||
listing = []
|
|
||||||
|
|
||||||
# Insert a 'Previous' button when start > 0
|
# Insert a 'Previous' button when start > 0
|
||||||
|
# TODO: See if icon can be changed here and for the "Next" button (by an arraow for example)
|
||||||
if int(start) > 0:
|
if int(start) > 0:
|
||||||
start = int(start) - self.items_per_page
|
start = int(start) - self.items_per_page
|
||||||
list_item = xbmcgui.ListItem(label='Previous')
|
list_item = xbmcgui.ListItem(label='Previous')
|
||||||
|
@ -134,6 +127,57 @@ class PeertubeAddon():
|
||||||
url = '{0}?action=browse&start={1}'.format(self.plugin_url, str(start))
|
url = '{0}?action=browse&start={1}'.format(self.plugin_url, str(start))
|
||||||
listing.append((url, list_item, True))
|
listing.append((url, list_item, True))
|
||||||
|
|
||||||
|
return listing
|
||||||
|
|
||||||
|
|
||||||
|
def search_videos(self, start):
|
||||||
|
"""
|
||||||
|
Search for videos on selected instance
|
||||||
|
:param start: string
|
||||||
|
:result: None
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Show a 'Search video' dialog
|
||||||
|
search = xbmcgui.Dialog().input(heading='Search video on ' + self.selected_inst, type=xbmcgui.INPUT_ALPHANUM)
|
||||||
|
# Go back to main menu when user cancels
|
||||||
|
if not search:
|
||||||
|
self.main_menu()
|
||||||
|
|
||||||
|
# Search for videos on selected PeerTube instance
|
||||||
|
# TODO: Handle failures
|
||||||
|
# Make count configurable
|
||||||
|
# Sort videos by rating ( + make the sort method configurabe)
|
||||||
|
xbmc.log('PeertubeAddon: Searching for videos on instance ' + self.selected_inst, xbmc.LOGDEBUG)
|
||||||
|
req = self.selected_inst + '/api/v1/searchs/videos?search=' + search + '&count=' + str(self.items_per_page) + '&start=' + start
|
||||||
|
resp = urllib2.urlopen(req)
|
||||||
|
videos = json.load(resp)
|
||||||
|
|
||||||
|
# Create array of xmbcgui.ListItem's
|
||||||
|
listing = create_videos_list(videos)
|
||||||
|
|
||||||
|
# Add our listing to Kodi.
|
||||||
|
xbmcplugin.addDirectoryItems(self.plugin_id, listing, len(listing))
|
||||||
|
xbmcplugin.endOfDirectory(self.plugin_id)
|
||||||
|
|
||||||
|
def list_videos(self, start):
|
||||||
|
"""
|
||||||
|
Create the list of playable videos in the Kodi interface.
|
||||||
|
:param start: string
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Get the list of videos published by the instance
|
||||||
|
# TODO: Handle failures
|
||||||
|
# Make count configurable
|
||||||
|
# Sort videos by rating ( + make the sort method configurabe)
|
||||||
|
xbmc.log('PeertubeAddon: Listing videos from instance ' + self.selected_inst, xbmc.LOGDEBUG)
|
||||||
|
req = self.selected_inst + '/api/v1/videos?count=' + str(self.items_per_page) + '&start=' + start
|
||||||
|
resp = urllib2.urlopen(req)
|
||||||
|
videos = json.load(resp)
|
||||||
|
|
||||||
|
# Create array of xmbcgui.ListItem's
|
||||||
|
listing = create_videos_list(videos)
|
||||||
|
|
||||||
# Add our listing to Kodi.
|
# Add our listing to Kodi.
|
||||||
xbmcplugin.addDirectoryItems(self.plugin_id, listing, len(listing))
|
xbmcplugin.addDirectoryItems(self.plugin_id, listing, len(listing))
|
||||||
xbmcplugin.endOfDirectory(self.plugin_id)
|
xbmcplugin.endOfDirectory(self.plugin_id)
|
||||||
|
@ -188,7 +232,7 @@ class PeertubeAddon():
|
||||||
|
|
||||||
# 2nd menu entry
|
# 2nd menu entry
|
||||||
list_item = xbmcgui.ListItem(label='Search on selected instance')
|
list_item = xbmcgui.ListItem(label='Search on selected instance')
|
||||||
url = '{0}?action=select_inst'.format(self.plugin_url)
|
url = '{0}?action=search&start=0'.format(self.plugin_url)
|
||||||
listing.append((url, list_item, False))
|
listing.append((url, list_item, False))
|
||||||
|
|
||||||
# 3rd menu entry
|
# 3rd menu entry
|
||||||
|
@ -222,6 +266,9 @@ class PeertubeAddon():
|
||||||
if params['action'] == 'browse':
|
if params['action'] == 'browse':
|
||||||
# List videos on selected instance
|
# List videos on selected instance
|
||||||
self.list_videos(params['start'])
|
self.list_videos(params['start'])
|
||||||
|
elif params['action'] == 'search':
|
||||||
|
# Search for videos on selecgted instance
|
||||||
|
self.search_videos()
|
||||||
elif params['action'] == 'play':
|
elif params['action'] == 'play':
|
||||||
# Play video from provided URL.
|
# Play video from provided URL.
|
||||||
self.play_video(params['url'])
|
self.play_video(params['url'])
|
||||||
|
|
Loading…
Reference in New Issue