Can someone plass help is to make an xbmc plugin from this Python ? thanks in advance !!!
Direct link is : http://pastebin.com/gqdYaX5D
import urllib,urllib2,re,os
import xbmcplugin,xbmcgui,xbmcaddon
__settings__ = xbmcaddon.Addon(id='plugin.video.mbc')
home = __settings__.getAddonInfo('path')
icon = xbmc.translatePath( os.path.join( home, 'icon.png' ) )
fanart = xbmc.translatePath( os.path.join( home, 'fanart.jpg' ) )
def CATEGORIES():
addDir('MBC','http://shahid.mbc.net/Media/channel/1',1,'http://upload.wikimedia.org/wikipedia/en/a/ae/Mbc1logo.jpg')
addDir('MBC DRAMA','http://shahid.mbc.net/Media/channel/4',1,'http://video.frolh.com/videoimg/mbc_Drama.jpg')
addDir('MBC3','http://shahid.mbc.net/Media/channel/3',1,'http://www.mbc3.info/mbc3.jpg')
addDir('MBC4','http://shahid.mbc.net/Media/channel/2',1,'http://www.liga01.de/CMSFiles/MBC_4_KAMERA_0579/MBC_4_KAMERA_0579__720x576.175.jpg')
addDir('MBC Action','http://shahid.mbc.net/Media/channel/5',1,'http://en.kingofsat.net/jpg/mbc-action.jpg')
addDir('AlARABIA','http://shahid.mbc.net/Media/channel/6',1,'http://www.actforaustralia.com/sites/default/files/alarabiya%20logo.jpg')
def INDEX(url,page):
req = urllib2.Request(url)
req.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')
data=urllib2.urlopen(req).read()
match=re.compile('href="(.+?)" title=""><b><img src="(.+?)" width="" height="" border="0" alt="" /></b><span class=".+?">(.+?)</span>').findall(link)
for url,thumbnail,name in match:
addDir(name,url,2,thumbnail)
def INDEX2(url,page): # here you need to add the page param, the first call page would == 1
req = urllib2.Request(url)
req.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')
data = urllib2.urlopen(req).read()
match=re.compile('</span><a href="(.+?)" title=""><b><img src="(.+?)" alt="" border="0" height="" width="" /><span class="video"></span><span class="duration">(.+?)</span></b><span class="title major"> </span><span class="title">(.+?)</span>').findall(data)
for url,thumbnail,name,duration in match:
addDir(name+' - '+duration,url,3,thumbnail)
if
add_page = page + 1
num_per_page = 10
offset = (page -1) * num_per_page
channel_id = 1 # from the source you posted
sort = # you'll need to find this variable
ajax_url = '/Ajax'
ajax_url += '/' + 'series_sort'
ajax_url += '?offset=' + str(offset)
ajax_url += '&channel_id=' + str(channel_id)
ajax_url += '&sort=' + sort
ajax_url += '&limit=' + str(num_per_page)
# here mode is the mode used to call INDEX2, then pass add_page as the page param
addDir('Next Page', 'http://
?'+ajax_url, mode, thumbnail, add_page)## To pass the page param you'll have to change def addDir()
def addDir(name,url,mode,iconimage,page):
# now add the page param to u
u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)+"&page="+str(page)
## add the check for page param
try:
url=urllib.unquote_plus(params["url"])
except:
pass
try:
name=urllib.unquote_plus(params["name"])
except:
pass
try:
page=int(params["page"]) # we use int here because we want a number instead of a string
except:
pass
def VIDEOLINKS(url,name):
req = urllib2.Request(url)
req.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(req)
link=response.read()
response.close()
match=re.compile('<embed src="(.+?)" name="(.+?)" wmode="(.+?)" width="705" height="449" allowScriptAccess="(.+?)" allowFullScreen="(.+?)" type="(.+?)" pluginspage=".+?" flashvars="(.+?)"></embed>').findall(link)
for url in match:
addLink(name,url,'')
def get_params():
param=[]
paramstring=sys.argv[2]
if len(paramstring)>=2:
params=sys.argv[2]
cleanedparams=params.replace('?','')
if (params[len(params)-1]=='/'):
params=params[0:len(params)-2]
pairsofparams=cleanedparams.split('&')
param={}
for i in range(len(pairsofparams)):
splitparams={}
splitparams=pairsofparams[i].split('=')
if (len(splitparams))==2:
param[splitparams[0]]=splitparams[1]
return param
def addLink(name,url,iconimage):
ok=True
liz=xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage=iconimage)
liz.setInfo( type="Video", infoLabels={ "Title": name } )
ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,listitem=liz)
return ok
def addDir(name,url,mode,iconimage):
u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)
ok=True
liz=xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=iconimage)
liz.setInfo( type="Video", infoLabels={ "Title": name } )
ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=True)
return ok
params=get_params()
url=None
name=None
mode=None
page=None
try:
url=urllib.unquote_plus(params["url"])
except:
pass
try:
name=urllib.unquote_plus(params["name"])
except:
pass
try:
mode=int(params["mode"])
except:
pass
print "Mode: "+str(mode)
print "URL: "+str(url)
print "Name: "+str(name)
print " "+str(page) # i don't know what have to do here.
if mode==None or url==None or len(url)<1:
print ""
CATEGORIES()
elif mode==1:
print ""+url
INDEX(url,page)
elif mode==2:
print ""+url
VIDEOLINKS(url,name)
xbmcplugin.endOfDirectory(int(sys.argv[1]))
create a new version of this paste RAW Paste Data

Search
Help