コード例 #1
0
ファイル: default.py プロジェクト: khoda/xbmc-oppetarkiv
def createDirectory(url,page,index,callertype,dirtype):
  """
  Creates a directory with list items from the supplied program
  page (url).
  """

  #if not url.startswith("/"):
  #  url = "/" + url

  tabname = svt.TAB_EPISODES
  if MODE_RECOMMENDED == callertype:
    tabname = svt.TAB_RECOMMENDED
  elif MODE_LATEST_NEWS == callertype:
    tabname = svt.TAB_NEWS
  elif MODE_VIEW_CLIPS == callertype:
    tabname = svt.TAB_CLIPS
  elif MODE_CATEGORY == callertype or MODE_VIEW_TITLES == callertype:
    tabname = svt.TAB_TITLES

  html = svt.getPage(url)

  visafler = common.parseDOM(html, "a", attrs = { "class": "[^\"']*svtCenterUnknown[^\"']*" }, ret = "href")

  if len(visafler) == 1:
    kolla = True
    populateDirNoPaging(url,dirtype,tabname)
    url = visafler[0]

    while (kolla):
      html = svt.getPage(url)
      visafler = common.parseDOM(html, "a", attrs = { "class": "[^\"']*svtCenterUnknown[^\"']*" }, ret = "href")
      populateDirNoPaging(url,dirtype,tabname)
      
      if len(visafler) == 2:
        url = visafler[1]
      else:
        kolla = False
        
    return
  else:
    populateDirNoPaging(url,dirtype,tabname)
    return    
コード例 #2
0
ファイル: default.py プロジェクト: linqcan/xbmc-oppetarkiv
def startVideo(url):
  """
  Starts the XBMC player if a valid video url is 
  found for the given page url.
  """
  #if not url.startswith("/"):
  #  url = "/" + url

  url = url + svt.JSON_SUFFIX
  common.log("url: " + url)
  html = svt.getPage(url)

  jsonString = common.replaceHTMLCodes(html)
  jsonObj = json.loads(jsonString)
  common.log(jsonString)

  subtitle = None
  player = xbmc.Player()
  startTime = time.time()
  videoUrl = None
  extension = "None"
  args = ""

  for video in jsonObj["video"]["videoReferences"]:
    """
    Determine which file extension that will be used
    m3u8 is preferred, hence the break.
    Order: m3u8, f4m, mp4, flv
    """
    tmpurl = video["url"]
    argpos = tmpurl.rfind("?")
    if argpos > 0:
      args = tmpurl[argpos:]
      tmpurl = tmpurl[:argpos]

    if tmpurl.endswith(".m3u8"):
      extension = "HLS"
      videoUrl = tmpurl
      break
    if tmpurl.endswith(".f4m"):
      extension = "F4M"
      videoUrl = tmpurl
      continue
    if tmpurl.endswith(".mp4"):
      extension = "MP4"
      videoUrl = tmpurl
      continue
    if tmpurl.endswith(".flv"):
      extension = "FLV"
      videoUrl = tmpurl
      continue
    videoUrl = tmpurl

  for sub in jsonObj["video"]["subtitleReferences"]:
    if sub["url"].endswith(".wsrt"):
      subtitle = sub["url"]
    else:
      if len(sub["url"]) > 0:
        common.log("Skipping unknown subtitle: " + sub["url"])

  if extension == "HLS" and HLS_STRIP:
    videoUrl = hlsStrip(videoUrl)
  elif extension == "HLS" and BW_SELECT: 
    videoUrl = getStream(videoUrl)

  if extension == "F4M":
    videoUrl = videoUrl.replace("/z/", "/i/").replace("manifest.f4m","master.m3u8")

  if extension == "MP4":
    videoUrl = mp4Handler(jsonObj)

  if extension == "None" and videoUrl:
    # No supported video was found
    common.log("No supported video extension found for URL: " + videoUrl)
    videoUrl = None

  if videoUrl:
    
    if args and not (HLS_STRIP or BW_SELECT):
      common.log("Appending arguments: "+args)
      videoUrl = videoUrl + args

    if extension == "MP4" and videoUrl.startswith("rtmp://"):
      videoUrl = videoUrl + " swfUrl="+svt.SWF_URL+" swfVfy=1"
 
    xbmcplugin.setResolvedUrl(pluginHandle, True, xbmcgui.ListItem(path=videoUrl))

    if subtitle:

      while not player.isPlaying() and time.time() - startTime < 10:
        time.sleep(1.)

      player.setSubtitles(subtitle)

      if not SHOW_SUBTITLES:
        player.showSubtitles(False)
  else:
    # No video URL was found
    dialog = xbmcgui.Dialog()
    dialog.ok("SVT PLAY", localize(30100))