Advertisement
alexdunlop81

thecw.py all bitrates

May 7th, 2013
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.78 KB | None | 0 0
  1. import xbmc
  2. import xbmcgui
  3. import xbmcplugin
  4. import urllib
  5. import urllib2
  6. import httplib
  7. import sys
  8. import os
  9. import re
  10. import demjson
  11.  
  12. from BeautifulSoup import BeautifulSoup
  13. import resources.lib._common as common
  14.  
  15. pluginhandle=int(sys.argv[1])
  16.  
  17. BASE_URL = 'http://www.cwtv.com/cw-video/'
  18. BASE = 'http://www.cwtv.com'
  19.  
  20. def masterlist():
  21.     return rootlist(db=True)
  22.  
  23. def rootlist(db=False):
  24.     data = common.getURL(BASE_URL)
  25.     tree=BeautifulSoup(data, convertEntities=BeautifulSoup.HTML_ENTITIES)
  26.     menu=tree.find('div',attrs={'id':'shows-video'}).findAll('li')
  27.     db_shows = []
  28.     for item in menu:
  29.         url = BASE + item.find('a')['href']
  30.         #thumb = item.find('img')['src']
  31.         showname = item.find('p',attrs={'class':'t'}).string.strip()
  32.         #if showname == 'More Video':
  33.         #    continue
  34.         if db==True:
  35.             db_shows.append((showname,'thecw','show',url))
  36.         else:
  37.             common.addShow(showname, 'thecw', 'show', url)
  38.     if db==True:
  39.         return db_shows
  40.     else:
  41.         common.setView('tvshows')
  42.  
  43. def show(url=common.args.url):
  44.     data = common.getURL(url)
  45.     tree=BeautifulSoup(data, convertEntities=BeautifulSoup.HTML_ENTITIES)
  46.     menu=tree.find('div',attrs={'id':'videotabs'}).findAll('li')
  47.     for item in menu:
  48.         itemurl = url +'<videotab>'+ item['id'].replace('videotab_','')
  49.         name = item.find('p').string.split('(')[0].title()
  50.         common.addDirectory(name, 'thecw', 'episodes', itemurl)
  51.     common.setView('seasons')
  52.  
  53. def episodes(url=common.args.url):
  54.     urldata = url.split('<videotab>')
  55.     tabid = int(urldata[1])
  56.     url = urldata[0]
  57.     data = common.getURL(url)
  58.     tree=BeautifulSoup(data, convertEntities=BeautifulSoup.HTML_ENTITIES)
  59.     menu=tree.find(attrs={'id':'cw-content'}).findAll(attrs={'class':'videotabcontents'})
  60.     for item in menu:
  61.         itemid = int(item['id'].replace('videotabcontents_',''))
  62.         if tabid == itemid:
  63.             videos=item.findAll('div',recursive=False)
  64.             for video in videos:
  65.                 print video.prettify()
  66.                 url = video.find('a')['href'].split('=')[1]
  67.                 print url
  68.                 thumb = video.find('img')['src']
  69.                 name = video.find(attrs={'class':'t1'}).string.title()
  70.                 description = video.find(attrs={'class':'d3'}).string
  71.                 #try:
  72.                 #    description = hoverinfo.contents[2].strip()
  73.                 #except:
  74.                 #    print 'description failure'
  75.                 #    description = ''
  76.                 try:
  77.                     airdate = hoverinfo.contents[0].contents[2].replace('Original Air Date: ','')
  78.                 except:
  79.                     print 'airdate failure'
  80.                     airdate=''
  81.                 try:
  82.                     duration = hoverinfo.contents[0].contents[4].strip()
  83.                 except:
  84.                     print 'duration failure'
  85.                     duration = ''
  86.                 try:
  87.                     seasonepisode = hoverinfo.contents[0].contents[0].replace('Season ','').split(', EP. ')
  88.                     season = int(seasonepisode[0])
  89.                     episode = int(seasonepisode[1])
  90.                     displayname = '%sx%s - %s' % (str(season),str(episode),name)
  91.                 except:
  92.                     displayname = name
  93.                     season = 0
  94.                     episode = 0
  95.                 u = sys.argv[0]
  96.                 u += '?url="'+urllib.quote_plus(url)+'"'
  97.                 u += '&mode="thecw"'
  98.                 u += '&sitemode="play"'
  99.                 infoLabels={ "Title":name,
  100.                              "Season":season,
  101.                              "Episode":episode,
  102.                              "Plot":description,
  103.                              "premiered":airdate,
  104.                              "Duration":duration,
  105.                              #"TVShowTitle":common.args.name
  106.                              }
  107.                 common.addVideo(u,displayname,thumb,infoLabels=infoLabels)
  108.     common.setView('episodes')
  109.  
  110. def play(url=common.args.url):
  111.     #rtmpe://wbads.fcod.llnwd.net/a2383/o33/ playpath=mp4:kidswb/channels/video/thundercats_01_exodus_700kbps.mp4
  112.     swfurl = 'http://pdl.warnerbros.com/cwtv/digital-smiths/production_player/vsplayer.swf'
  113.     #swfurl = 'http://media.cwtv.com/cwtv/digital-smiths/production_player/vsplayer.swf'
  114.     url = 'http://metaframe.digitalsmiths.tv/v2/CWtv/assets/%s/partner/132?format=json' % common.args.url
  115.     #jsonurl = 'http://metaframe.digitalsmiths.tv/v2/CWtv/assets/'+url+'/partner/132?format=json'
  116.     data = common.getURL(url)
  117.     print "D",data
  118.     #    data = common.getURL(jsonurl)
  119.     #print demjson.decode(data)['videos']
  120.     #rtmp = demjson.decode(data)['videos']['ds700']['uri']
  121.     #rtmpsplit = rtmp.split('mp4:')
  122.     #74.213.154.10
  123.     #rtmp = rtmpsplit[0]+' playpath=mp4:'+rtmpsplit[1]
  124.     #rtmp = 'rtmpe://74.213.154.10/cwtv/ playpath=mp4:'+rtmpsplit[1]
  125.     #rtmpe://cwtvfs.fplive.net/cwtv/
  126.     items = demjson.decode(data)
  127.     sbitrate = int(common.settings['quality'])
  128.     hbitrate=-1
  129.     lbitrate=-1
  130.     for key in items['videos']:
  131.         item=items['videos'][key]
  132.         print "item",item
  133.         bitrate = int(item['bitrate'])
  134.         #print "BR",bitrate
  135.         print sbitrate,bitrate,hbitrate
  136.         if bitrate < lbitrate or lbitrate==-1:
  137.             lbitrate = bitrate
  138.             #print "BR",bitrate
  139.             lrtmpdata = item['uri'].split('mp4:')
  140.         if bitrate > hbitrate and bitrate <= sbitrate:
  141.             hbitrate = bitrate
  142.             print "BR",bitrate
  143.             rtmpdata = item['uri'].split('mp4:')
  144.     if hbitrate==-1:
  145.        dialog = xbmcgui.Dialog()
  146.        line1 = "No video found for maxium bitrate "+common.settings['quality']
  147.        line2 = "Lowest bitrate found is "+str(lbitrate)
  148.        line3 = "Use this bitrate?"
  149.        if dialog.yesno("Free Cable", line1,line2,line3):
  150.           rtmpdata=lrtmpdata
  151.  
  152.  
  153.        #dialog.ok("Free Cable", line1, line2, line3)
  154.      
  155.     #recently there are more than two steams, some of whch have issues need to support all to work around playback
  156.     #if sbitrate > 700:
  157.      #   rtmpdata = items['videos']['ds700']['uri'].split('mp4:')
  158.     #if sbitrate < 700:
  159.     #    rtmpdata = items['videos']['ds500']['uri'].split('mp4:')
  160.     #rtmpdata = items['videos']['ds500']['uri'].split('mp4:')
  161.     rtmp = rtmpdata[0]
  162.     playpath ='mp4:'+rtmpdata[1].replace('Level3','')
  163.     #'mp4:'+'cwtv/videos/2013/04/24/CW-Arrow-2J7320-HomeInvasion_a68203930_500kbps.mp4'
  164.     #can this be found?
  165.     rtmp = 'rtmpe://wbworldtv.fcod.llnwd.net/a2246/o23/'
  166.     rtmpurl = rtmp+' playpath='+playpath+" swfurl=" + swfurl + " swfvfy=true"
  167.     item = xbmcgui.ListItem(path=rtmpurl)
  168.     xbmcplugin.setResolvedUrl(pluginhandle, True, item)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement