Index: channels/youtube.py ================================================================== --- channels/youtube.py +++ channels/youtube.py @@ -1,11 +1,11 @@ # encoding: UTF-8 # api: streamtuner2 # title: Youtube # description: Channel, playlist and video browsing for youtube. # type: channel -# version: 0.2 +# version: 0.3 # url: http://www.youtube.com/ # category: video # config: # { name: youtube_channels, type: text, value: "Key Of Awesome, Pentatonix", description: "Preferred channels to list videos from.", category: select } # { name: youtube_region, type: select, select: "=No Region|AR=Argentina|AU=Australia|AT=Austria|BE=Belgium|BR=Brazil|CA=Canada|CL=Chile|CO=Colombia|CZ=Czech Republic|EG=Egypt|FR=France|DE=Germany|GB=Great Britain|HK=Hong Kong|HU=Hungary|IN=India|IE=Ireland|IL=Israel|IT=Italy|JP=Japan|JO=Jordan|MY=Malaysia|MX=Mexico|MA=Morocco|NL=Netherlands|NZ=New Zealand|PE=Peru|PH=Philippines|PL=Poland|RU=Russia|SA=Saudi Arabia|SG=Singapore|ZA=South Africa|KR=South Korea|ES=Spain|SE=Sweden|CH=Switzerland|TW=Taiwan|AE=United Arab Emirates|US=United States", value: GB, description: "Filter by region id.", category: auth } @@ -196,21 +196,29 @@ # - iterates over playlist # - then over playlistitems to get videos elif cat in channels: # channel id, e.g. UCEmCXnbNYz-MOtXi3lZ7W1Q UC = self.channel_id(cat) + + # fetches videos ordered by date + for row in self.api("search", order="date", fields="pageInfo,nextPageToken,items(id,snippet(title,channelTitle,description))", channelId=UC, type="video"): + entries.append( self.wrap3(row, {"genre": cat, "playing": cat}) ) - # playlist + # augments with playlist entries for i,playlist in enumerate(self.api("playlists", fields="items(id,snippet/title)", channelId=UC, maxResults=15)): # items (videos) for row in self.api("playlistItems", playlistId=playlist["id"], fields="items(snippet(title,resourceId/videoId,description))"): entries.append(self.wrap3(row, {"genre": cat, "playing": playlist["snippet"]["title"]})) self.update_streams_partially_done(entries) self.parent.status(i / 15.0) + # unique entries + e = [] + [e.append(v) for v in entries if v not in e] + entries = e # empty entries else: return self.placeholder @@ -232,20 +240,21 @@ #-- Retrieve Youtube API query results # - def api(self, method, ver=3, pages=5, **params): + def api(self, method, ver=3, pages=5, debug=False, **params): items = [] # URL and default parameters (base_url, defaults) = self.service[ver] params = dict( list(defaults.items()) + list(params.items()) ) # Retrieve data set while pages > 0: j = ahttp.get(base_url + method, params=params) + #if debug: #log.DATA(j) if j: # json decode data = json.loads(j) @@ -291,16 +300,19 @@ url = "http://youtube.com/v/" + id, homepage = "http://youtu.be/" + id + ("?wadsworth=1" if conf.youtube_wadsworth else ""), format = self.audioformat, title = row["snippet"]["title"], )) + #log.DATA(row) # optional values - if "playing" not in data: - data["playing"] = row["snippet"]["channelTitle"] - if "description" in row["snippet"]: - data["description"] = row["snippet"]["description"], + if "snippet" in row: + if "playing" not in data and "channelTitle" in row["snippet"]: + data["playing"] = row["snippet"]["channelTitle"] + if "description" in row["snippet"] and "description" in row["snippet"]: + data["description"] = row["snippet"]["description"], + #log.UI(data) return data # API version 2.0s jsonified XML needs different unpacking: