コード例 #1
0
def getSearchResultsForList(html, list_id):
  """
  Returns the items in the supplied list.

  Lists are the containers on a program page that contains clips or programs.
  """
  container = common.parseDOM(html, "div", attrs = { "id" : list_id })
  if not container:
    helper.errorMsg("No container found for list ID '"+list_id+"'")
    return None

  articles = common.parseDOM(container, "article")
  if not articles:
    helper.errorMsg("No articles found for list ID '"+list_id+"'")
    return None

  titles = common.parseDOM(container, "article", ret = "data-title")

  results = []
  for index, article in enumerate(articles):
    thumbnail = common.parseDOM(article, "img", attrs = { "class" : "[^\"']*play_videolist-element__thumbnail-image[^\"']*" }, ret = "src")[0]
    url = common.parseDOM(article, "a", ret = "href")[0]
    title = common.replaceHTMLCodes(titles[index])
    thumbnail = helper.prepareThumb(thumbnail, baseUrl=BASE_URL)

    item_type = "video"
    if list_id == SEARCH_LIST_TITLES:
      item_type = "program"
    results.append({"item": { "title" : title, "thumbnail" : thumbnail, "url" : url  }, "type" : item_type })

  return results
コード例 #2
0
def getProgramsForCategory(url):
  """
  Returns a list of programs for a specific category URL.
  """
  html = getPage(url)

  container = common.parseDOM(html, "div", attrs = { "id" : "[^\"']*playJs-alphabetic-list[^\"']*" })

  if not container:
    helper.errorMsg("Could not find container for URL "+url)
    return None

  articles = common.parseDOM(container, "article", attrs = { "class" : "[^\"']*play_videolist-element[^\"']*" })

  if not articles:
    helper.errorMsg("Could not find program links for URL "+url)
    return None

  programs = []
  for index, article in enumerate(articles):
    url = common.parseDOM(article, "a", ret="href")[0]
    title = common.parseDOM(article, "span", attrs= { "class" : "play_videolist-element__title-text" })[0]
    title = common.replaceHTMLCodes(title)
    thumbnail = common.parseDOM(article, "img", ret="src")[0]
    program = { "title": title, "url": url, "thumbnail": helper.prepareThumb(thumbnail, baseUrl=BASE_URL)}
    programs.append(program)
  return programs
コード例 #3
0
def getChannels():
  """
  Returns the live channels from the page "Kanaler".
  """
  anchor_class = "[^\"']*play_zapper__menu-item-link[^\"']*"
  html = getPage(URL_TO_CHANNELS)

  container = common.parseDOM(html, "ul", attrs = { "data-play_tabarea" : "ta-schedule"})
  if not container:
    helper.errorMsg("No container found for channels")
    return None

  channels = []
  ch_boxes = common.parseDOM(container, "li")
  for box in ch_boxes:
    title = common.parseDOM(box, "a", attrs = {"class" : anchor_class}, ret = "data-channel")[0]
    url = common.parseDOM(box, "a", attrs = {"class" : anchor_class}, ret = "href")[0]
    plot = common.parseDOM(box, "span", attrs = {"class" : "[^\"']*play_zapper__menu-item-title[^\"']*"})[0]
    thumbnail = common.parseDOM(box, "a", attrs = {"class" : anchor_class}, ret = "data-thumbnail")[0]
    channels.append({
      "title" : title.title(),
      "url" : url,
      "thumbnail" : helper.prepareThumb(thumbnail, baseUrl=BASE_URL),
      "info" : { "title" : common.replaceHTMLCodes(plot), "plot" : common.replaceHTMLCodes(plot)}
    })

  return channels
コード例 #4
0
def getAlphas():
  """
  Returns a list of all letters in the alphabet that has programs.
  """
  html = getPage(URL_A_TO_O)
  container = common.parseDOM(html, "ul", attrs = { "class" : "[^\"']*play_alphabetic-list[^\"']*" })

  if not container:
    helper.errorMsg("No container found!")
    return None

  letters = common.parseDOM(container[0], "h3", attrs = { "class" : "[^\"']*play_alphabetic-list__letter[^\"']*" })

  if not letters:
    helper.errorMsg("Could not find any letters!")
    return None

  alphas = []

  for letter in letters:
    alpha = {}
    alpha["title"] = helper.convertChar(letter)
    alpha["char"] =  letter
    alphas.append(alpha)

  return alphas
コード例 #5
0
def getSearchResults(url):
  """
  Returns a list of both clips and programs
  for the supplied search URL.
  """
  html = getPage(url)

  results = []

  for list_id in [SEARCH_LIST_TITLES, SEARCH_LIST_EPISODES, SEARCH_LIST_CLIPS]:
    items = getSearchResultsForList(html, list_id)
    if not items:
      helper.errorMsg("No items in list '"+list_id+"'")
      continue
    results.extend(items)

  return results
コード例 #6
0
def getCategories():
  """
  Returns a list of all categories.
  """
  html = getPage("/")


  container = common.parseDOM(html, "div", attrs = { "id": "[^\"']*playJs-categories[^\"']*" })
  if not container:
    helper.errorMsg("Could not find container")
    return None
  articles = common.parseDOM(container, "article")
  if not articles:
    helper.errorMsg("Could not find articles")
    return None
  thumbs = common.parseDOM(container, "img", attrs = { "class": "[^\"']*play_categorylist-element__thumbnail-image[^\"']*" }, ret = "src")
  if not thumbs:
    helper.errorMsg("Could not find thumbnails")
    return None
  categories = []

  for index, article in enumerate(articles):
    category = {}
    category["url"] = common.parseDOM(article, "a", ret = "href")[0]
    title = common.parseDOM(article, "a", ret="title")[0]

    if category["url"].endswith("oppetarkiv"):
      # Skip the "Oppetarkiv" category
      continue

    category["title"] = common.replaceHTMLCodes(title)
    category["thumbnail"] = helper.prepareThumb(thumbs[index], baseUrl=BASE_URL)
    categories.append(category)

  return categories
コード例 #7
0
def getProgramsByLetter(letter):
  """
  Returns a list of all program starting with the supplied letter.
  """
  letter = urllib.unquote(letter)

  html = getPage(URL_A_TO_O)

  letterboxes = common.parseDOM(html, "li", attrs = { "class": "[^\"']*play_alphabetic-list__letter-container[^\"']*" })
  if not letterboxes:
    helper.errorMsg("No containers found for letter '%s'" % letter)
    return None

  letterbox = None

  for letterbox in letterboxes:

    heading = common.parseDOM(letterbox, "h3")[0]

    if heading == letter:
      break

  lis = common.parseDOM(letterbox, "li", attrs = { "class": "[^\"']*play_js-filterable-item[^\"']*" })
  if not lis:
    helper.errorMsg("No items found for letter '"+letter+"'")
    return None

  programs = []

  for li in lis:
    program = {}
    program["url"] = common.parseDOM(li, "a", ret = "href")[0]
    title = common.parseDOM(li, "a")[0]
    program["title"] = common.replaceHTMLCodes(title)
    programs.append(program)

  return programs
コード例 #8
0
def getProgramItems(section_name, url=None):
  """
  Returns a list of program items for a show.
  Program items have 'title', 'thumbnail', 'url' and 'info' keys.
  """
  if not url:
    url = "/"
  html = getPage(url + "?sida=2")

  video_list_class = "[^\"']*play_videolist[^\"']*"

  container = common.parseDOM(html, "div", attrs = { "id" : section_name })
  if not container:
    helper.errorMsg("No container found for section "+section_name+"!")
    return None
  container = container[0]

  item_class = "[^\"']*play_vertical-list__item[^\"']*"
  items = common.parseDOM(container, "li", attrs = { "class" : item_class })
  if not items:
    helper.errorMsg("No items found in container \""+section_name+"\"")
    return None
  new_articles = []


  for index, item in enumerate(items):
    live_item = False
    if "play_live-countdown" in item:
      live_item = True
      helper.infoMsg("Skipping live item!")
      continue
    info = {}
    new_article = {}
    title = common.parseDOM(item, "a",
                            attrs = { "class" : "[^\"']*play_vertical-list__header-link[^\"']*" })[0]
    plot = common.parseDOM(item, "p",
                            attrs = { "class" : "[^\"']*play_vertical-list__description-text[^\"']*" })[0]
    new_article["url"] = common.parseDOM(item, "a",
                            attrs = { "class": "[^\"']*play_vertical-list__header-link[^\"']*" },
                            ret = "href")[0]
    thumbnail = common.parseDOM(item,
                                "img",
                                attrs = { "class": "[^\"']*play_vertical-list__image[^\"']*" },
                                ret = "src")[0]
    new_article["thumbnail"] = helper.prepareThumb(thumbnail, baseUrl=BASE_URL)
    duration = common.parseDOM(item, "time", attrs = {}, )[0]
    aired = common.parseDOM(item, "p", attrs = { "class" : "[^\"']*play_vertical-list__meta-info[^\"']*" })
    if aired:
      aired = aired[0].replace("Publicerades ", "")
    else:
      # Some items does not contain this meta data
      aired = ""

    plot = common.replaceHTMLCodes(plot)
    new_article["title"] = title
    info["title"] = title
    info["plot"] = plot
    info["aired"] = helper.convertDate(aired) 
    info["duration"] = helper.convertDuration(duration)
    info["fanart"] = helper.prepareFanart(thumbnail, baseUrl=BASE_URL)
    new_article["info"] = info
    new_articles.append(new_article)

  return new_articles
コード例 #9
0
def getArticles(section_name, url=None):
  """
  Returns a list of the articles in a section as program items.

  Program items have 'title', 'thumbnail', 'url' and 'info' keys.
  """
  if not url:
    url = "/"
  html = getPage(url)

  video_list_class = "[^\"']*play_videolist[^\"']*"

  container = common.parseDOM(html, "div", attrs = { "class" : video_list_class, "id" : section_name })
  if not container:
    helper.errorMsg("No container found for section "+section_name+"!")
    return None
  container = container[0]

  article_class = "[^\"']*play_videolist-element[^\"']*"
  articles = common.parseDOM(container, "article", attrs = { "class" : article_class })
  titles = common.parseDOM(container, "article", attrs = { "class" : article_class }, ret = "data-title")
  plots = common.parseDOM(container, "article", attrs = { "class" : article_class }, ret = "data-description")
  airtimes = common.parseDOM(container, "article", attrs = { "class" : article_class }, ret = "data-broadcasted")
  if section_name == SECTION_LATEST_CLIPS:
    airtimes = common.parseDOM(container, "article", attrs = { "class" : article_class }, ret = "data-published")
  durations = common.parseDOM(container, "article", attrs = { "class" : article_class }, ret = "data-length")
  new_articles = []

  if not articles:
    helper.errorMsg("No articles found for section '"+section_name+"' !")
    return None

  for index, article in enumerate(articles):
    info = {}
    new_article = {}
    plot = plots[index]
    aired = airtimes[index]
    duration = durations[index]
    title = titles[index]
    new_article["url"] = common.parseDOM(article, "a",
                            attrs = { "class": "[^\"']*play_videolist-element__link[^\"']*" },
                            ret = "href")[0]
    thumbnail = common.parseDOM(article,
                                "img",
                                attrs = { "class": "[^\"']*play_videolist-element__thumbnail-image[^\"']*" },
                                ret = "src")[0]
    new_article["thumbnail"] = helper.prepareThumb(thumbnail, baseUrl=BASE_URL)
    if section_name == SECTION_LIVE_PROGRAMS:
      notlive = common.parseDOM(article, "span", attrs = {"class": "[^\"']*play_graphics-live[^\"']*is-inactive[^\"']*"})
      if notlive:
        new_article["live"] = False
      else:
        new_article["live"] = True
    title = common.replaceHTMLCodes(title)
    plot = common.replaceHTMLCodes(plot)
    new_article["title"] = title
    info["title"] = title
    info["plot"] = plot
    info["aired"] = helper.convertDate(aired)
    info["duration"] = helper.convertDuration(duration)
    info["fanart"] = helper.prepareFanart(thumbnail, baseUrl=BASE_URL)
    new_article["info"] = info
    new_articles.append(new_article)

  return new_articles
コード例 #10
0
ファイル: grammar.py プロジェクト: 97686773/PingPHP
def p_error(p):
    from helper import errorMsg
    errorMsg("Grammar", p)
コード例 #11
0
ファイル: lexer.py プロジェクト: 97686773/PingPHP
def t_error(t):
    from helper import errorMsg
    errorMsg('Lexical', t)
コード例 #12
0
    })
  return favorites

def __load_from_disk():
  global FAVORITES
  FAVORITES = {}
  if os.path.exists(FILE_PATH) and os.stat(FILE_PATH).st_size != 0:
    with open(FILE_PATH, "r") as file_handle:
        FAVORITES = json.load(file_handle)
  helper.infoMsg("Load from disk: "+str(FAVORITES))

def __save_to_disk():
  helper.infoMsg("Save to disk: "+str(FAVORITES))
  directory = os.path.dirname(FILE_PATH)
  if not os.path.exists(directory):
    os.makedirs(directory)
  with open(FILE_PATH, "w") as file_handle:
    file_handle.write(json.dumps(FAVORITES))

# To support XBMC.RunScript
if __name__ == "__main__":
  helper.infoMsg("FM called as script!")
  if len(sys.argv) < 2:
    helper.errorMsg("No argument given!")
  else:
    if sys.argv[1] == "add" and len(sys.argv) > 3:
      add(sys.argv[2], sys.argv[3])
    elif sys.argv[1] == "remove" and len(sys.argv) > 2:
      remove(sys.argv[2])
      xbmc.executebuiltin("XBMC.Container.Refresh")
コード例 #13
0
def __load_from_disk():
    global FAVORITES
    FAVORITES = {}
    if os.path.exists(FILE_PATH) and os.stat(FILE_PATH).st_size != 0:
        with open(FILE_PATH, "r") as file_handle:
            FAVORITES = json.load(file_handle)
    helper.infoMsg("Load from disk: " + str(FAVORITES))


def __save_to_disk():
    helper.infoMsg("Save to disk: " + str(FAVORITES))
    directory = os.path.dirname(FILE_PATH)
    if not os.path.exists(directory):
        os.makedirs(directory)
    with open(FILE_PATH, "w") as file_handle:
        file_handle.write(json.dumps(FAVORITES))


# To support XBMC.RunScript
if __name__ == "__main__":
    helper.infoMsg("FM called as script!")
    if len(sys.argv) < 2:
        helper.errorMsg("No argument given!")
    else:
        if sys.argv[1] == "add" and len(sys.argv) > 3:
            add(sys.argv[2], sys.argv[3])
        elif sys.argv[1] == "remove" and len(sys.argv) > 2:
            remove(sys.argv[2])
            xbmc.executebuiltin("XBMC.Container.Refresh")