-#!/usr/bin/env python
+#!/usr/bin/env python3
#
# See: https://kodi.wiki/view/Audio-video_add-on_tutorial
#
import sys
-import urllib,urllib2
+import urllib.request
import re,json
+import youtube_dl
def get_params():
param = []
param[splitparams[0]] = splitparams[1]
return param
-def getUrl(url,exp=''):
- req = urllib2.Request(url)
- req.add_header('User-Agent', 'Kodi')
- response = urllib2.urlopen(req)
- content = response.read()
- response.close()
- if exp != '':
- match = re.compile(exp,re.DOTALL).findall(content)
- return match
- return content
+def getUrl(url):
+ req = urllib.request.Request(
+ url,
+ data=None,
+ headers={
+ 'User-Agent': 'Kodi'
+ }
+ )
+ return urllib.request.urlopen(req).read().decode('utf-8')
def getParams():
param=[]
ok = xbmcplugin.addDirectoryItem(handle=addon_handle,url=u,listitem=li,isFolder=True)
return ok
-def getVideos(url):
- content = getUrl(url)
- return content
- #from BeautifulSoup import BeautifulSoup
- #from io import StringIO, BytesIO
- #from lxml.html import parse
- #from lxml.html import document_fromstring
- #from lxml import etree
- #from HTMLParser import HTMLParser
- #tree = etree.HTML(content)
- #return tree.cssselect('article')
-
- #tree = parse(url).getroot()
- #return tree
- parser = etree.HTMLParser()
- content = etree.tostring(content, encoding='unicode')
- html = StringIO(content)
- #tree = etree.parse(StringIO(content), parser)
- #print tree
- #tree.get('article')
- #soup = BeautifulSoup(content)
- #return soup.body.find('article', attrs={'class' : 'news-item'})
- videos = []
- #for item in content:
+def getYoutube(id):
+ ydl = youtube_dl.YoutubeDL({'outtmpl': '%(id)s%(ext)s'})
+ with ydl:
+ result = ydl.extract_info(
+ 'http://www.youtube.com/watch?v='+id,
+ download = False,
+ )
+
+ if 'entries' in result:
+ # Can be a playlist or a list of videos
+ video = result['entries'][0]
+ else:
+ # Just a video
+ video = result
+
+ return str(video)
#
# Main
#
KODI = True
-#KODI = False
+KODI = False
-reload(sys)
-sys.setdefaultencoding("UTF8")
+# pyhton2
+#reload(sys)
+#sys.setdefaultencoding("UTF8")
if KODI:
import xbmcgui
# NB 22.04.19 __icon__ = addon.getAddonInfo('icon')
# NB 22.04.19 __fanart__ = addon.getAddonInfo('fanart')
addon_handle = int(sys.argv[1])
- #xbmcplugin.setContent(addon_handle, 'plugin.video.news.nbdom.net')
xbmcplugin.setContent(addon_handle, 'movies')
- url = None
- name = None
- mode = None
-# NB 22.04.19 params=get_params()
-# NB 22.04.19 try:
-# NB 22.04.19 url=urllib.unquote_plus(params["url"])
-# NB 22.04.19 except:
-# NB 22.04.19 pass
-# NB 22.04.19 try:
-# NB 22.04.19 name=urllib.unquote_plus(params["name"])
-# NB 22.04.19 except:
-# NB 22.04.19 pass
-# NB 22.04.19 try:
-# NB 22.04.19 mode=int(params["mode"])
-# NB 22.04.19 except:
-# NB 22.04.19 pass
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 } )
xbmcplugin.addDirectoryItem(handle=addon_handle,url=row['link'],listitem=li)
else:
- print '\t'.join([
+ print('\t'.join([
row['lang'],
row['title'],
row['description'],
row['id'],
row['link'],
- ])
+ ]))
# 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')