Advertisement
Guest User

Untitled

a guest
May 30th, 2013
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.69 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*
  3. import xbmcplugin
  4. import xbmc
  5. import xbmcgui
  6. import urllib
  7. import sys
  8. import re
  9. import os
  10. from BeautifulSoup import BeautifulStoneSoup
  11. import resources.lib._common as common
  12. import resources.lib.m3u8 as m3u8
  13. import base64
  14.  
  15. pluginHandle = int(sys.argv[1])
  16.  
  17. BRANDID = '001'
  18. PARTNERID = '585231'
  19. SITE = 'abc'
  20. SHOWLIST = 'http://abc.go.com/vp2/ws/s/contents/2012/shows/' + BRANDID + '/001/-1?rand=2.0.0000'
  21. VIDEOLIST = 'http://abc.go.com/vp2/ws/s/contents/2012/videos/' + BRANDID + '/001/'
  22.  
  23. def masterlist():
  24.     return rootlist(db=True)
  25.  
  26. def rootlist(db=False):
  27.     root_data = common.getURL(SHOWLIST)
  28.     root_tree = BeautifulStoneSoup(root_data, convertEntities=BeautifulStoneSoup.HTML_ENTITIES)
  29.     root_menu = root_tree.findAll('show')
  30.     db_shows = []
  31.     for root_item in root_menu:
  32.         root_name = root_item('title')[0].string
  33.         season_id = root_item['id']
  34.         if db == True:
  35.             db_shows.append(root_name, SITE,'seasons',season_id)
  36.         else:
  37.             common.addShow(root_name, SITE,'seasons',season_id)
  38.     if db == True:
  39.         return db_shows
  40.     else:
  41.         common.setView('tvshows')
  42.  
  43. def seasons(url=common.args.url):
  44.     show_id = url
  45.     show_url = VIDEOLIST + 'lf/' + show_id + '/-1/-1/-1/-1?rand=2.0.0000'
  46.     show_data = common.getURL(show_url)
  47.     show_menu = sorted(set(re.findall(r'<season id\=\"(.+?)\"',show_data)))
  48.     for show_item in show_menu:
  49.         show_name = 'Season ' + show_item
  50.         show_url = VIDEOLIST + 'lf/' + show_id + '/' + show_item + '/-1/-1/-1?rand=2.0.0000'
  51.         common.addDirectory(show_name, SITE, 'episodes', show_url)
  52.     clip_id = url
  53.     clip_url = VIDEOLIST + 'sf/' + show_id + '/-1/-1/-1/-1?rand=2.0.0000'
  54.     clip_data = common.getURL(clip_url)
  55.     clip_menu = sorted(set(re.findall(r'<season id\=\"(.+?)\"',clip_data)))
  56.     for clip_item in clip_menu:
  57.         clip_name = 'Clips Season ' + clip_item
  58.         clip_url = VIDEOLIST + 'sf/' + clip_id + '/' + clip_item + '/-1/-1/-1?rand=2.0.0000'
  59.         common.addDirectory(clip_name, SITE, 'episodes', clip_url)
  60.     common.setView('seasons')
  61.  
  62. def episodes(url=common.args.url):
  63.     episode_data = common.getURL(url)
  64.     episode_tree = BeautifulStoneSoup(episode_data, convertEntities=BeautifulStoneSoup.HTML_ENTITIES)
  65.     episode_menu = episode_tree.findAll('video')
  66.     for episode_item in episode_menu:
  67.         episode_name = episode_item('title')[1].string
  68.         try:
  69.             episode_thumb = episode_item('thumbnails')[1]('thumbnail')[1].string
  70.         except:
  71.             try:
  72.                 episode_thumb = episode_item('thumbnails')[1]('thumbnail')[0].string
  73.             except:
  74.                 episode_thumb = episode_item('thumbnail')[0].string
  75.         if (episode_item('asset')[0]['format'] == 'MOV'):
  76.             sitemode = 'playVideoMOV'
  77.         elif (episode_item('asset')[0]['format'] == 'MP4'):
  78.             sitemode = 'playVideoMP4'
  79.         else:
  80.             sitemode = 'playVideoUPL'
  81.         url = episode_item['id']
  82.         try:
  83.             description = episode_item('longdescription')[0].string
  84.         except:
  85.             description = episode_item('description')[0].string
  86.         episode_airDate = re.sub(r" P(.)T","",episode_item('airdate')[0].string)
  87.         episode_duration = int(episode_item('duration')[0].string)/60000
  88.         episode_number = episode_item('number')[0].string
  89.         season_number = episode_item('season')[0]['id']
  90.         u = sys.argv[0]
  91.         u += '?url="' + urllib.quote_plus(url) + '"'
  92.         u += '&mode="' + SITE + '"'
  93.         u += '&sitemode="' + sitemode + '"'
  94.         infoLabels={ "Title":episode_name,
  95.                      "Plot":description,
  96.                      "premiered":common.formatDate(episode_airDate,'%a, %d %b %Y %H:%M:%S','%d.%m.%Y'),
  97.                      "Duration":episode_duration,
  98.                      "Episode":episode_number,
  99.                      "Season":season_number
  100.                    }
  101.         common.addVideo(u,episode_name,episode_thumb,infoLabels=infoLabels)
  102.     common.setView('episodes')
  103.  
  104. def playVideoMOV(url=common.args.url):
  105.     video_id = url.replace('VDKA', '')
  106.     hbitrate = -1
  107.     sbitrate = int(common.settings['quality'])
  108.     video_url = 'http://www.kaltura.com/p/' + PARTNERID + '/sp/' + PARTNERID + '00/playManifest/format/rtmp/entryId/' + video_id
  109.     video_data = common.getURL(video_url)
  110.     video_tree = BeautifulStoneSoup(video_data, convertEntities=BeautifulStoneSoup.HTML_ENTITIES)
  111.     base_url = video_tree('baseurl')[0].string
  112.     video_url2 = video_tree.findAll('media')
  113.     for video_index in video_url2:
  114.         bitrate = int(video_index['bitrate'])
  115.         if bitrate > hbitrate and bitrate <= sbitrate:
  116.             hbitrate = bitrate
  117.             playpath_url = video_index['url']
  118.     swf_url = 'http://livepassdl.conviva.com/ver/2.61.0.65970/LivePassModuleMain.swf'
  119.     finalurl = base_url + ' playpath=' + playpath_url + ' swfUrl=' + swf_url + ' swfVfy=true'
  120.     xbmcplugin.setResolvedUrl(pluginHandle, True, xbmcgui.ListItem(path = finalurl))
  121.  
  122. def playVideoMP4(url=common.args.url):
  123.     video_id = url.replace('VDKA', '')
  124.     hbitrate = -1
  125.     sbitrate = int(common.settings['quality'])
  126.     video_url = 'http://www.kaltura.com/p/' + PARTNERID + '/sp/' + PARTNERID + '00/playManifest/format/applehttp/entryId/' + video_id
  127.     video_data = common.getURL(video_url)
  128.     video_url2 = m3u8.parse(video_data)
  129.     for video_index in video_url2.get('playlists'):
  130.         bitrate = int(video_index.get('stream_info')['bandwidth'])
  131.         if bitrate > hbitrate and bitrate <= (sbitrate * 1000):
  132.             hbitrate = bitrate
  133.             finalurl = video_index.get('uri')
  134.     xbmcplugin.setResolvedUrl(pluginHandle, True, xbmcgui.ListItem(path=finalurl))
  135.  
  136. def playVideoUPL(url=common.args.url):
  137.     video_id = url.replace('VDKA', '')
  138.     hbitrate = -1
  139.     sbitrate = int(common.settings['quality'])
  140.     video_url = 'http://www.kaltura.com/p/' + PARTNERID + '/sp/' + PARTNERID + '00/playManifest/format/http/entryId/' + video_id + '/a.f4m?playbackContext=brand%3D' + BRANDID + '%26device%3D001'
  141.     video_data = common.getURL(video_url)
  142.     video_tree = BeautifulStoneSoup(video_data, convertEntities=BeautifulStoneSoup.HTML_ENTITIES)
  143.     video_url2 = video_tree.find('media')['url']
  144.     video_data2 = common.getURL(video_url2)
  145.     video_url3 = m3u8.parse(video_data2)
  146.     for video_index in video_url3.get('playlists'):
  147.         bitrate = int(video_index.get('stream_info')['bandwidth'])
  148.         if bitrate > hbitrate and bitrate <= (sbitrate * 1000):
  149.             hbitrate = bitrate
  150.             finalurl = video_index.get('uri')
  151.     xbmcplugin.setResolvedUrl(pluginHandle, True, xbmcgui.ListItem(path=finalurl))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement