Added code to get all videos from a peertube instance + added

some code to enrich the ListItem's with more info

TODO: Make it possible to specify the instance the user wants to browse
This commit is contained in:
Cyrille Bollu 2018-07-26 13:04:47 +02:00
parent 83a37cbcd3
commit 4271e7baa4
1 changed files with 26 additions and 14 deletions

View File

@ -8,6 +8,7 @@
# - Make sure we are seeding when downloading and watching # - Make sure we are seeding when downloading and watching
# - 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
import libtorrent import libtorrent
import time, sys import time, sys
@ -27,36 +28,47 @@ def list_videos():
:return: None :return: None
""" """
# List of videos. # TODO: Make the instance configurable
# TODO: Get this list from an instance, several instances, or the result from a search # Make it actuatly possible to use several instances
videos = ['https://peertube.cpy.re/api/v1/videos/5a6133b8-3e0c-40dc-b859-69d0540c3fe5', inst = 'https://peertube.cpy.re'
'https://peertube.cpy.re/api/v1/videos/a8ea95b8-0396-49a6-8f30-e25e25fb2828']
# Get the list of videos published by the instance
resp = urllib2.urlopen(inst + '/api/v1/videos')
videos = json.load(resp)
# Return when no videos are found
if videos['total'] == 0:
return
# Create a list for our items. # Create a list for our items.
listing = [] listing = []
for video in videos: for video in videos:
# Get video metadata
resp = urllib2.urlopen(video)
metadata = json.load(resp)
# Create a list item with a text label # Create a list item with a text label
# TODO: Get video thumbnail and add it to list_item # TODO: Get video thumbnail and add it to list_item
list_item = xbmcgui.ListItem(label=metadata['name']) list_item = xbmcgui.ListItem(label=video['name'])
# list_item = xbmcgui.ListItem(label=metadata['name'], thumbnailImage=video['thumb']) # list_item = xbmcgui.ListItem(label=metadata['name'], thumbnailImage=video['thumb'])
# Set a fanart image for the list item. # Set a fanart image for the list item.
#list_item.setProperty('fanart_image', video['thumb']) #list_item.setProperty('fanart_image', video['thumb'])
# Set additional info for the list item. # Compute media info from video's metadata
# TODO: Manage multiple tags info = {'title': video['name'],
# TODO: Add video's description to the list_item's info 'playcount': video['views'],
list_item.setInfo('video', {'title': metadata['name'], 'tags': metadata['tags'][0]}) 'plotoutline': video['description'],
'duration': video['duration']
}
# Add a rating based on likes and dislikes
if video['likes'] > 0 or video['dislikes'] > 0):
info['rating'] = video['likes']/(video['likes'] + video['dislikes']
# Set additional info for the list item.
list_item.setInfo('video', info)
# Set 'IsPlayable' property to 'true'.
# This is mandatory for playable items! # This is mandatory for playable items!
list_item.setProperty('IsPlayable', 'true') list_item.setProperty('IsPlayable', 'true')
# Find smallest file's torrentUrl # Find smallest file's torrentUrl
# TODO: Get the best quality torrent given settings and/or available bandwidth # TODO: Get the best quality torrent given settings and/or available bandwidth
# See how they do that in the peerTube client's code # See how they do that in the peerTube client's code