2014-11-15, 00:44
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:
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.
Can anyone help me?
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()