2018-07-26 11:30:15 +02:00
|
|
|
# A Kodi Addon to play video hosted on the peertube service (http://joinpeertube.org/)
|
|
|
|
#
|
|
|
|
# TODO: - Delete downloaded files by default
|
|
|
|
# - Allow people to choose if they want to keep their download after watching?
|
2018-07-26 13:04:47 +02:00
|
|
|
# - Do sanity checks on received data
|
2018-07-30 12:00:27 +02:00
|
|
|
# - Handle languages better (with .po files)
|
2018-07-31 16:50:22 +02:00
|
|
|
# - Get the best quality torrent given settings and/or available bandwidth
|
|
|
|
# See how they do that in the peerTube client's code
|
2018-07-26 11:30:15 +02:00
|
|
|
|
|
|
|
import time, sys
|
|
|
|
import urllib2, json
|
|
|
|
from urlparse import parse_qsl
|
2018-07-27 14:43:21 +02:00
|
|
|
import xbmc, xbmcgui, xbmcaddon, xbmcplugin, xbmcvfs
|
2018-07-26 17:53:27 +02:00
|
|
|
import AddonSignals
|
2018-07-26 11:30:15 +02:00
|
|
|
|
2018-07-26 17:53:27 +02:00
|
|
|
class PeertubeAddon():
|
|
|
|
"""
|
|
|
|
Main class of the addon
|
|
|
|
"""
|
2018-07-26 11:30:15 +02:00
|
|
|
|
2018-07-29 22:14:06 +02:00
|
|
|
def __init__(self, plugin, plugin_id):
|
2018-07-26 17:53:27 +02:00
|
|
|
"""
|
2018-07-27 14:43:21 +02:00
|
|
|
Initialisation of the PeertubeAddon class
|
2018-07-31 15:08:46 +02:00
|
|
|
:param plugin, plugin_id: str, int
|
2018-07-28 13:35:28 +02:00
|
|
|
:return: None
|
2018-07-26 17:53:27 +02:00
|
|
|
"""
|
|
|
|
|
2018-07-27 11:26:40 +02:00
|
|
|
xbmc.log('PeertubeAddon: Initialising', xbmc.LOGDEBUG)
|
2018-07-28 13:44:57 +02:00
|
|
|
|
2018-07-29 22:14:06 +02:00
|
|
|
# Save addon URL and ID
|
|
|
|
self.plugin_url = plugin
|
|
|
|
self.plugin_id = plugin_id
|
|
|
|
|
|
|
|
# Get an Addon instance
|
|
|
|
addon = xbmcaddon.Addon()
|
2018-07-28 13:44:57 +02:00
|
|
|
|
|
|
|
# Select preferred instance by default
|
|
|
|
self.selected_inst = addon.getSetting('preferred_instance')
|
|
|
|
|
|
|
|
# Get the number of videos to show per page
|
2018-07-31 12:23:16 +02:00
|
|
|
self.items_per_page = int(addon.getSetting('items_per_page'))
|
2018-07-28 13:35:28 +02:00
|
|
|
|
2018-07-31 15:26:27 +02:00
|
|
|
# Get the video sort method
|
|
|
|
self.sort_method = addon.getSetting('video_sort_method')
|
|
|
|
|
2018-08-02 16:53:09 +02:00
|
|
|
# Get the preferred resolution for video
|
|
|
|
self.preferred_resolution = addon.getSetting('preferred_resolution')
|
|
|
|
|
2018-07-26 17:53:27 +02:00
|
|
|
# Nothing to play at initialisation
|
|
|
|
self.play = 0
|
2018-07-26 19:59:47 +02:00
|
|
|
self.torrent_name = ''
|
2018-07-26 17:53:27 +02:00
|
|
|
|
|
|
|
return None
|
|
|
|
|
2018-07-31 16:50:22 +02:00
|
|
|
def query_peertube(self, req):
|
2018-07-26 17:53:27 +02:00
|
|
|
"""
|
2018-07-31 16:50:22 +02:00
|
|
|
Issue a PeerTube API request and return the results
|
|
|
|
:param req: str
|
|
|
|
:result data: dict
|
2018-07-26 17:53:27 +02:00
|
|
|
"""
|
|
|
|
|
2018-07-31 16:50:22 +02:00
|
|
|
# Send the PeerTube REST API request
|
|
|
|
try:
|
|
|
|
xbmc.log('PeertubeAddon: Issuing request {0}'.format(req), xbmc.LOGDEBUG)
|
|
|
|
resp = urllib2.urlopen(req)
|
|
|
|
data = json.load(resp)
|
|
|
|
except:
|
|
|
|
xbmcgui.Dialog().notification('Communication error', 'Error during my request on {0}'.format(self.selected_inst), xbmcgui.NOTIFICATION_ERROR)
|
|
|
|
return None
|
2018-07-26 17:53:27 +02:00
|
|
|
|
2018-07-30 21:17:08 +02:00
|
|
|
# Return when no results are found
|
|
|
|
if data['total'] == 0:
|
|
|
|
xbmc.log('PeertubeAddon: No result found', xbmc.LOGDEBUG)
|
2018-07-31 16:50:22 +02:00
|
|
|
return None
|
2018-07-29 22:14:06 +02:00
|
|
|
else:
|
2018-07-31 16:50:22 +02:00
|
|
|
xbmc.log('PeertubeAddon: Found {0} results'.format(data['total']), xbmc.LOGDEBUG)
|
|
|
|
|
|
|
|
return data
|
|
|
|
|
2018-07-31 21:46:16 +02:00
|
|
|
def create_list(self, lst, data_type, start):
|
2018-07-31 16:50:22 +02:00
|
|
|
"""
|
2018-07-31 21:46:16 +02:00
|
|
|
Create an array of xmbcgui.ListItem's from the lst parameter
|
|
|
|
:param lst, data_type, start: dict, str, str
|
2018-07-31 16:50:22 +02:00
|
|
|
:result listing: array
|
|
|
|
"""
|
2018-07-26 17:53:27 +02:00
|
|
|
# Create a list for our items.
|
2018-07-31 16:50:22 +02:00
|
|
|
listing = []
|
2018-07-31 21:46:16 +02:00
|
|
|
for data in lst['data']:
|
2018-07-26 17:53:27 +02:00
|
|
|
|
|
|
|
# Create a list item with a text label
|
2018-07-31 21:46:16 +02:00
|
|
|
list_item = xbmcgui.ListItem(label=data['name'])
|
2018-07-26 13:17:47 +02:00
|
|
|
|
2018-07-31 16:50:22 +02:00
|
|
|
if data_type == 'videos':
|
|
|
|
# Add thumbnail
|
2018-07-31 21:46:16 +02:00
|
|
|
list_item.setArt({'thumb': self.selected_inst + '/' + data['thumbnailPath']})
|
2018-07-31 16:50:22 +02:00
|
|
|
|
|
|
|
# Set a fanart image for the list item.
|
2018-07-31 21:46:16 +02:00
|
|
|
#list_item.setProperty('fanart_image', data['thumb'])
|
2018-07-31 16:50:22 +02:00
|
|
|
|
|
|
|
# Compute media info from item's metadata
|
2018-07-31 21:46:16 +02:00
|
|
|
info = {'title':data['name'],
|
|
|
|
'playcount': data['views'],
|
|
|
|
'plotoutline': data['description'],
|
|
|
|
'duration': data['duration']
|
2018-07-31 16:50:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# For videos, add a rating based on likes and dislikes
|
2018-07-31 21:46:16 +02:00
|
|
|
if data['likes'] > 0 or data['dislikes'] > 0:
|
|
|
|
info['rating'] = data['likes']/(data['likes'] + data['dislikes'])
|
2018-07-31 16:50:22 +02:00
|
|
|
|
|
|
|
# Set additional info for the list item.
|
|
|
|
list_item.setInfo('video', info)
|
|
|
|
|
|
|
|
# Videos are playable
|
|
|
|
list_item.setProperty('IsPlayable', 'true')
|
|
|
|
|
2018-08-02 17:29:36 +02:00
|
|
|
# Find the URL of the best possible video matching user's preferrence
|
2018-07-31 16:50:22 +02:00
|
|
|
# TODO: Error handling
|
2018-08-02 17:29:36 +02:00
|
|
|
current_res = 0
|
|
|
|
higher_res = -1
|
|
|
|
torrent_url = ''
|
2018-07-31 21:46:16 +02:00
|
|
|
resp = urllib2.urlopen(self.selected_inst + '/api/v1/videos/' + data['uuid'])
|
2018-07-31 16:50:22 +02:00
|
|
|
metadata = json.load(resp)
|
2018-08-02 17:29:36 +02:00
|
|
|
xbmc.log('PeertubeAddon: Looking for the best possible video matching user preferrences', xbmc.LOGDEBUG)
|
2018-07-31 16:50:22 +02:00
|
|
|
for f in metadata['files']:
|
2018-08-02 17:29:36 +02:00
|
|
|
# Get file resolution
|
|
|
|
res = f['resolution']['id']
|
|
|
|
if res == self.preferred_resolution:
|
|
|
|
# Stop directly, when we find the exact same resolution as the user's preferred one
|
|
|
|
xbmc.log('PeertubeAddon: Found video with preferred resolution', xbmc.LOGDEBUG)
|
2018-07-31 16:50:22 +02:00
|
|
|
torrent_url = f['torrentUrl']
|
2018-08-02 17:29:36 +02:00
|
|
|
break
|
|
|
|
elif res < self.preferred_resolution and res > current_res:
|
|
|
|
# Else, try to find the best one just below the user's preferred one
|
|
|
|
xbmc.log('PeertubeAddon: Found video with good lower resolution ({0})'.format(f['resolution']['label']), xbmc.LOGDEBUG)
|
|
|
|
torrent_url = f['torrentUrl']
|
|
|
|
current_res = res
|
|
|
|
elif res > self.preferred_resolution and ( res < higher_res or higher_res == -1 ):
|
|
|
|
# In the worth case, we'll take the one just above the user's preferred one
|
|
|
|
xbmc.log('PeertubeAddon: Saving video with higher resolution ({0}) as a possible alternative'.format(f['resolution']['label']), xbmc.LOGDEBUG)
|
|
|
|
backup_url = f['torrentUrl']
|
|
|
|
higher_res = res
|
|
|
|
|
|
|
|
# Use smallest file with an higher resolution, when we didn't find a resolution equal or
|
|
|
|
# slower than the user's preferred one
|
|
|
|
if not torrent_url:
|
|
|
|
xbmc.log('PeertubeAddon: Using video with higher resolution as alternative', xbmc.LOGDEBUG)
|
|
|
|
torrent_url = backup_url
|
|
|
|
|
|
|
|
# Compose the correct URL for Kodi
|
2018-07-31 16:50:22 +02:00
|
|
|
url = '{0}?action=play_video&url={1}'.format(self.plugin_url, torrent_url)
|
|
|
|
|
|
|
|
elif data_type == 'instances':
|
2018-07-31 16:52:45 +02:00
|
|
|
# TODO: Add a context menu to select instance as preferred instance
|
2018-07-31 16:50:22 +02:00
|
|
|
# Instances are not playable
|
|
|
|
list_item.setProperty('IsPlayable', 'false')
|
|
|
|
|
|
|
|
# Set URL to select this instance
|
2018-07-31 21:46:16 +02:00
|
|
|
url = '{0}?action=select_instance&url={1}'.format(self.plugin_url, data['host'])
|
2018-07-26 11:30:15 +02:00
|
|
|
|
2018-07-26 21:44:13 +02:00
|
|
|
# Add our item to the listing as a 3-element tuple.
|
|
|
|
listing.append((url, list_item, False))
|
2018-07-26 11:30:15 +02:00
|
|
|
|
2018-07-31 16:50:22 +02:00
|
|
|
# Add a 'Next page' button when there are more data to show
|
2018-07-31 10:43:17 +02:00
|
|
|
start = int(start) + self.items_per_page
|
2018-07-31 21:46:16 +02:00
|
|
|
if lst['total'] > start:
|
2018-07-31 16:50:22 +02:00
|
|
|
list_item = xbmcgui.ListItem( label='Next page ({0})'.format(start/self.items_per_page) )
|
|
|
|
url = '{0}?action=browse_{1}&start={2}'.format(self.plugin_url, data_type, start)
|
2018-07-29 22:14:06 +02:00
|
|
|
listing.append((url, list_item, True))
|
2018-07-28 13:54:19 +02:00
|
|
|
|
2018-07-30 12:00:27 +02:00
|
|
|
return listing
|
|
|
|
|
|
|
|
def search_videos(self, start):
|
|
|
|
"""
|
2018-07-31 16:50:22 +02:00
|
|
|
Function to search for videos on a PeerTube instance and navigate in the results
|
2018-07-30 12:00:27 +02:00
|
|
|
:param start: string
|
|
|
|
:result: None
|
|
|
|
"""
|
|
|
|
|
2018-07-30 21:23:44 +02:00
|
|
|
# Show a 'Search videos' dialog
|
|
|
|
search = xbmcgui.Dialog().input(heading='Search videos on ' + self.selected_inst, type=xbmcgui.INPUT_ALPHANUM)
|
2018-07-31 15:08:46 +02:00
|
|
|
|
2018-07-30 12:00:27 +02:00
|
|
|
# Go back to main menu when user cancels
|
|
|
|
if not search:
|
2018-07-31 22:36:48 +02:00
|
|
|
return None
|
2018-07-31 16:50:22 +02:00
|
|
|
|
|
|
|
# Create the PeerTube REST API request for searching videos
|
|
|
|
req = '{0}/api/v1/search/videos?search={1}&count={2}&start={3}&sort={4}'.format(self.selected_inst, search, self.items_per_page, start, self.sort_method)
|
2018-07-30 12:00:27 +02:00
|
|
|
|
2018-07-31 16:50:22 +02:00
|
|
|
# Send the query
|
|
|
|
results = self.query_peertube(req)
|
2018-07-30 12:00:27 +02:00
|
|
|
|
2018-07-31 22:36:48 +02:00
|
|
|
# Exit directly when no result is found
|
|
|
|
if not results:
|
|
|
|
xbmcgui.Dialog().notification('No videos found', 'No videos found matching query', xbmcgui.NOTIFICATION_WARNING)
|
|
|
|
return None
|
|
|
|
|
2018-07-30 12:33:37 +02:00
|
|
|
# Create array of xmbcgui.ListItem's
|
2018-07-31 16:50:22 +02:00
|
|
|
listing = self.create_list(results, 'videos', start)
|
2018-07-30 12:00:27 +02:00
|
|
|
|
|
|
|
# Add our listing to Kodi.
|
|
|
|
xbmcplugin.addDirectoryItems(self.plugin_id, listing, len(listing))
|
|
|
|
xbmcplugin.endOfDirectory(self.plugin_id)
|
2018-07-31 16:50:22 +02:00
|
|
|
|
|
|
|
return None
|
2018-07-30 12:00:27 +02:00
|
|
|
|
2018-07-31 16:50:22 +02:00
|
|
|
def browse_videos(self, start):
|
2018-07-30 12:00:27 +02:00
|
|
|
"""
|
2018-07-31 16:50:22 +02:00
|
|
|
Function to navigate through all the video published by a PeerTube instance
|
2018-07-30 12:00:27 +02:00
|
|
|
:param start: string
|
|
|
|
:return: None
|
|
|
|
"""
|
|
|
|
|
2018-07-31 16:50:22 +02:00
|
|
|
# Create the PeerTube REST API request for listing videos
|
|
|
|
req = '{0}/api/v1/videos?count={1}&start={2}&sort={3}'.format(self.selected_inst, self.items_per_page, start, self.sort_method)
|
|
|
|
|
|
|
|
# Send the query
|
|
|
|
results = self.query_peertube(req)
|
2018-07-30 12:00:27 +02:00
|
|
|
|
2018-07-30 12:33:37 +02:00
|
|
|
# Create array of xmbcgui.ListItem's
|
2018-07-31 16:50:22 +02:00
|
|
|
listing = self.create_list(results, 'videos', start)
|
2018-07-30 12:00:27 +02:00
|
|
|
|
2018-07-26 17:53:27 +02:00
|
|
|
# Add our listing to Kodi.
|
2018-07-29 22:14:06 +02:00
|
|
|
xbmcplugin.addDirectoryItems(self.plugin_id, listing, len(listing))
|
|
|
|
xbmcplugin.endOfDirectory(self.plugin_id)
|
2018-07-26 11:30:15 +02:00
|
|
|
|
2018-07-31 16:50:22 +02:00
|
|
|
return None
|
|
|
|
|
|
|
|
def browse_instances(self, start):
|
|
|
|
"""
|
|
|
|
Function to navigate through all PeerTube instances
|
|
|
|
:param start: str
|
|
|
|
:return: None
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Create the PeerTube REST API request for browsing PeerTube instances
|
|
|
|
req = '{0}/api/v1/instances?count={1}&start={2}'.format('https://instances.joinpeertube.org', self.items_per_page, start)
|
|
|
|
|
|
|
|
# Send the query
|
|
|
|
results = self.query_peertube(req)
|
|
|
|
|
|
|
|
# Create array of xmbcgui.ListItem's
|
|
|
|
listing = self.create_list(results, 'instances', start)
|
|
|
|
|
|
|
|
# Add our listing to Kodi.
|
|
|
|
xbmcplugin.addDirectoryItems(self.plugin_id, listing, len(listing))
|
|
|
|
xbmcplugin.endOfDirectory(self.plugin_id)
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
2018-07-27 18:40:24 +02:00
|
|
|
def play_video_continue(self, data):
|
2018-07-26 17:53:27 +02:00
|
|
|
"""
|
2018-07-26 19:59:47 +02:00
|
|
|
Callback function to let the play_video function resume when the PeertubeDownloader
|
|
|
|
has downloaded all the torrent's metadata
|
|
|
|
:param data: dict
|
|
|
|
:return: None
|
2018-07-26 17:53:27 +02:00
|
|
|
"""
|
2018-07-26 11:30:15 +02:00
|
|
|
|
2018-07-27 11:26:40 +02:00
|
|
|
xbmc.log('PeertubeAddon: Received metadata_downloaded signal, will start playing media', xbmc.LOGDEBUG)
|
2018-07-26 17:53:27 +02:00
|
|
|
self.play = 1
|
2018-07-27 10:53:28 +02:00
|
|
|
self.torrent_f = data['file']
|
2018-07-26 19:59:47 +02:00
|
|
|
|
2018-07-31 16:50:22 +02:00
|
|
|
return None
|
2018-07-26 17:53:27 +02:00
|
|
|
|
2018-07-27 10:53:28 +02:00
|
|
|
def play_video(self, torrent_url):
|
2018-07-26 17:53:27 +02:00
|
|
|
"""
|
|
|
|
Start the torrent's download and play it while being downloaded
|
2018-07-27 10:53:28 +02:00
|
|
|
:param torrent_url: str
|
2018-07-26 17:53:27 +02:00
|
|
|
:return: None
|
|
|
|
"""
|
|
|
|
|
2018-07-31 16:50:22 +02:00
|
|
|
xbmc.log('PeertubeAddon: Starting torrent download ({0})'.format(torrent_url), xbmc.LOGDEBUG)
|
2018-07-31 15:16:24 +02:00
|
|
|
|
2018-07-26 17:53:27 +02:00
|
|
|
# Start a downloader thread
|
2018-07-27 10:53:28 +02:00
|
|
|
AddonSignals.sendSignal('start_download', {'url': torrent_url})
|
2018-07-26 17:53:27 +02:00
|
|
|
|
2018-07-31 15:16:24 +02:00
|
|
|
# Wait until the PeerTubeDownloader has downloaded all the torrent's metadata
|
2018-07-26 21:59:50 +02:00
|
|
|
AddonSignals.registerSlot('plugin.video.peertube', 'metadata_downloaded', self.play_video_continue)
|
2018-07-31 15:16:24 +02:00
|
|
|
timeout = 0
|
|
|
|
while self.play == 0 and timeout < 10:
|
2018-07-26 17:53:27 +02:00
|
|
|
xbmc.sleep(1000)
|
2018-07-31 15:16:24 +02:00
|
|
|
timeout += 1
|
|
|
|
|
|
|
|
# Abort in case of timeout
|
|
|
|
if timeout == 10:
|
|
|
|
xbmcgui.Dialog().notification('Download timeout', 'Timeout fetching ' + torrent_url, xbmcgui.NOTIFICATION_ERROR)
|
2018-07-31 16:50:22 +02:00
|
|
|
return None
|
2018-07-31 15:16:24 +02:00
|
|
|
else:
|
|
|
|
# Wait a little before starting playing the torrent
|
|
|
|
xbmc.sleep(3000)
|
2018-07-26 17:53:27 +02:00
|
|
|
|
|
|
|
# Pass the item to the Kodi player for actual playback.
|
2018-07-31 16:50:22 +02:00
|
|
|
xbmc.log('PeertubeAddon: Starting video playback ({0})'.format(torrent_url), xbmc.LOGDEBUG)
|
2018-07-27 10:53:28 +02:00
|
|
|
play_item = xbmcgui.ListItem(path=self.torrent_f)
|
2018-07-29 22:14:06 +02:00
|
|
|
xbmcplugin.setResolvedUrl(self.plugin_id, True, listitem=play_item)
|
2018-07-26 17:53:27 +02:00
|
|
|
|
2018-07-31 16:50:22 +02:00
|
|
|
return None
|
|
|
|
|
|
|
|
def select_instance(self, instance):
|
|
|
|
"""
|
|
|
|
Change currently selected instance to 'instance' parameter
|
|
|
|
:param instance: str
|
|
|
|
:return: None
|
|
|
|
"""
|
|
|
|
|
2018-07-31 22:06:58 +02:00
|
|
|
self.selected_inst = 'https://' + instance
|
|
|
|
xbmcgui.Dialog().notification('Current instance changed', 'Changed current instance to {0}'.format(self.selected_inst), xbmcgui.NOTIFICATION_INFO)
|
|
|
|
xbmc.log('PeertubeAddon: Changing currently selected instance to {0}'.format(self.selected_inst), xbmc.LOGDEBUG)
|
2018-07-31 16:50:22 +02:00
|
|
|
|
|
|
|
return None
|
|
|
|
|
2018-07-28 13:35:28 +02:00
|
|
|
def main_menu(self):
|
|
|
|
"""
|
2018-07-31 15:08:46 +02:00
|
|
|
Addon's main menu
|
|
|
|
:param: None
|
|
|
|
:return: None
|
2018-07-28 13:35:28 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
# Create a list for our items.
|
|
|
|
listing = []
|
|
|
|
|
|
|
|
# 1st menu entry
|
|
|
|
list_item = xbmcgui.ListItem(label='Browse selected instance')
|
2018-07-31 16:50:22 +02:00
|
|
|
url = '{0}?action=browse_videos&start=0'.format(self.plugin_url)
|
2018-07-29 22:14:06 +02:00
|
|
|
listing.append((url, list_item, True))
|
2018-07-28 13:35:28 +02:00
|
|
|
|
|
|
|
# 2nd menu entry
|
|
|
|
list_item = xbmcgui.ListItem(label='Search on selected instance')
|
2018-07-31 16:50:22 +02:00
|
|
|
url = '{0}?action=search_videos&start=0'.format(self.plugin_url)
|
2018-07-31 22:00:33 +02:00
|
|
|
listing.append((url, list_item, True))
|
2018-07-28 13:35:28 +02:00
|
|
|
|
|
|
|
# 3rd menu entry
|
|
|
|
list_item = xbmcgui.ListItem(label='Select other instance')
|
2018-07-31 16:50:22 +02:00
|
|
|
url = '{0}?action=browse_instances&start=0'.format(self.plugin_url)
|
2018-07-31 22:00:33 +02:00
|
|
|
listing.append((url, list_item, True))
|
2018-07-28 13:35:28 +02:00
|
|
|
|
|
|
|
# Add our listing to Kodi.
|
2018-07-29 22:14:06 +02:00
|
|
|
xbmcplugin.addDirectoryItems(self.plugin_id, listing, len(listing))
|
2018-07-28 13:35:28 +02:00
|
|
|
|
|
|
|
# Finish creating a virtual folder.
|
2018-07-29 22:14:06 +02:00
|
|
|
xbmcplugin.endOfDirectory(self.plugin_id)
|
2018-07-31 16:50:22 +02:00
|
|
|
|
|
|
|
return None
|
2018-07-28 13:35:28 +02:00
|
|
|
|
2018-07-26 17:53:27 +02:00
|
|
|
def router(self, paramstring):
|
|
|
|
"""
|
|
|
|
Router function that calls other functions
|
|
|
|
depending on the provided paramstring
|
|
|
|
:param paramstring: dict
|
|
|
|
:return: None
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Parse a URL-encoded paramstring to the dictionary of
|
|
|
|
# {<parameter>: <value>} elements
|
|
|
|
params = dict(parse_qsl(paramstring[1:]))
|
|
|
|
|
|
|
|
# Check the parameters passed to the plugin
|
|
|
|
if params:
|
2018-07-31 16:50:22 +02:00
|
|
|
if params['action'] == 'browse_videos':
|
|
|
|
# Browse videos on selected instance
|
|
|
|
self.browse_videos(params['start'])
|
|
|
|
elif params['action'] == 'search_videos':
|
2018-07-30 21:17:08 +02:00
|
|
|
# Search for videos on selected instance
|
2018-07-30 12:33:37 +02:00
|
|
|
self.search_videos(params['start'])
|
2018-07-31 16:50:22 +02:00
|
|
|
elif params['action'] == 'browse_instances':
|
|
|
|
# Browse peerTube instances
|
|
|
|
self.browse_instances(params['start'])
|
|
|
|
elif params['action'] == 'play_video':
|
2018-07-28 13:35:28 +02:00
|
|
|
# Play video from provided URL.
|
|
|
|
self.play_video(params['url'])
|
2018-07-31 16:50:22 +02:00
|
|
|
elif params['action'] == 'select_instance':
|
|
|
|
self.select_instance(params['url'])
|
2018-07-26 17:53:27 +02:00
|
|
|
else:
|
2018-07-28 13:35:28 +02:00
|
|
|
# Display the addon's main menu when the plugin is called from Kodi UI without any parameters
|
|
|
|
self.main_menu()
|
2018-07-26 11:30:15 +02:00
|
|
|
|
2018-07-31 16:50:22 +02:00
|
|
|
return None
|
|
|
|
|
2018-07-26 11:30:15 +02:00
|
|
|
if __name__ == '__main__':
|
2018-07-26 17:53:27 +02:00
|
|
|
|
|
|
|
# Initialise addon
|
2018-07-29 22:14:06 +02:00
|
|
|
addon = PeertubeAddon(sys.argv[0], int(sys.argv[1]))
|
2018-07-26 11:30:15 +02:00
|
|
|
# Call the router function and pass the plugin call parameters to it.
|
2018-07-26 17:53:27 +02:00
|
|
|
addon.router(sys.argv[2])
|