Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff -Naur ytcold/addon.xml ytcnew/addon.xml
- --- ytcold/addon.xml 2013-03-20 19:09:52.000000000 +0000
- +++ ytcnew/addon.xml 2015-04-26 16:04:34.000000000 +0000
- @@ -2,6 +2,7 @@
- <addon id="plugin.video.youtube.channels" name="YouTube Channels" version="2.0.2" provider-name="AddonScriptorDE">
- <requires>
- <import addon="xbmc.python" version="2.1.0"/>
- + <import addon="script.module.simplejson" version="2.0.10"/>
- </requires>
- <extension point="xbmc.python.pluginsource" library="default.py">
- <provides>video</provides>
- diff -Naur ytcold/default.py ytcnew/default.py
- --- ytcold/default.py 2013-03-20 19:09:52.000000000 +0000
- +++ ytcnew/default.py 2015-04-27 16:40:22.000000000 +0000
- @@ -1,6 +1,10 @@
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- import xbmcaddon,xbmcplugin,xbmcgui,sys,urllib,urllib2,re,socket,os
- +try:
- + import json
- +except:
- + import simplejson as json
- socket.setdefaulttimeout(30)
- pluginhandle = int(sys.argv[1])
- @@ -147,45 +151,44 @@
- fh.close()
- def listVideos(params):
- + apikey="AIzaSyAd-YEOqZz9nXVzGtn3KWzYLbLaajhqIDA"
- spl=params.split("#")
- user=spl[0]
- index=spl[1]
- orderby=spl[2]
- updateThumb(user)
- - content = getUrl("http://gdata.youtube.com/feeds/api/videos?author="+user+"&racy=include&max-results=50&start-index="+index+"&orderby="+orderby+"&v=2")
- - match=re.compile("<openSearch:totalResults>(.+?)</openSearch:totalResults><openSearch:startIndex>(.+?)</openSearch:startIndex>", re.DOTALL).findall(content)
- - maxIndex=int(match[0][0])
- - startIndex=int(match[0][1])
- - spl=content.split('<entry')
- - for i in range(1,len(spl),1):
- - entry=spl[i]
- - match=re.compile('<yt:videoid>(.+?)</yt:videoid>', re.DOTALL).findall(entry)
- - id=match[0]
- - match=re.compile("viewCount='(.+?)'", re.DOTALL).findall(entry)
- - viewCount="0"
- - if len(match)>0:
- - viewCount=match[0]
- - match=re.compile("duration='(.+?)'", re.DOTALL).findall(entry)
- - durationTemp=int(match[0])
- - min=(durationTemp/60)+1
- - sec=durationTemp%60
- - duration=str(min)+":"+str(sec)
- - match=re.compile("<author><name>(.+?)</name>", re.DOTALL).findall(entry)
- - author=match[0]
- - match=re.compile("<media:title type='plain'>(.+?)</media:title>", re.DOTALL).findall(entry)
- - title=match[0]
- - title=cleanTitle(title)
- - match=re.compile("<media:description type='plain'>(.+?)</media:title>", re.DOTALL).findall(entry)
- - desc=""
- - if len(match)>0:
- - desc=match[0]
- - desc=cleanTitle(desc)
- - match=re.compile("<published>(.+?)T", re.DOTALL).findall(entry)
- - date=match[0]
- - thumb="http://img.youtube.com/vi/"+id+"/0.jpg"
- + newcontent = getUrl("https://www.googleapis.com/youtube/v3/channels?part=contentDetails&"+
- + "forUsername="+user+
- + "&racy=include&maxResults=50&startIndex="+index+
- + "&orderby="+orderby+
- + "&key="+apikey)
- + userdata = json.loads(newcontent)
- + playlistid = userdata['items'][0]['contentDetails']['relatedPlaylists']['uploads']
- + print "Playlist for the user's uploads is: "+playlistid
- + params = "?part=id%2Csnippet%2CcontentDetails%2Cstatus"+"&playlistId="+playlistid+"&maxResults=50"+"&key="+apikey
- + if index!="1":
- + params=params+"&pageToken="+index
- + newcontent = getUrl("https://www.googleapis.com/youtube/v3/playlistItems"+params)
- + playlistdata = json.loads(newcontent)
- + videos = playlistdata['items']
- + for i in range(0,len(videos),1):
- + #print "Titel: "+videos[i]['snippet']['title'].encode('utf8')
- + id = videos[i]['snippet']['resourceId']['videoId']
- + #print "Video-ID: "+id
- + viewCount="0" #not available via this API-Call, and not interesting for me
- + duration="0" #TODO: not available via this API-Call
- + author=videos[i]['snippet']['channelTitle']
- + title=videos[i]['snippet']['title']
- + desc=videos[i]['snippet']['description']
- + date=videos[i]['snippet']['publishedAt']
- + thumb="https://i.ytimg.com/vi/"+id+"/0.jpg" #behaviour kept from the old api, now the URL is also available from the API in different resolutions
- addLink(title,id,'playVideo',thumb,"Date: "+date+"; Views: "+viewCount+"\n"+desc,duration,author)
- - if startIndex+50<=maxIndex:
- - addDir(translation(30007),user+"#"+str(int(index)+50)+"#"+orderby,'listVideos',"")
- + print 'nextPageToken' in playlistdata
- + print hasattr(playlistdata, 'nextPageToken')
- + try:
- + addDir(translation(30007),user+"#"+playlistdata['nextPageToken']+"#"+orderby,'listVideos',"")
- + except KeyError:
- + print "Seems to be the last page"
- xbmcplugin.endOfDirectory(pluginhandle)
- if forceViewMode=="true":
- xbmc.executebuiltin('Container.SetViewMode('+viewMode+')')
- @@ -398,6 +401,7 @@
- xbmc.executebuiltin("Container.Refresh")
- def getUrl(url):
- + print "Fetching URL: "+url
- req = urllib2.Request(url)
- req.add_header('User-Agent', 'Mozilla/5.0 (Windows NT 6.1; rv:19.0) Gecko/20100101 Firefox/19.0')
- response = urllib2.urlopen(req)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement