Advertisement
Guest User

Untitled

a guest
Mar 2nd, 2012
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.12 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3. import urllib
  4. import urllib2
  5. import re
  6. import os
  7. import xbmcplugin
  8. import xbmcgui
  9. import xbmcaddon
  10. import xbmcvfs
  11. from BeautifulSoup import BeautifulStoneSoup, BeautifulSoup, BeautifulSOAP
  12. try:
  13. import json
  14. except:
  15. import simplejson as json
  16.  
  17. # external libs
  18. import utils, httplib2, socks, httplib, logging, time
  19.  
  20. addon = xbmcaddon.Addon('plugin.video.LiveTV')
  21. profile = xbmc.translatePath(addon.getAddonInfo('profile'))
  22. __settings__ = xbmcaddon.Addon(id='plugin.video.LiveTV')
  23. home = __settings__.getAddonInfo('path')
  24. favorites = xbmc.translatePath( os.path.join( profile, 'favorites' ) )
  25. REV = xbmc.translatePath( os.path.join( profile, 'list_revision') )
  26. icon = xbmc.translatePath( os.path.join( home, 'icon.png' ) )
  27. fanart = xbmc.translatePath( os.path.join( home, 'fanart.jpg' ) )
  28. source_file = xbmc.translatePath( os.path.join( profile, 'source_file') )
  29. if os.path.exists(favorites)==True:
  30. FAV = open(favorites).read()
  31. if os.path.exists(source_file)==True:
  32. SOURCES = open(source_file).read()
  33.  
  34. # setup cache dir
  35. __scriptname__ = 'LiveTV'
  36. __scriptid__ = "plugin.video.LiveTV"
  37. __addoninfo__ = utils.get_addoninfo(__scriptid__)
  38. __addon__ = __addoninfo__["addon"]
  39. __settings__ = xbmcaddon.Addon(id=__scriptid__)
  40.  
  41.  
  42. DIR_CACHE = xbmc.translatePath(os.path.join( "T:"+os.sep,"plugin_data", __scriptname__,'cache' ))
  43. if not os.path.isdir(DIR_CACHE):
  44. try:
  45. os.makedirs(DIR_CACHE)
  46. except:
  47. DIR_CACHE = os.path.join(os.getcwd(),'cache')
  48. os.makedirs(DIR_CACHE)
  49.  
  50. DIR_USERDATA = xbmc.translatePath(__addoninfo__["profile"])
  51. SUBTITLES_DIR = os.path.join(DIR_USERDATA, 'Subtitles')
  52. IMAGE_DIR = os.path.join(DIR_USERDATA, 'Images')
  53.  
  54. if not os.path.isdir(DIR_USERDATA):
  55. os.makedirs(DIR_USERDATA)
  56. if not os.path.isdir(SUBTITLES_DIR):
  57. os.makedirs(SUBTITLES_DIR)
  58. if not os.path.isdir(IMAGE_DIR):
  59. os.makedirs(IMAGE_DIR)
  60.  
  61. def get_proxy():
  62. proxy_server = None
  63. proxy_type_id = 0
  64. proxy_port = 8080
  65. proxy_user = None
  66. proxy_pass = None
  67. try:
  68. proxy_server = __settings__.getSetting('proxy_server')
  69. proxy_type_id = __settings__.getSetting('proxy_type')
  70. proxy_port = int(__settings__.getSetting('proxy_port'))
  71. proxy_user = __settings__.getSetting('proxy_user')
  72. proxy_pass = __settings__.getSetting('proxy_pass')
  73. except:
  74. pass
  75.  
  76. if proxy_type_id == '0': proxy_type = socks.PROXY_TYPE_HTTP_NO_TUNNEL
  77. elif proxy_type_id == '1': proxy_type = socks.PROXY_TYPE_HTTP
  78. elif proxy_type_id == '2': proxy_type = socks.PROXY_TYPE_SOCKS4
  79. elif proxy_type_id == '3': proxy_type = socks.PROXY_TYPE_SOCKS5
  80.  
  81. proxy_dns = True
  82.  
  83. return (proxy_type, proxy_server, proxy_port, proxy_dns, proxy_user, proxy_pass)
  84.  
  85. def get_httplib():
  86. http = None
  87. try:
  88. if __settings__.getSetting('proxy_use') == 'true':
  89. (proxy_type, proxy_server, proxy_port, proxy_dns, proxy_user, proxy_pass) = get_proxy()
  90. logging.info("Using proxy: type %i rdns: %i server: %s port: %s user: %s pass: %s", proxy_type, proxy_dns, proxy_server, proxy_port, "***", "***")
  91. http = httplib2.Http(proxy_info = httplib2.ProxyInfo(proxy_type, proxy_server, proxy_port, proxy_dns, proxy_user, proxy_pass))
  92. else:
  93. logging.info("No Proxy\n")
  94. http = httplib2.Http()
  95. except:
  96. raise
  97. logging.error('Failed to initialize httplib2 module')
  98.  
  99. return http
  100.  
  101. http = get_httplib()
  102.  
  103.  
  104. http.cache = httplib2.FileCache(DIR_CACHE, safe=lambda x: md5.new(x).hexdigest())
  105.  
  106. # what OS?
  107. environment = os.environ.get( "OS", "xbox" )
  108.  
  109. def getSources():
  110. if os.path.exists(favorites)==True:
  111. addDir('Favorites','url',4,xbmc.translatePath(os.path.join(home, 'resources', 'favorite.png')),fanart,'','','',False)
  112. if os.path.exists(source_file)==False:
  113. xbmc.executebuiltin("XBMC.Notification(LiveTV,Choose type source and then select Add Source.,15000,"+icon+")")
  114. __settings__.openSettings()
  115. return
  116. sources = json.loads(open(source_file,"r").read())
  117. if len(sources) > 1:
  118. for i in sources:
  119. addDir(i[0],i[1],1,icon,fanart,'','','')
  120. else:
  121. getData(sources[0][1],fanart)
  122.  
  123.  
  124. def addSource(url=None):
  125. if url is None:
  126. if not __settings__.getSetting("new_file_source") == "":
  127. source = __settings__.getSetting('new_file_source')
  128. if not __settings__.getSetting("new_url_source") == "":
  129. source = __settings__.getSetting('new_url_source')
  130. else:
  131. source = url
  132. if source == '' or source is None:
  133. return
  134. if '/' in source:
  135. nameStr = source.split('/')[-1].split('.')[0]
  136. if '\\' in source:
  137. nameStr = source.split('\\')[-1].split('.')[0]
  138. if '%' in nameStr:
  139. nameStr = urllib.unquote_plus(nameStr)
  140. keyboard = xbmc.Keyboard(nameStr,'Displayed Name, Rename?')
  141. keyboard.doModal()
  142. if (keyboard.isConfirmed() == False):
  143. return
  144. newStr = keyboard.getText()
  145. if len(newStr) == 0:
  146. return
  147. source_list = []
  148. source = (newStr, source)
  149. if os.path.exists(source_file)==False:
  150. source_list.append(source)
  151. b = open(source_file,"w")
  152. b.write(json.dumps(source_list))
  153. b.close()
  154. else:
  155. sources = json.loads(open(source_file,"r").read())
  156. sources.append(source)
  157. b = open(source_file,"w")
  158. b.write(json.dumps(sources))
  159. b.close()
  160. __settings__.setSetting('new_url_source', "")
  161. __settings__.setSetting('new_file_source', "")
  162. xbmc.executebuiltin("XBMC.Notification(LiveTV,New source added.,5000,"+icon+")")
  163.  
  164. def rmSource(name):
  165. sources = json.loads(open(source_file,"r").read())
  166. for index in range(len(sources)):
  167. try:
  168. if sources[index][0] == name:
  169. del sources[index]
  170. b = open(source_file,"w")
  171. b.write(json.dumps(sources))
  172. b.close()
  173. except:
  174. pass
  175.  
  176.  
  177. def getCommunitySources():
  178. req = urllib2.Request('http://live-tv-stream.googlecode.com/svn/trunk/')
  179. response = urllib2.urlopen(req)
  180. link=response.read()
  181. response.close()
  182. soup = BeautifulSoup(link, convertEntities=BeautifulSoup.HTML_ENTITIES)
  183. files = soup('ul')[0]('li')[1:]
  184. for i in files:
  185. name = i('a')[0]['href']
  186. url = 'http://live-tv-stream.googlecode.com/svn/trunk/'+name
  187. addDir(name,url,11,icon,fanart,'','','',False)
  188.  
  189.  
  190. def getUpdate():
  191. req = urllib2.Request('http://live-tv-stream.googlecode.com/svn/trunk/')
  192. response = urllib2.urlopen(req)
  193. link1=response.read()
  194. response.close()
  195. soup = BeautifulSoup(link1, convertEntities=BeautifulSoup.HTML_ENTITIES)
  196. files = soup('ul')[0]('li')[1:]
  197. try:
  198. R = open(REV,"w")
  199. R.write(link1)
  200. R.close()
  201. except:
  202. print "there was a problem writing REV to profile."
  203. for i in files:
  204. name = i('a')[0]['href']
  205. url = 'http://live-tv-stream.googlecode.com/svn/trunk/'+name
  206. req = urllib2.Request(url)
  207. response = urllib2.urlopen(req)
  208. link=response.read()
  209. response.close()
  210. if not xbmcvfs.exists(__settings__.getSetting('save_location')):
  211. success = xbmcvfs.mkdir(__settings__.getSetting('save_location'))
  212. save_location = __settings__.getSetting('save_location')
  213. if 'smb:' in save_location:
  214. file_name = xbmc.makeLegalFilename(os.path.join( profile, 'temp', name))
  215. f = open(os.path.join( profile, 'temp', name),"w")
  216. f.write(link)
  217. f.close()
  218. copy = xbmcvfs.copy(os.path.join( profile, 'temp', name), os.path.join( save_location, name))
  219. if copy:
  220. xbmcvfs.delete( xbmc.translatePath(os.path.join( profile, 'temp', name)))
  221. else:
  222. print '------ Error smb: makeLegalFilename -----'
  223. else:
  224. try:
  225. file_name = xbmc.makeLegalFilename(os.path.join(save_location, name))
  226. f = open(os.path.join(save_location, name),"w")
  227. f.write(link)
  228. f.close()
  229. except:
  230. print "there was a problem writing to save location."
  231. return
  232. xbmc.executebuiltin("XBMC.Notification(LiveTV,LiveTV Updated,5000,"+icon+")")
  233.  
  234.  
  235. def checkForUpdate():
  236. url = 'http://live-tv-stream.googlecode.com/svn/trunk/'
  237. req = urllib2.Request(url)
  238. response = urllib2.urlopen(req)
  239. link=response.read()
  240. response.close()
  241. revision = re.compile('<html><head><title>(.+?)/trunk</title></head>').findall(link)[0]
  242. try:
  243. R = open(REV,"r")
  244. rev = R.read()
  245. R.close()
  246. revision_check = re.compile('<html><head><title>(.+?)/trunk</title></head>').findall(rev)[0]
  247. if revision_check != revision:
  248. getUpdate()
  249. except:
  250. print "----- Error: revision_check ------ getUpdate"
  251. getUpdate()
  252.  
  253.  
  254. if __settings__.getSetting('LiveTV') == "true":
  255. if __settings__.getSetting('save_location') == "":
  256. xbmc.executebuiltin("XBMC.Notification('LiveTV','Choose a location to save files and select OK to save.',15000,"+icon+")")
  257. __settings__.openSettings()
  258. else:
  259. try:
  260. checkForUpdate()
  261. except urllib2.URLError, e:
  262. errorStr = str(e.read())
  263. if hasattr(e, 'reason'):
  264. print 'We failed to reach a server.'
  265. print 'Reason: ', e.reason
  266. if hasattr(e, 'code'):
  267. print 'We failed with error code - %s.' % e.code
  268.  
  269.  
  270. def getSoup(url):
  271. print 'getSoup(): '+url
  272. if url.startswith('http://'):
  273. try:
  274. req = urllib2.Request(url)
  275. response = urllib2.urlopen(req)
  276. data = response.read()
  277. response.close()
  278. except urllib2.URLError, e:
  279. # errorStr = str(e.read())
  280. if hasattr(e, 'code'):
  281. print 'We failed with error code - %s.' % e.code
  282. xbmc.executebuiltin("XBMC.Notification(LiveTV,We failed with error code - "+str(e.code)+",10000,"+icon+")")
  283. elif hasattr(e, 'reason'):
  284. print 'We failed to reach a server.'
  285. print 'Reason: ', e.reason
  286. xbmc.executebuiltin("XBMC.Notification(LiveTV,We failed to reach a server. - "+str(e.reason)+",10000,"+icon+")")
  287. else:
  288. if xbmcvfs.exists(url):
  289. if url.startswith("smb://"):
  290. copy = xbmcvfs.copy( url, xbmc.translatePath(os.path.join(profile, 'temp', 'sorce_temp.txt')))
  291. if copy:
  292. data = open( xbmc.translatePath(os.path.join(profile, 'temp', 'sorce_temp.txt')), "r").read()
  293. xbmcvfs.delete( xbmc.translatePath(os.path.join(profile, 'temp', 'sorce_temp.txt')) )
  294. else:
  295. print "--- failed to copy from smb: ----"
  296. else:
  297. data = open(url, 'r').read()
  298. else:
  299. print "---- Soup Data not found! ----"
  300. return
  301. soup = BeautifulSOAP(data, convertEntities=BeautifulStoneSoup.XML_ENTITIES)
  302. return soup
  303.  
  304.  
  305. def getData(url,fanart):
  306. soup = getSoup(url)
  307. if len(soup('channels')) > 0:
  308. channels = soup('channel')
  309. for channel in channels:
  310. name = channel('name')[0].string
  311. thumbnail = channel('thumbnail')[0].string
  312. if thumbnail == None:
  313. thumbnail = ''
  314.  
  315. try:
  316. if not channel('fanart'):
  317. if __settings__.getSetting('use_thumb') == "true":
  318. fanArt = thumbnail
  319. else:
  320. fanArt = fanart
  321. else:
  322. fanArt = channel('fanart')[0].string
  323. if fanArt == None:
  324. raise
  325. except:
  326. fanArt = fanart
  327.  
  328. try:
  329. desc = channel('info')[0].string
  330. if desc == None:
  331. raise
  332. except:
  333. desc = ''
  334.  
  335. try:
  336. genre = channel('genre')[0].string
  337. if genre == None:
  338. raise
  339. except:
  340. genre = ''
  341.  
  342. try:
  343. date = channel('date')[0].string
  344. if date == None:
  345. raise
  346. except:
  347. date = ''
  348. try:
  349. addDir(name.encode('utf-8', 'ignore'),url,2,thumbnail,fanArt,desc,genre,date)
  350. except:
  351. print 'There was a problem adding directory from getData(): '+name.encode('utf-8', 'ignore')
  352. else:
  353. getItems(soup('item'),fanart)
  354.  
  355.  
  356. def getChannelItems(name,url,fanart):
  357. soup = getSoup(url)
  358. channel_list = soup.find('channel', attrs={'name' : name})
  359. items = channel_list('item')
  360. try:
  361. fanArt = channel_list('fanart')[0].string
  362. if fanArt == None:
  363. raise
  364. except:
  365. fanArt = fanart
  366. for channel in channel_list('subchannel'):
  367. name = channel('name')[0].string
  368. try:
  369. thumbnail = channel('thumbnail')[0].string
  370. if thumbnail == None:
  371. raise
  372. except:
  373. thumbnail = ''
  374. try:
  375. if not channel('fanart'):
  376. if __settings__.getSetting('use_thumb') == "true":
  377. fanArt = thumbnail
  378. else:
  379. fanArt = channel('fanart')[0].string
  380. if fanArt == None:
  381. raise
  382. except:
  383. pass
  384. try:
  385. desc = channel('info')[0].string
  386. if desc == None:
  387. raise
  388. except:
  389. desc = ''
  390.  
  391. try:
  392. genre = channel('genre')[0].string
  393. if genre == None:
  394. raise
  395. except:
  396. genre = ''
  397.  
  398. try:
  399. date = channel('date')[0].string
  400. if date == None:
  401. raise
  402. except:
  403. date = ''
  404. try:
  405. addDir(name.encode('utf-8', 'ignore'),url,3,thumbnail,fanArt,desc,genre,date)
  406. except:
  407. print 'There was a problem adding directory - '+name.encode('utf-8', 'ignore')
  408. print fanArt
  409. getItems(items,fanArt)
  410.  
  411.  
  412. def getSubChannelItems(name,url,fanart):
  413. soup = getSoup(url)
  414. channel_list = soup.find('subchannel', attrs={'name' : name})
  415. items = channel_list('subitem')
  416. getItems(items,fanart)
  417.  
  418.  
  419. def getItems(items,fanart):
  420. for item in items:
  421. try:
  422. name = item('title')[0].string
  423. except:
  424. print '-----Name Error----'
  425. name = ''
  426. try:
  427. if item('uk'):
  428. if item('uk')[0].string > 1:
  429. name += getuk(item('uk')[0].string)
  430. except:
  431. print '----- EPG Error ----'
  432. try:
  433. if item('usa'):
  434. if item('usa')[0].string > 1:
  435. name += getusa(item('usa')[0].string)
  436. else:
  437. pass
  438. except:
  439. print '----- EPG Error ----'
  440.  
  441. try:
  442. if __settings__.getSetting('mirror_link') == "true":
  443. try:
  444. url = item('link')[1].string
  445. except:
  446. url = item('link')[0].string
  447. if __settings__.getSetting('mirror_link_low') == "true":
  448. try:
  449. url = item('link')[2].string
  450. except:
  451. try:
  452. url = item('link')[1].string
  453. except:
  454. url = item('link')[0].string
  455. else:
  456. url = item('link')[0].string
  457. except:
  458. print '---- URL Error Passing ----'+name
  459. pass
  460.  
  461. try:
  462. thumbnail = item('thumbnail')[0].string
  463. if thumbnail == None:
  464. raise
  465. except:
  466. thumbnail = ''
  467. try:
  468. if not item('fanart'):
  469. if __settings__.getSetting('use_thumb') == "true":
  470. fanArt = thumbnail
  471. else:
  472. fanArt = fanart
  473. else:
  474. fanArt = item('fanart')[0].string
  475. if fanArt == None:
  476. raise
  477. except:
  478. fanArt = fanart
  479. try:
  480. desc = getuk2(item('uk2')[0].string)
  481. if desc == None:
  482. raise
  483. except:
  484. try:
  485. desc = getusa2(item('usa2')[0].string)
  486. if desc == None:
  487. raise
  488. except:
  489. desc = ''
  490.  
  491. try:
  492. genre = item('genre')[0].string
  493. if genre == None:
  494. raise
  495. except:
  496. genre = ''
  497.  
  498. try:
  499. date = item('date')[0].string
  500. if date == None:
  501. raise
  502. except:
  503. date = ''
  504. try:
  505. addLink(url,name.encode('utf-8', 'ignore'),thumbnail,fanArt,desc,genre,date,True)
  506. except:
  507. print 'There was a problem adding link - '+name.encode('utf-8', 'ignore')
  508.  
  509.  
  510. def get_params():
  511. param=[]
  512. paramstring=sys.argv[2]
  513. if len(paramstring)>=2:
  514. params=sys.argv[2]
  515. cleanedparams=params.replace('?','')
  516. if (params[len(params)-1]=='/'):
  517. params=params[0:len(params)-2]
  518. pairsofparams=cleanedparams.split('&')
  519. param={}
  520. for i in range(len(pairsofparams)):
  521. splitparams={}
  522. splitparams=pairsofparams[i].split('=')
  523. if (len(splitparams))==2:
  524. param[splitparams[0]]=splitparams[1]
  525. return param
  526.  
  527.  
  528. def getFavorites():
  529. for i in json.loads(open(favorites).read()):
  530. name = i[0]
  531. url = i[1]
  532. iconimage = i[2]
  533. try:
  534. fanArt = i[3]
  535. if fanArt == None:
  536. raise
  537. except:
  538. if __settings__.getSetting('use_thumb') == "true":
  539. fanArt = iconimage
  540. else:
  541. fanArt = fanart
  542. addLink(url,name,iconimage,fanArt,'','','')
  543.  
  544.  
  545. def addFavorite(name,url,iconimage,fanart):
  546. favList = []
  547. if os.path.exists(favorites)==False:
  548. print 'Making Favorites File'
  549. favList.append((name,url,iconimage,fanart))
  550. a = open(favorites, "w")
  551. a.write(json.dumps(favList))
  552. a.close()
  553. else:
  554. print 'Appending Favorites'
  555. a = open(favorites).read()
  556. data = json.loads(a)
  557. data.append((name,url,iconimage,fanart))
  558. b = open(favorites, "w")
  559. b.write(json.dumps(data))
  560. b.close()
  561.  
  562.  
  563. def rmFavorite(name):
  564. print 'Remove Favorite'
  565. a = open(favorites).read()
  566. data = json.loads(a)
  567. for index in range(len(data)):
  568. try:
  569. if data[index][0]==name:
  570. del data[index]
  571. b = open(favorites, "w")
  572. b.write(json.dumps(data))
  573. b.close()
  574. except:
  575. pass
  576.  
  577.  
  578. def addDir(name,url,mode,iconimage,fanart,description,genre,date,showcontext=True):
  579. u=sys.argv[0]+"?url="+urllib.quote_plus(url)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)+"&fanart="+urllib.quote_plus(fanart)
  580. ok=True
  581. liz=xbmcgui.ListItem(name, iconImage="DefaultFolder.png", thumbnailImage=iconimage)
  582. liz.setInfo( type="Video", infoLabels={ "Title": name, "Plot": description, "Genre": genre, "Date": date } )
  583. liz.setProperty( "Fanart_Image", fanart )
  584. if showcontext == True:
  585. try:
  586. if name in str(SOURCES):
  587. contextMenu = [('Remove from Sources','XBMC.Container.Update(%s?mode=8&name=%s)' %(sys.argv[0], urllib.quote_plus(name)))]
  588. liz.addContextMenuItems(contextMenu, True)
  589. except:
  590. pass
  591. ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=True)
  592. return ok
  593.  
  594.  
  595. def addLink(url,name,iconimage,fanart,description,genre,date,showcontext=True):
  596. ok=True
  597. liz=xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage=iconimage)
  598. liz.setInfo( type="Video", infoLabels={ "Title": name, "Plot": description, "Genre": genre, "Date": date } )
  599. liz.setProperty( "Fanart_Image", fanart )
  600. if showcontext:
  601. try:
  602. if name in FAV:
  603. contextMenu = [('Remove from LiveTV Favorites','XBMC.Container.Update(%s?mode=6&name=%s)' %(sys.argv[0], urllib.quote_plus(name)))]
  604. else:
  605. contextMenu = [('Add to LiveTV Favorites','XBMC.Container.Update(%s?mode=5&name=%s&url=%s&iconimage=%s&fanart=%s)' %(sys.argv[0], urllib.quote_plus(name), urllib.quote_plus(url), urllib.quote_plus(iconimage), urllib.quote_plus(fanart)))]
  606. except:
  607. contextMenu = [('Add to LiveTV Favorites','XBMC.Container.Update(%s?mode=5&name=%s&url=%s&iconimage=%s&fanart=%s)' %(sys.argv[0], urllib.quote_plus(name), urllib.quote_plus(url), urllib.quote_plus(iconimage), urllib.quote_plus(fanart)))]
  608. liz.addContextMenuItems(contextMenu)
  609. ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,listitem=liz)
  610. return ok
  611.  
  612.  
  613. # Thanks to mikey1234, epg scraper for uk and usa
  614. def getuk2(link):
  615. req = urllib2.Request('http://www.locatetv.com/uk/listings/'+link)
  616. 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')
  617. response = urllib2.urlopen(req)
  618. link=response.read()
  619. response.close()
  620. match=re.compile('<a class="pickable" href="/tv/(.+?)/(.+?)</a><p>(.+?)</p></div></li>').findall(link)
  621. nowtitle = match[0][0]
  622. nowdesc = match [0][2]
  623. nexttitle = match[1][0]
  624. nextdesc = match [1][2]
  625. nowtitle = nowtitle.replace("-"," ")
  626. nowtitle = re.sub("\">.+?<", "", nowtitle)
  627. nexttitle = nexttitle.replace("-"," ")
  628. nexttitle = re.sub("\">.+?<", "", nexttitle)
  629. nowdesc = nowdesc.replace("&#039;","")
  630. nextdesc = nextdesc.replace("&#039;","")
  631. return "[B][NOW]%s[/B]\n%s\n\n[B][NEXT] - %s[/B]\n%s" %(nowtitle, nowdesc, nexttitle, nextdesc)
  632.  
  633. def getuk(link):
  634. req = urllib2.Request('http://www.locatetv.com/uk/listings/'+link)
  635. 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')
  636. response = urllib2.urlopen(req)
  637. link=response.read()
  638. response.close()
  639. match=re.compile('<a class="pickable" href="/tv/(.+?)/(.+?)</a><p>(.+?)</p></div></li>').findall(link)
  640. nowtitle = match[0][0]
  641. nowtitle = nowtitle.replace("-"," ")
  642. nowtitle = re.sub("\">.+?<", "", nowtitle)
  643. return " - %s" %(nowtitle)
  644.  
  645. def getusa2(link):
  646. req = urllib2.Request('http://www.locatetv.com/listings/'+link)
  647. 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')
  648. response = urllib2.urlopen(req)
  649. link=response.read()
  650. response.close()
  651. match=re.compile('<a class="pickable" href="/tv/(.+?)/(.+?)</a><p>(.+?)</p></div></li>').findall(link)
  652. nowtitle = match[0][0]
  653. nowdesc = match [0][2]
  654. nexttitle = match[1][0]
  655. nextdesc = match [1][2]
  656. nowtitle = nowtitle.replace("-"," ")
  657. nowtitle = re.sub("\">.+?<", "", nowtitle)
  658. nexttitle = nexttitle.replace("-"," ")
  659. nexttitle = re.sub("\">.+?<", "", nexttitle)
  660. nowdesc = nowdesc.replace("&#039;","")
  661. nextdesc = nextdesc.replace("&#039;","")
  662. return "[B][NOW]%s[/B]\n%s\n\n[B][NEXT] - %s[/B]\n%s" %(nowtitle, nowdesc, nexttitle, nextdesc)
  663.  
  664. def getusa(link):
  665. req = urllib2.Request('http://www.locatetv.com/listings/'+link)
  666. 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')
  667. response = urllib2.urlopen(req)
  668. link=response.read()
  669. response.close()
  670. match=re.compile('<a class="pickable" href="/tv/(.+?)/(.+?)</a><p>(.+?)</p></div></li>').findall(link)
  671. nowtitle = match[0][0]
  672. nowtitle = nowtitle.replace("-"," ")
  673. nowtitle = re.sub("\">.+?<", "", nowtitle)
  674. return " - %s" %(nowtitle)
  675.  
  676.  
  677.  
  678.  
  679. xbmcplugin.setContent(int(sys.argv[1]), 'movies')
  680. try:
  681. xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_UNSORTED)
  682. except:
  683. pass
  684. try:
  685. xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_LABEL)
  686. except:
  687. pass
  688. try:
  689. xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_DATE)
  690. except:
  691. pass
  692. try:
  693. xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_GENRE)
  694. except:
  695. pass
  696.  
  697. params=get_params()
  698.  
  699. url=None
  700. name=None
  701. mode=None
  702.  
  703. try:
  704. url=urllib.unquote_plus(params["url"])
  705. except:
  706. pass
  707. try:
  708. name=urllib.unquote_plus(params["name"])
  709. except:
  710. pass
  711. try:
  712. iconimage=urllib.unquote_plus(params["iconimage"])
  713. except:
  714. pass
  715. try:
  716. fanart=urllib.unquote_plus(params["fanart"])
  717. except:
  718. pass
  719. try:
  720. mode=int(params["mode"])
  721. except:
  722. pass
  723.  
  724. print "Mode: "+str(mode)
  725. print "URL: "+str(url)
  726. print "Name: "+str(name)
  727.  
  728. if mode==None:
  729. print "getSources"
  730. getSources()
  731.  
  732. elif mode==1:
  733. print "getData"
  734. getData(url,fanart)
  735.  
  736. elif mode==2:
  737. print "getChannelItems"
  738. getChannelItems(name,url,fanart)
  739.  
  740. elif mode==3:
  741. print ""
  742. getSubChannelItems(name,url,fanart)
  743.  
  744. elif mode==4:
  745. print ""
  746. getFavorites()
  747.  
  748. elif mode==5:
  749. print ""
  750. try:
  751. name = name.split('\\ ')[1]
  752. except:
  753. pass
  754. try:
  755. name = name.split(' - ')[0]
  756. except:
  757. pass
  758. addFavorite(name,url,iconimage,fanart)
  759.  
  760. elif mode==6:
  761. print ""
  762. try:
  763. name = name.split('\\ ')[1]
  764. except:
  765. pass
  766. try:
  767. name = name.split(' - ')[0]
  768. except:
  769. pass
  770. rmFavorite(name)
  771.  
  772. elif mode==7:
  773. print "addSource"
  774. addSource(url)
  775.  
  776. elif mode==8:
  777. print "rmSource"
  778. rmSource(name)
  779.  
  780. elif mode==9:
  781. print "getUpdate"
  782. getUpdate()
  783.  
  784. elif mode==10:
  785. print "getCommunitySources"
  786. getCommunitySources()
  787.  
  788. elif mode==11:
  789. print ""
  790. addSource(url)
  791.  
  792. elif mode==12:
  793. print ""
  794.  
  795.  
  796. xbmcplugin.endOfDirectory(int(sys.argv[1]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement