2011-09-28, 21:07
Hello!
I am trying to develop a small add-on (that will play content from tv3play.se) for my xbmc and I have 2 problems.
The first is that the actual "video-link" "looks" like directory, but this is maybe not the main problem.
The main problem is that xbmc do not want to play movie.
Could someone please check out this code, you guys maybe see the problem like in 3 sec.
Url to pastebin - http://pastebin.com/KjH4gX7Y
Thank you for your help in advance!
I am trying to develop a small add-on (that will play content from tv3play.se) for my xbmc and I have 2 problems.
The first is that the actual "video-link" "looks" like directory, but this is maybe not the main problem.
The main problem is that xbmc do not want to play movie.
Could someone please check out this code, you guys maybe see the problem like in 3 sec.
Url to pastebin - http://pastebin.com/KjH4gX7Y
PHP Code:
# -*- coding: utf-8 -*-
import urllib
import urllib2
import re
import sys
import os
import time
''' XBMC '''
import xbmc
import xbmcgui
import xbmcplugin
base_url = 'http://www.tv3play.se'
def _decode_html_entities(string):
return string.replace('&', '&')
def get_data(url):
r = urllib2.Request(url)
r.add_header = [('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3')]
response = urllib2.urlopen(r)
data = response.read()
return data
def get_params():
param = []
params = sys.argv[2]
if len(params) >= 2:
params = params[0:len(params)-2]
pairs = params.replace('?','').split('&')
param = {}
for i in range(len(pairs)):
split = pairs[i].split('=')
if (len(split)) == 2:
param[split[0]] = split[1]
return param
def start():
add_list_item(_decode_html_entities('Program A-Ö'), base_url + '/program', 'program-a-o');
return
def get(name, url):
''' Get data from page '''
data = get_data(url)
if name == 'program-a-o':
programs = re.compile('<li><a href="(/program/[^<]+)">([^<]+)</a></li>').findall(data, re.DOTALL)
for program_url, title in programs:
add_list_item(_decode_html_entities(title), base_url + program_url, 'episodes')
if name == 'episodes':
episodes = re.compile('<a href="([^"]+)" >([^<]+)</a>\W+</th>\W+<td class="col2">([^<]+)</td>').findall(data, re.DOTALL)
for program_url, title, episode in episodes:
if program_url[0:7] != "http://":
title = title.strip() + ' (Episod: ' + episode + ')'
add_list_item(_decode_html_entities(title), base_url + program_url, 'play', '', False)
def play(name, url):
data = get_data(url)
id = url.replace('http://www.tv3play.se/play/', '').replace('/', '')
id = str(id)
video_params = '&autostart=true&affiliate=2se&country=se&id=' + id + '&theVolume=100&playerVersion=normal'
video_link = re.compile('embedSWF\("([^"]+)"').findall(data, re.DOTALL)[0]
video_link = video_link + video_params
video_link = video_link.replace('tv/flvplayer/play/', 'tv/play/')
item = xbmcgui.ListItem(name, iconImage = '', thumbnailImage = '')
item.setInfo(type = 'Video', infoLabels = {'Title' : name})
xbmc.Player().play(video_link, item)
def add_list_item(name, url, mode, icon = '', is_folder = True):
u = sys.argv[0] + '?url=' + urllib.quote_plus(url) + '&mode=' + urllib.quote_plus(mode) + '&name=' + urllib.quote_plus(name)
list_item = xbmcgui.ListItem(name, iconImage = '', thumbnailImage = icon)
list_item.setInfo(type = 'Video', infoLabels = {'Title' : name})
return xbmcplugin.addDirectoryItem(handle = int(sys.argv[1]), url = u, listitem = list_item, isFolder = is_folder)
''' Setting params '''
params = get_params()
url = None
name = None
mode = None
try:
url = urllib.unquote_plus(params["url"])
except:
pass
try:
name = urllib.unquote_plus(params["name"])
except:
pass
try:
mode = urllib.unquote_plus(params["mode"])
except:
pass
''' Checking mode '''
if mode == None or url == None or len(url) < 1:
start()
xbmcplugin.endOfDirectory(int(sys.argv[1]))
if mode == 'program-a-o':
get('program-a-o', url)
xbmcplugin.endOfDirectory(int(sys.argv[1]))
if mode == 'episodes':
get('episodes', url)
xbmcplugin.endOfDirectory(int(sys.argv[1]))
if mode == 'play':
play(name, url)
Thank you for your help in advance!