Skip to content

Commit

Permalink
[plugin.video.ytchannels] 0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mintsoft committed Feb 6, 2022
1 parent 3d228f2 commit cba7973
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion plugin.video.ytchannels/addon.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.ytchannels" name="YouTube Channels" version="0.3.6+matrix.1" provider-name="natko1412,mintsoft,yeahme49">
<addon id="plugin.video.ytchannels" name="YouTube Channels" version="0.4.0+matrix.1" provider-name="natko1412,mintsoft,yeahme49">
<requires>
<import addon="xbmc.python" version="3.0.0"/>
<import addon="script.module.six" version="1.11.0"/>
Expand Down
4 changes: 4 additions & 0 deletions plugin.video.ytchannels/changelog.txt
@@ -1,6 +1,10 @@
===============================
Youtube Channels addon by yeahme49/mintsoft/natko1412
===============================
v0.4.0 [06-Feb-2022]
-URL encode channel name to support UTF-8 encoding
-Update yt_time function
-Add thumbnail and channel description when searching for new channels to add

v0.3.6 [28-Aug-2021]
-Show live streams for a channel
Expand Down
Expand Up @@ -137,6 +137,10 @@ msgctxt "#30029"
msgid "Live"
msgstr ""

msgctxt "#30031"
msgid "Playing using YouTube"
msgstr ""

msgctxt "#30099"
msgid "Youtube channels"
msgstr ""
Expand Down Expand Up @@ -176,4 +180,3 @@ msgstr ""
msgctxt "#30208"
msgid "Enable live streams"
msgstr ""

11 changes: 8 additions & 3 deletions plugin.video.ytchannels/resources/lib/functions.py
Expand Up @@ -7,6 +7,7 @@
import json
import sys
import re
from requests.utils import requote_uri
from six.moves import urllib

addonID = xbmcaddon.Addon().getAddonInfo("id")
Expand Down Expand Up @@ -52,7 +53,7 @@ def yt_time(duration="P1W2DT6H21M32S"):
# Put list in ascending order & remove 'None' types
units = list(reversed([int(x) if x != None else 0 for x in units]))
# Do the maths
return sum([x*60**units.index(x) for x in units])
return units[2]*60*60 + units[1]*60 + units[0]

def move_up(id):
cur = db.cursor()
Expand Down Expand Up @@ -145,6 +146,7 @@ def delete_database():
return

def read_url(url):
url = requote_uri(url)
req = urllib.request.Request(url)
req.add_header('User-Agent', 'Mozilla/5.0 (Windows NT 6.1; rv:33.0) Gecko/20100101 Firefox/33.0')
response = urllib.request.urlopen(req)
Expand Down Expand Up @@ -276,21 +278,22 @@ def search_channel(channel_name):
my_addon = xbmcaddon.Addon()
result_num = my_addon.getSetting('result_number_channels')

req_url='https://www.googleapis.com/youtube/v3/search?q=%s&type=channel&part=snippet&maxResults=%s&key=%s'%(channel_name.replace(' ','%20'),str(result_num),YOUTUBE_API_KEY)
req_url='https://www.googleapis.com/youtube/v3/search?q=%s&type=channel&part=snippet&maxResults=%s&key=%s'%(channel_name,str(result_num),YOUTUBE_API_KEY)
read=read_url(req_url)
decoded_data=json.loads(read)
listout=[]

for x in range(0, len(decoded_data['items'])):
title=decoded_data['items'][x]['snippet']['title']
thumb=decoded_data['items'][x]['snippet']['thumbnails']['high']['url']
desc=decoded_data['items'][x]['snippet']['description']
channel_id=decoded_data['items'][x]['snippet']['channelId']
req1='https://www.googleapis.com/youtube/v3/channels?part=contentDetails&id=%s&key=%s'%(channel_id,YOUTUBE_API_KEY)
read2=read_url(req1)
decoded_data2=json.loads(read2)
try:
channel_uplid=decoded_data2['items'][0]['contentDetails']['relatedPlaylists']['uploads']
listout.append([title,channel_uplid,thumb,channel_id])
listout.append([title,channel_uplid,thumb,channel_id,desc])
except:
pass

Expand All @@ -312,11 +315,13 @@ def search_channel_by_username(username):

title=decoded_data['items'][0]['snippet']['title']
thumb=decoded_data['items'][0]['snippet']['thumbnails']['high']['url']
desc=decoded_data['items'][0]['snippet']['description']
channel_uplid=uploads_id
listout.append(title)
listout.append(channel_uplid)
listout.append(thumb)
listout.append(channel_id)
listout.append(desc)
return listout
elif decoded_data['pageInfo']['totalResults']==0:
return 'not found'
Expand Down
8 changes: 5 additions & 3 deletions plugin.video.ytchannels/resources/lib/ytchannels.py
Expand Up @@ -321,6 +321,7 @@ def ytchannels_main():
plot = desc

uri='plugin://plugin.video.youtube/play/?video_id='+video_id

li = xbmcgui.ListItem('%s'%title)
li.setArt({'icon':thumb})
li.setProperty('IsPlayable', 'true')
Expand All @@ -346,11 +347,12 @@ def ytchannels_main():

results=search_channel(channel_name)

result_list=[]
li=[None]*len(results)
for i in range(len(results)):
result_list+=[results[i][0]]
li[i] = xbmcgui.ListItem(results[i][0],results[i][4])
li[i].setArt({'icon':results[i][2]})
dialog = xbmcgui.Dialog()
index = dialog.select(local_string(30013), result_list)
index = dialog.select(local_string(30013), li, useDetails=True)
if index>-1:
channel_uplid=results[index][1]
channel_name=results[index][0]
Expand Down

0 comments on commit cba7973

Please sign in to comment.