WIP need help with json decoder to parse youtube url
#1
Sorry for bothering you guys with this but I have never coded anything and was trying to make my first addon and am stuck, maybe one of you could bail me out. So I want to build an addon that basically goes out to a website called armlook.com to the url of a particular show, and then finds the urls of recent episodes of that show which are posted to youtube or similar sites, and displays them in the menu of the addon. The show page is here: http://www.armlook.com/show/armenia-tv/h...-tshnami/3

So I consulted with a guy whose website I was using to try to learn how to make this addon and he said the easiest thing to do would be to decode this page which is in JSON:
http://www.armlook.com/program/allEpisod...0/offset/0
He said I could change the "60" in the URL to anything to change the number of episodes (from most recent) displayed. The code for a single episode is:
Code:
[{"id":"3212","e":"Episode 413","p":"Harazat Tshnami","m":"NOV","d":"14","url":"\/episode\/armenia-tv\/harazat-tshnami\/episode-413\/3212","type":"episode","bg":"\/uploads\/images\/episodes\/img_54665ccdf2ec2.png","bgb":"\/uploads\/images\/episodes\/big\/img_54665ccdf2ec2.png","new":true}]

He said to decode the "URL" lines on this page which take you to the page on armlook that has the individual episode embedded from youtube, then parse that youtube url. I understand what he is saying but I have no idea how to put that into code. I have searched the web for days for any info on how to do this or for any addons that do the same thing and have gotten nowhere and am now surrendering to you experts in hope that someone can help me finish this project.

Here is what my default.py code looks like at the moment.
Code:
import util, urllib2
import simplejson as json

def playVideo(params):
    response = urllib2.urlopen(params['video'])
    if response and response.getcode() == 200:
        jsonurl = urlopen(url)
        text = json.loads(jsonurl.read())
        content = response.read()
        videoLink = util.extract(content, 'flashvars.File = "', '"')
        util.playMedia(params['title'], params['image'], videoLink, 'Video')
    else:
        util.showError(ADDON_ID, 'Could not open URL %s to get video information' % (params['video']))
    
def buildMenu():
    url = WEB_PAGE_BASE
    response = urllib2.urlopen(url)
    jsonurl = urlopen(url)
        text = json.loads(jsonurl.read())
    if response and response.getcode() == 200:
        content = response.read()
        videos = util.extractAll(content, '<div class="video">', '</div>')
        for video in videos:
            params = {'play':1}
            params['video'] = WEB_PAGE_BASE + util.extract(video, 'src="', '\"')
            params['image'] = WEB_PAGE_BASE + util.extract(video, 'img src="', '\"')
            params['title'] = util.extract(video, '</a>', '<')
            link = util.makeLink(params)
            util.addMenuItem(params['title'], link, 'DefaultVideo.png', params['image'], False)
        util.endListing()
    else:
        util.showError(ADDON_ID, 'Could not open URL %s to create menu' % (url))

WEB_PAGE_BASE = 'http://www.armlook.com/program/allEpisodes/3/limit/3/offset/0'
ADDON_ID = 'plugin.video.hartsh'

parameters = util.parseParameters()
if 'play' in parameters:
    playVideo(parameters)
else:
    buildMenu()
Can anyone help me?
Reply
#2
F.e. in this webpage http://www.armlook.com/episode/armenia-t...anons/3222 u can see the embedded youtube file:
<iframe width="853" height="480" src="//www.youtube.com/embed/4ALIehnpw8M" frameborder="0" allowfullscreen></iframe>

U need to grab the youtubeID. That's "4ALIehnpw8M" in this example.
Then: youtube_url = 'plugin://plugin.video.youtube/?action=play_video&videoid=%s' % youtubeID

xbmc should be able to play the youtube_url.

Check plugin.video.nlhardwareinfo\resources\lib\nlhardwareinfo_list_play.py as an example.

Good luck.
Reply
#3
(2014-11-17, 20:48)Skipmode A1 Wrote: F.e. in this webpage http://www.armlook.com/episode/armenia-t...anons/3222 u can see the embedded youtube file:
<iframe width="853" height="480" src="//www.youtube.com/embed/4ALIehnpw8M" frameborder="0" allowfullscreen></iframe>

U need to grab the youtubeID. That's "4ALIehnpw8M" in this example.
Then: youtube_url = 'plugin://plugin.video.youtube/?action=play_video&videoid=%s' % youtubeID

xbmc should be able to play the youtube_url.

Check plugin.video.nlhardwareinfo\resources\lib\nlhardwareinfo_list_play.py as an example.

Good luck.

Thanks for the response. Again... I am a novice at coding so "you need to grab the youtubeID" is unclear to me. What code do I use to "grab" it?

Also you are explaining how to do it from the episode page (http://www.armlook.com/episode/armenia-t...anons/3222) but that is several steps into the code right? First the code has to decode the JSON page to grab the episode URLs. Then from the episode URLs your suggestion may work.

From what I could find in the "nlhardwareinfo_list_play.py" file it seems the page being parsed for this addon is xml (http://nl.hardware.info/tv/rss-private/streaming) format, so I don't think it's going to help me decode the JSON page to get the episode urls to then get the youtube link for each episode url, to then play them.

The youtube link on that page is an embed link too which is different, I don't know how that affects the performance of the code but I tried entering it as such and it didn't work.

Sorry, wish I wasn't so helpless... really need help with putting this code together... in layman's terms.
Reply
#4
I've jammed together a first version of the addon: http://www.mediafire.com/download/22zbhh...rmlook.zip

I suggest checking it out and once it's clear to you how it works, adding stuff to it...
Reply
#5
(2014-11-22, 07:19)Skipmode A1 Wrote: I've jammed together a first version of the addon: http://www.mediafire.com/download/22zbhh...rmlook.zip

I suggest checking it out and once it's clear to you how it works, adding stuff to it...

Thank you soooooooooooooo much. This works awesome. I'll start going through it and see if I can figure out how it works. Ultimately I'd like to find a way to just make an "Armenian TV" app that would have all the shows from the networks that are posted on this site and then maybe a few live feeds as well. Thanks again, you're my hero! Smile
Reply
#6
(2014-11-22, 07:19)Skipmode A1 Wrote: I've jammed together a first version of the addon: http://www.mediafire.com/download/22zbhh...rmlook.zip

I suggest checking it out and once it's clear to you how it works, adding stuff to it...

Hi there, I've been enjoying this addon thanks to you. I know it's a rough draft but it seems to work great. The only problem I'm experiencing is that usually the latest video will not be available until the day after it's available on the armlook site. I think that's because Armlook uses different sources for their videos. I am noticing that their videos can come from vimeo and rutube also. Then it seems like within 24hrs of it being posted to one of those two it ends up on youtube and is then available on the addon. Is there a relatively painless way to tell the addon to also look for links to vimeo and rutube as well as youtube and then display whatever it finds first?

Looks like "armlook_play.py" would be the place to add the code, but I am at a loss as to how to write it because vimeo / rutube are so different than youtube.
Reply
#7
I've added vimeo to the plugin: http://www.mediafire.com/download/1kadrj..._0.0.2.zip

I suggest checking it out...
Reply
#8
UPDATE: Just found that someone has made an addon for all videos on armlook.com which is working perfect. Download from the below link.

https://github.com/maridansoft/kodi_armlook
Reply

Logout Mark Read Team Forum Stats Members Help
need help with json decoder to parse youtube url0