From 57a724732a7727077a236c5c7f38ced5865c9d7c Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Mon, 22 Apr 2019 15:30:54 +0100 Subject: [PATCH] addon.py --- addon.py | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/addon.py b/addon.py index 57e2d38..01794ac 100755 --- a/addon.py +++ b/addon.py @@ -4,6 +4,7 @@ # import sys +import os import urllib.request import re,json import youtube_dl @@ -73,8 +74,8 @@ def addDir(name,url,mode,iconimage,description): ok = xbmcplugin.addDirectoryItem(handle=addon_handle,url=u,listitem=li,isFolder=True) return ok -def getYoutube(id): - ydl = youtube_dl.YoutubeDL({'outtmpl': '%(id)s%(ext)s'}) +def ytUrl(id): + ydl = youtube_dl.YoutubeDL({'outtmpl': '%(id)s%(ext)s', 'quiet': True}) with ydl: result = ydl.extract_info( 'http://www.youtube.com/watch?v='+id, @@ -86,21 +87,22 @@ def getYoutube(id): video = result['entries'][0] else: # Just a video - video = result + video = result['formats'][0]['url'] - return str(video) + return video # # Main # -KODI = True -KODI = False +TEST = False +if len(sys.argv)>1 and sys.argv[1] == '--test': + TEST = True # pyhton2 #reload(sys) #sys.setdefaultencoding("UTF8") -if KODI: +if not TEST: import xbmcgui import xbmcplugin # NB 22.04.19 addon = xbmcaddon.Addon('plugin.video.news.nbdom.net') @@ -109,19 +111,12 @@ if KODI: # NB 22.04.19 __fanart__ = addon.getAddonInfo('fanart') addon_handle = int(sys.argv[1]) xbmcplugin.setContent(addon_handle, 'movies') + sys.stderr = open(os.devnull, "w") content = getUrl('https://news.nbdom.net/videos/kodi/') for row in json.loads(content): - row['link'] = getYoutube(row['id']) - if KODI: - iconimage = 'https://i1.ytimg.com/vi/' + row['id'] + '/mqdefault.jpg' - li = xbmcgui.ListItem(row['title'] +' ' + row['description'], iconImage="DefaultVideo.png", thumbnailImage=iconimage) -# NB 22.04.19 li.setInfo( 'video', infoLabels={ -# NB 22.04.19 'title': row['title'], -# NB 22.04.19 'plot': row['description'] -# NB 22.04.19 } ) - xbmcplugin.addDirectoryItem(handle=addon_handle,url=row['link'],listitem=li) - else: + row['link'] = ytUrl(row['id']) + if TEST: print('\t'.join([ row['lang'], row['title'], @@ -129,12 +124,21 @@ for row in json.loads(content): row['id'], row['link'], ])) + break + else: + iconimage = 'https://i1.ytimg.com/vi/' + row['id'] + '/mqdefault.jpg' + li = xbmcgui.ListItem(row['title'] +' ' + row['description'], iconImage="DefaultVideo.png", thumbnailImage=iconimage) +# NB 22.04.19 li.setInfo( 'video', infoLabels={ +# NB 22.04.19 'title': row['title'], +# NB 22.04.19 'plot': row['description'] +# NB 22.04.19 } ) + xbmcplugin.addDirectoryItem(handle=addon_handle,url=row['link'],listitem=li) # NB 17.04.19 url = 'https://nbdom.net/data/en/911-experiments-The_Force_Behind_the_Motion.mp4' # NB 17.04.19 li = xbmcgui.ListItem('My First Video!', iconImage='DefaultVideo.png') # NB 17.04.19 xbmcplugin.addDirectoryItem(handle=addon_handle, url=url, listitem=li) -if KODI: +if not TEST: xbmcplugin.endOfDirectory(addon_handle) #sys.exit(0) -- 2.47.3