def experts(): """Lists experts, and their choices""" href = get_arg("href", False) if not href: url = jafc.get_url("en/works-favorites.html") data = jafc.get_html(url) container = data.find("div", "work-favorites") for item in container.find_all("div", "work-favorite"): author = item.find("strong").text add_menu_item(experts, author, args={"href": "en/" + item.find("a")["href"], "title": item.find("strong").text}, info={"plot": item.find("div", "work-favorite-summary").text}, art=ku.art(jafc.get_url(item.find("img", "thumbnail")["src"]))) xbmcplugin.setPluginCategory(plugin.handle, ku.localize(32023)) # Experts Choice else: url = jafc.get_url(href) data = jafc.get_html(url) for item in data.find_all("div", "favorite-work"): action = item.find("h2").find("a") add_menu_item(play_film, action.text, args={"href": action["href"]}, info={"plot": item.find("dd").text}, art=ku.art(jafc.get_url(item.find("img", "thumbnail")["src"])), directory=False) xbmcplugin.setPluginCategory(plugin.handle, get_arg("title")) # Experts name xbmcplugin.endOfDirectory(plugin.handle)
def experts(): """Lists experts, and their choices""" href = get_arg("href", False) if not href: url = jafc.get_page_url("en/works-favorites.html") data = jafc.get_html(url) container = data.find("div", "work-favorites") for item in container.find_all("div", "work-favorite"): action = item.find("a") img = item.find("img", "thumbnail") title = img["alt"] ku.log(action) add_menu_item(experts, title, args={"href": "en/" + action["href"], "title": title}, info={"plot": item.find("div", "work-favorite-summary").text}, art=ku.art(jafc.get_page_url(img["src"]))) else: url = jafc.get_page_url(href) data = jafc.get_html(url) for item in data.find_all("div", "favorite-work"): img = item.find("img", "thumbnail") action = item.find("h2").find("a") title = action.text add_menu_item(play_film, title, args={"href": action["href"]}, info={"plot": item.find("dd").text}, art=ku.art(jafc.get_page_url(img["src"])), directory=False) xp.setPluginCategory(plugin.handle, get_arg("title")) xp.endOfDirectory(plugin.handle)
def section(): # type: () -> None """Show category menu and category playable items""" href = get_arg("href") category = get_arg("category", ku.localize(32002)) page = int(get_arg("page", 1)) offset = int(get_arg("offset", 0)) if not href: # section menu soup = nfpfs.get_html(nfpfs.NFPF_SCREENING_ROOM_URI) for item in soup.find_all("table"): title = item.find("h5").text add_menu_item(section, title, args={ "href": item.find("a").get("href"), "category": title }, art=ku.art(nfpfs.get_url( item.find("img").get("src"))), info={"plot": item.find("p").text}) else: url = nfpfs.get_url(href) soup = nfpfs.get_html(url) if url == nfpfs.NFPF_MERCURY_URI: # odd playable items parse_mercury(soup) else: results = soup.find_all("figure", "video-thumb") items = results[offset:nfpfs.SEARCH_MAX_RESULTS + offset] # section paging if len(results) > len(items) == nfpfs.SEARCH_MAX_RESULTS: paginate(category, href, page) for item in items: # section playable items action = item.find("figcaption").find("a") url = nfpfs.get_url(action.get("href")) data = nfpfs.get_info(nfpfs.get_html(url)) data.get("info")["genre"] = item.get("data-archive") add_menu_item(play_film, data.get("title"), args={"href": url}, art=ku.art(data.get("image")), info=data.get("info"), directory=False) xbmcplugin.setContent(plugin.handle, "videos") xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE) xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_VIDEO_YEAR) xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_GENRE) xbmcplugin.setPluginCategory(plugin.handle, category) xbmcplugin.endOfDirectory(plugin.handle)
def programas(): # type: () -> None """Lista de Programas por CanalSur.""" href = get_arg("href", False) category = get_arg("category", CATEGORY_PROGRAMAS) # Programas if not href: # Listado de Programas menu xbmc.executebuiltin('Container.SetViewMode(%d)' % VIEW_TYPE_ICON) xbmc.executebuiltin('Container.SetViewMode(%d)' % VIEW_TYPE_ICON) ps = canalsur.get_programas() for programa in ps: logger.info("programas->ku.art = {}".format(programa.thumbnail())) add_menu_item( programas, programa.nombre, info={"Plot": programa.descripcion.encode("ascii", "ignore")}, args={ "href": programa.id, "category": programa.nombre.encode("ascii", "ignore") }, art=ku.art(programa.thumbnail())) else: # Lista de Capitulos del programa (href es programaId) xbmc.executebuiltin('Container.SetViewMode(%d)' % VIEW_TYPE_PLAIN_LIST) xbmc.executebuiltin('Container.SetViewMode(%d)' % VIEW_TYPE_PLAIN_LIST) capitulos = canalsur.get_capitulos(id=href) for capitulo in capitulos: add_menu_item(play_film, capitulo.capitulo, args={ "href": capitulo.id, "videoUrl": capitulo.url[0], "capitulo": capitulo.capitulo.encode("ascii", "ignore"), "fecha": capitulo.fecha }, info={ "Plot": capitulo.capitulo.encode("ascii", "ignore"), "Date": capitulo.fecha }, art=ku.art(capitulo.tapa), directory=False) xbmcplugin.setContent(plugin.handle, "capitulos") xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE) xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_DATE) xbmcplugin.setPluginCategory(plugin.handle, category) xbmcplugin.endOfDirectory(plugin.handle)
def programmes(): # type: () -> None """View series curated by British Pathé.""" href = get_arg("href", False) category = get_arg("category", ku.localize(32021)) # programming if not href: # Programmes menu soup = bps.get_html(bps.BP_COLLECTIONS_URI) for img in soup.select("a > img"): if img.parent['href'].startswith('/programmes/'): title = img.parent.findNext("a").text href = img.parent.findNext("a")["href"] add_menu_item(programmes, title, info={"plot": "foobar"}, args={ "href": href, "category": title }, art=ku.art(bps.get_uri(img["src"]))) else: # Programme's playable items soup = bps.get_html(bps.get_uri(href)) table = soup.find("table", {"id": "programmeTable"}).extract() for img in table.select("a > img"): action = img.parent row = action.find_parent("tr") add_menu_item(play_film, row.find("span").text, args={"href": action["href"]}, info={ "plot": "", "year": int(row.find("td", "far-right").text.strip()), "episode": int( row.find("td", "episode-number").text.strip()) }, art=ku.art(img["src"]), directory=False) xbmcplugin.setContent(plugin.handle, "episodes") xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE) xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_VIDEO_YEAR) xbmcplugin.setPluginCategory(plugin.handle, category) xbmcplugin.endOfDirectory(plugin.handle)
def the_cut(): # type: () -> None """Shows the-cut menu and sub-menu items""" href = get_arg("href") category = get_arg("title", "The Cut") if not href: # The Cut menu soup = bfis.get_html(bfis.THE_CUT_URI) for card in soup.find_all("div", "c_card"): action = card.find(["a", "card__action"]).extract() if action is None: continue title_tag = card.find("h3", "c_card__title") plot_tag = card.find("div", "c_card__footer__summary") title = title_tag.text if title_tag else action["aria-label"] add_menu_item(the_cut, title, args={ "href": action["href"], "title": title }, info={"plot": plot_tag.text}, art=ku.art(bfis.BFI_URI, card.find("img").attrs)) else: # The Cut playable items soup = bfis.get_html(bfis.get_page_url(href)) items = soup.find_all("div", "player") for item in items: plot = soup.find("div", "text__visible").find("p") \ if item is items[0] \ else item.find_next("div", "m_card__description") add_menu_item(play_film, item.get("data-label"), args={ "video_id": item.get(PLAYER_ID_ATTR), "href": href }, info={ "mediatype": "video", "plot": plot.text.encode("utf-8") if plot else "" }, art=ku.art(bfis.BFI_URI, item.find_next("img").attrs), directory=False) xbmcplugin.setContent(plugin.handle, "videos") xbmcplugin.setPluginCategory(plugin.handle, category) xbmcplugin.endOfDirectory(plugin.handle)
def recent(): # type: () -> None """Show recently viewed films""" data = bfis.recents.retrieve() for url, video_id in data: soup = bfis.get_html(url) title = soup.find("h1").text.strip() description = soup.find("meta", { "name": "description" }).get("content").encode("utf-8") image = soup.find("meta", {"property": "og:image"}).get("content") add_menu_item(play_film, title, args={ "href": url, "video_id": video_id }, info={ "plot": description, "mediatype": "video" }, art=ku.art("", image), directory=False) xbmcplugin.setContent(plugin.handle, "videos") xbmcplugin.setPluginCategory(plugin.handle, ku.localize(32021)) # Recently Viewed xbmcplugin.endOfDirectory(plugin.handle)
def parse_search_results(soup, category, method): # type: (BeautifulSoup, str, callable) -> None """Adds menu items for search result data""" if not soup: # NB: some show links 404 :( return paginate(soup.find("a", "load-more"), category, method) for item in soup.find_all("div", "media-module"): # category/show playable items action = item.find("a") img = item.find("img") title = item.find("div", "title").text.encode("utf-8") duration = item.find("div", "timestamp") add_menu_item(play_film, title, args={"href": action.get("href")}, art=ku.art( img.get("data-lazyload-src", img.get("data-src", img.get("src")))), info={ "mediatype": "video", "duration": ngs.time_to_seconds(duration.text) if duration else 0 }, directory=False) xbmcplugin.setContent(plugin.handle, "videos") xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_DURATION) xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE)
def parse_results(data, offset=1, query=None): # type (BeautifulSoup, int, str) -> None """Parse videos from results and add pagination""" items = data.find_all("div", "result_item") if not items: return if query is not None and data.find("div", "pagination"): paginate(query, offset, len(items)) for item in items: action = item.find("a") title = item.find("h2").text.strip() img = item.find("img") add_menu_item( play_film, title, args={"href": action["href"].lstrip("../")}, art=ku.art(eafa.get_page_url(img["src"])), info={ "title": title, "plot": item.find("p").text.strip(), "duration": parse_time(item.find("span", "dur").text) }, directory=False ) xp.setContent(plugin.handle, "videos") xp.endOfDirectory(plugin.handle)
def parse_search_results(data, query, offset): # type: (dict, str, int) -> None """Adds menu items for search result data""" if not data: return hits = data.get("hits") if not hits: return results = hits.get("hits", []) paginate(query, len(results), int(hits.get("total", 0)), offset) for element in results: data = element.get("_source", False) if not data: continue title = data.get("title", "") duration = data.get("duration") info = { "originaltitle": data.get("original_title", ""), "plot": bfis.html_to_text(data.get("standfirst", "")), "genre": data.get("genre", ""), "cast": data.get("cast", ""), "director": data.get("director", ""), "year": int(data.get("release_date", 0)), "duration": int(duration) * 60 if duration else 0, "mediatype": "video" } add_menu_item(play_film, title, args={"href": data.get("url")}, art=ku.art("", data.get("image", ["Default.png"])[0]), info=info, directory=False)
def programme(): """Shows the programme menu or a programme's playable items""" href = get_arg("href") category = get_arg("category", ku.localize(32009)) # Programs if not href: # TV Shows menu soup = dws.get_html(dws.DW_PROGRAMME_URI) content = soup.find("div", {"id": "bodyContent"}).extract() items = content.find_all("div", "epg") for item in items: img = item.find("img") title = item.find("h2").text.encode("utf-8") action = item.find("a", string="All videos") pid = dws.get_program_id(action.get("href")) plot = item.find("p").text.strip() add_menu_item(programme, title, { "href": dws.get_search_url(pid=pid), "category": title }, ku.art(dws.get_url(img.get("src"))), {"plot": plot if plot else title}) xbmcplugin.setContent(plugin.handle, "tvshows") else: # TV Show's playable episodes soup = dws.get_html(href) parse_search_results(soup, href, programme, category) xbmcplugin.setContent(plugin.handle, "episodes") xbmcplugin.setPluginCategory(plugin.handle, category) xbmcplugin.endOfDirectory(plugin.handle)
def shows(): page = get_arg("page", 0) category = get_arg("category", ku.localize(32003)) soup = ngs.get_html(ngs.get_show_url(page)) # Shows paging load_more = soup.find("a", "load-more") if load_more: next_page = ngs.get_gp(load_more.get("href")) add_menu_item(shows, "[{} {}]".format(ku.localize(32011), next_page + 1), args={"page": next_page}) for item in soup.find_all("div", "media-module"): # shows menu action = item.find("a") title = item.find("div", "title").text img = action.find("img") count = ngs.get_playable_item_count(action.get("href")) add_menu_item(section, "{} [{} items]".format(title, count), args={ "href": action.get("href"), "category": title }, art=ku.art(img.get("src"))) xbmcplugin.setPluginCategory(plugin.handle, category) xbmcplugin.endOfDirectory(plugin.handle)
def archive(): # type: () -> None """View important anniversaries, contextualising current events or illustrating trending topics""" data = bps.get_html(bps.BP_ARCHIVE_URI) content = data.find("div", "entry-content") if not content: logger.debug("Missing menu: {}".format(bps.BP_ARCHIVE_URI)) return images = content.select("a > img") # Archive menu for img in images: action = img.findNext("a") if not action: continue title = action.text.strip() date = action.findNextSibling("strong").text.strip() add_menu_item(collection, "{} ({})".format(title, date), args={ "href": action["href"], "playable": True, "category": title }, art=ku.art(img["src"])) xbmcplugin.setPluginCategory(plugin.handle, ku.localize(32009)) # Archive Picks xbmcplugin.endOfDirectory(plugin.handle)
def parse_results(data): # type (BeautifulSoup) -> None """Adds menu items for result data""" directory = data.find("div", {"id": "directory-list"}) if directory is None: return list = directory.find("ul") if list is None: return for child in list.find_all("li"): image = child.find("img") action = child.find("a") if image is None or action is None: continue info = { "genre": child.find("div", "col-4").text.split(","), "year": bcfs.text_to_int(child.find("div", "col-3").text), "director": child.find("div", "col-2").text } add_menu_item(play_film, child.find("div", "col-1").text, args={"href": action["href"]}, info=info, art=ku.art(bcfs.get_page_url(image["src"])), directory=False) xp.setContent(plugin.handle, "videos") xp.addSortMethod(plugin.handle, xp.SORT_METHOD_LABEL_IGNORE_THE) xp.addSortMethod(plugin.handle, xp.SORT_METHOD_GENRE) xp.addSortMethod(plugin.handle, xp.SORT_METHOD_VIDEO_YEAR) xp.endOfDirectory(plugin.handle)
def highlights(): href = get_arg("href", False) xp.setPluginCategory(plugin.handle, get_arg("title", ku.get_string(32006))) # Highlights if not href: url = eafa.get_page_url("highlights.aspx") data = eafa.get_html(url) for item in data.find_all("div", "hl_box"): action = item.find("a") img = action.find("img") title = img["alt"] add_menu_item( highlights, title, {"href": action["href"], "title": title}, art=ku.art(eafa.get_page_url(img["src"])) ) xp.setContent(plugin.handle, "videos") xp.endOfDirectory(plugin.handle) return url = eafa.get_page_url(href) data = eafa.get_html(url) form = get_form_data(data) if form: parse_links(data, form) else: parse_results(data)
def films(): """Playable movie items""" url = jafc.get_page_url(get_arg("href")) data = jafc.get_html(url) paginate(data.find("ul", "pager-menu"), films) container = data.find(True, {"class": ["categories", "characters", "writer-works"]}) for item in container.find_all("li"): title = item.find(True, {"class": ["category-title", "character-serif", "writer-work-heading"]}).text action = item.find("a") if action is None: continue img = item.find("img", "thumbnail") add_menu_item( play_film, title, {"href": action["href"]}, info=get_info(action["href"]), art=ku.art(jafc.get_page_url(img["src"])), directory=False) xp.setPluginCategory(plugin.handle, get_arg("title")) xp.setContent(plugin.handle, "videos") xp.addSortMethod(plugin.handle, xp.SORT_METHOD_LABEL_IGNORE_THE) xp.addSortMethod(plugin.handle, xp.SORT_METHOD_GENRE) xp.addSortMethod(plugin.handle, xp.SORT_METHOD_VIDEO_YEAR) xp.addSortMethod(plugin.handle, xp.SORT_METHOD_DURATION) xp.endOfDirectory(plugin.handle)
def films(): """Playable movie items""" url = jafc.get_url(get_arg("href")) data = jafc.get_html(url) paginate(data.find("ul", "pager-menu"), films) container = data.find(True, {"class": ["categories", "characters", "writer-works"]}) if container is None: ku.notification(ku.localize(32008), ku.localize(32009)) # Error - No playable items found return for item in container.find_all("li"): action = item.find("a") if action is None: continue add_menu_item( play_film, item.find(True, {"class": ["category-title", "character-serif", "writer-work-heading"]}).text, args={"href": action["href"]}, info=jafc.get_info(action["href"]), art=ku.art(jafc.get_url(item.find("img", "thumbnail")["src"])), directory=False) xbmcplugin.setContent(plugin.handle, "videos") xbmcplugin.setPluginCategory(plugin.handle, get_arg("title")) xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE) xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_GENRE) xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_VIDEO_YEAR) xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_DURATION) xbmcplugin.endOfDirectory(plugin.handle)
def parse_search_results(json, query): # type: (dict, str) -> None """Parses search results""" for video in json.get("videos"): for key in video: item = video.get(key) if not item: continue elif isinstance(item, list): item = " ".join(item) elif isinstance(item, int): item = str(item) if query in item: # simple text search on each field add_menu_item( play_film, video.get("name"), args={"href": video.get("path")}, art=ku.art(nfpfs.get_url(video.get("image_path"))), info={ "mediatype": "video", "plot": nfpfs.text_to_soup(video.get("notes")).find("p").text, "genre": video.get("archive_names"), "year": video.get("sort_year") }, directory=False) break # only one match per-video
def collection(): # type: () -> None """Various workspaces by theme, location and the personalities involved.""" category = get_arg("category", False) playable = get_arg("playable", False) href = get_arg("href", False) data = bps.get_collection_data() if not category: # Main collections menu for item in data: add_menu_item(collection, item, args={"category": item.encode("utf-8")}) if category and not href: # Collection category menu for item in data[category]: add_menu_item(collection, item, args={ "href": bps.get_uri(data[category][item][0]), "category": item.encode("utf-8") }, art=ku.art(bps.get_uri(data[category][item][1]))) if href and not playable: # Collection category sub-meu soup = bps.get_html(href) workspaces = soup.find_all("dl", "workspace") for item in workspaces: action = item.find("a") title = action["title"].strip().encode("utf-8") add_menu_item(collection, title, args={ "href": action["href"], "category": title, "playable": True }, art=ku.art(item.find("img")["src"])) if href and playable: # Collection category sub-menu playable items soup = bps.get_html(href) parse_search_results(soup) xbmcplugin.setPluginCategory(plugin.handle, category if category else ku.localize(32004)) xbmcplugin.endOfDirectory(plugin.handle)
def recent(): # type: () -> None """Show recently viewed films""" items = dws.recents.retrieve() for url in items: data = dws.get_info(url) add_menu_item(play_film, data.get("info").get("title"), {"href": url}, ku.art(data.get("image")), data.get("info"), False) xbmcplugin.setPluginCategory(plugin.handle, ku.localize(32005)) # Recent xbmcplugin.endOfDirectory(plugin.handle)
def parse_mercury(soup): # type: (BeautifulSoup) -> None """Parses the mercury theater items (odd mark-up)""" for image in soup.select("a > img"): action = image.find_previous("a") parts = soup.select("a[href={}]".format(action.get("href"))) add_menu_item(play_film, parts[1].text.strip(), args={"href": action.get("href")}, art=ku.art(nfpfs.get_url(image.get("src"))), info={"plot": soup.find("h3").find_next("p").text}, directory=False)
def recent(): # type: () -> None """Show recently viewed films""" data = pas.recents.retrieve() for url in data: soup = pas.get_html(url) info = pas.get_info(soup) add_menu_item(play_film, info.get("title"), args={"href": url}, art=ku.art(pas.get_url(info.get("image"))), info=info.get("info"), directory=False) xbmcplugin.setPluginCategory(plugin.handle, ku.localize(32005)) # Recent xbmcplugin.endOfDirectory(plugin.handle)
def search(): query = get_arg("q") href = get_arg("href", False) # remove saved search item if bool(get_arg("delete", False)): jafc.remove(query) xbmc.executebuiltin("Container.Refresh()") return True # View saved search menu if bool(get_arg("menu", False)): add_menu_item(search, "[{}]".format(ku.localize(32016)), {"new": True}) # [New Search] for item in jafc.retrieve(): text = item.encode("utf-8") add_menu_item( search, text, args={"q": text}) xbmcplugin.setPluginCategory(plugin.handle, ku.localize(32007)) # Search xbmcplugin.endOfDirectory(plugin.handle) return True # look-up if bool(get_arg("new", False)): query = ku.user_input() jafc.append(query) if not query: return False url = jafc.get_url(href) if href else jafc.get_search_url(query) data = jafc.get_html(url) results = data.find("ul", "work-results") if not results: return paginate(data.find("ul", "pager-menu"), search) for item in results.find_all("li", "work-result"): action = item.find("a") img = item.find("img", "thumbnail") add_menu_item(play_film, item.find("h2").text, args={"href": action["href"]}, info=jafc.get_info(action["href"]), art=ku.art(jafc.get_url(img["src"])), directory=False) xbmcplugin.setPluginCategory(plugin.handle, "{} '{}'".format(ku.localize(32016), query)) xbmcplugin.endOfDirectory(plugin.handle)
def new(): # type: () -> Union[None, bool] data = iwm.post_form({"zoneID": 6}) if data is None: return False for item in data["cellTokens"]: title, plot = item["overlay"].split("\n<BR>", 1) add_menu_item( play_film, iwm.clean_title(title), args={"href": "/record/{}".format(item["recordID"])}, info={"plot": plot.replace("<BR>", "")}, art=ku.art(iwm.get_image_url(item["imageStyle"])), directory=False) xbmcplugin.setPluginCategory(plugin.handle, ku.localize(32004)) # New Content xbmcplugin.endOfDirectory(plugin.handle)
def recent(): """Show recently viewed films""" data = jafc.get_recent() for item in data: token = jafc.pluck(item["uri"], "nfc/", "_en") info = jafc.get_info(token) if info is None: continue add_menu_item( play_film, info["title"], args={"href": token}, info=info, art=ku.art(jafc.get_url(jafc.get_image(token))), directory=False) xbmcplugin.setPluginCategory(plugin.handle, ku.localize(32026)) # Recently Viewed xbmcplugin.endOfDirectory(plugin.handle)
def authors(): """List of authors""" url = jafc.get_url("en/writer.html") data = jafc.get_html(url) container = data.find("ul", "writer-results") for item in container.find_all("li"): action = item.find("a") if action is None: continue add_menu_item(films, action.text, args={"href": "en/{}".format(action["href"]), "title": action.text}, info={"plot": item.find("div", "writer-result-description").text}, art=ku.art(jafc.get_url(item.find("img", "thumbnail")["src"]))) xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_LABEL) xbmcplugin.setPluginCategory(plugin.handle, ku.localize(32004)) # Authors xbmcplugin.endOfDirectory(plugin.handle)
def search(): query = get_arg("q") href = get_arg("href", False) # remove saved search item if bool(get_arg("delete", False)): jafc.remove(query) xbmc.executebuiltin("Container.Refresh()") return True # View saved search menu if bool(get_arg("menu", False)): add_menu_item(search, "[{}]".format(ku.get_string(32016)), {"new": True}) # [New Search] for item in jafc.retrieve(): text = item.encode("utf-8") add_menu_item(search, text, {"q": text}) xp.setPluginCategory(plugin.handle, ku.get_string(32007)) # Search xp.endOfDirectory(plugin.handle) return True # look-up if bool(get_arg("new", False)): query = ku.user_input() jafc.append(query) if not query: return False url = jafc.get_page_url(href) if href else jafc.get_search_url(query) data = jafc.get_html(url) results = data.find("ul", "work-results") if not results: return paginate(data.find("ul", "pager-menu"), search) for item in results.find_all("li", "work-result"): action = item.find("a") img = item.find("img", "thumbnail") add_menu_item(play_film, item.find("h2").text, {"href": action["href"]}, info=get_info(action["href"]), art=ku.art(jafc.get_page_url(img["src"])), directory=False) xp.setPluginCategory(plugin.handle, "{} '{}'".format(ku.get_string(32016), query)) xp.endOfDirectory(plugin.handle)
def authors(): """List of authors""" url = jafc.get_page_url("en/writer.html") data = jafc.get_html(url) container = data.find("ul", "writer-results") for item in container.find_all("li"): img = item.find("img", "thumbnail") action = item.find("a") if action is None: continue add_menu_item(films, action.text, args={ "href": "en/{}".format(action["href"]), "title": action.text }, info={ "plot": item.find("div", "writer-result-description").text }, art=ku.art(jafc.get_page_url(img["src"]))) xp.addSortMethod(plugin.handle, xp.SORT_METHOD_LABEL) xp.endOfDirectory(plugin.handle)
def recent(): # type: () -> None """Show recently viewed films""" data = nfpfs.recents.retrieve() for url in data: soup = nfpfs.get_html(url) info = nfpfs.get_info(soup) add_menu_item(play_film, info.get("title"), args={"href": url}, art=ku.art(info.get("image")), info=info.get("info"), directory=False) xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE) xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_VIDEO_YEAR) xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_GENRE) xbmcplugin.setPluginCategory(plugin.handle, ku.localize(32005)) # Recent xbmcplugin.setContent(plugin.handle, "videos") xbmcplugin.endOfDirectory(plugin.handle)
def show_category(): # type: () -> None """Shows the category menu (based on supplied key)""" key = get_arg("key", "category") href = get_arg("href", "free") target = get_arg("target") sub_directory = bool(get_arg("sub_directory", False)) category = get_arg("title", ku.localize(32008)) soup = bfis.get_html(bfis.get_page_url(href)) for card in soup.find_all(*JIG[key]["card"]): action = card.find(["a", "card__action"]) if action is None: continue plot_tag = card.find(*JIG[key]["plot"]) title = action["aria-label"].encode("utf-8") info = {"plot": plot_tag.text if plot_tag else "", "genre": []} if "meta" in JIG[key]: bfis.parse_meta_info(card.find_all(*JIG[key]["meta"]), info) if target == "play-kermode-introduces": del info["duration"] add_menu_item(show_category if sub_directory else play_film, title, args={ "href": action["href"], "title": title, "target": target }, art=ku.art(bfis.BFI_URI, card.find("img").attrs), info=info, directory=sub_directory) xbmcplugin.setPluginCategory(plugin.handle, category) xbmcplugin.setContent(plugin.handle, "videos") xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE) xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_GENRE) xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_VIDEO_YEAR) xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_DURATION) xbmcplugin.endOfDirectory(plugin.handle)
def parse_search_results(query, offset, data): # type: (str, int, dict) -> Union[None, bool] """Adds menu items for search result data""" if data is None or not data["results"]: return False paginate(query, len(data["results"]), int(data["ttlResults"]), offset) for child in data["results"]: add_menu_item( play_film, iwm.clean_title(child["Title"]), args={"href": child["url"]}, info={ "year": child["fieldClasses"]["date"], "plot": child["Summary"], "duration": iwm.time_to_seconds(child["mediaObjectDuration"]) }, art=ku.art(child["refImageUrl"]), directory=False) xbmcplugin.setContent(plugin.handle, "videos") xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE) xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_VIDEO_YEAR) xbmcplugin.endOfDirectory(plugin.handle)
def show_category(): key = get_arg("key", "category") href = get_arg("href", "free") is_dir = bool(get_arg("isdir", False)) category = get_arg("title", ku.get_string(32008)) url = bfis.get_page_url(href) html = bfis.get_html(url) for card in html.findAll(*JIG[key]["card"]): action = card.find(*JIG[key]["action"]) if action is None: continue title = card.find(*JIG[key]["title"]).text.encode("utf-8") info = { "mediatype": "video", "plot": bfis.html_to_text( card.find(*JIG[key]["plot"]).text.encode("utf-8")) } if "meta" in JIG[key]: try: genre, year, duration = card.find_all(*JIG[key]["meta"], limit=3) info["genre"] = genre.text.encode("utf-8") info["year"] = bfis.text_to_int(year.text.encode("utf-8")) info["duration"] = bfis.text_to_int( duration.text.encode("utf-8")) except (ValueError, TypeError): pass add_menu_item(show_category if is_dir else play_film, title, { "href": action["href"], "title": title }, ku.art(card.find("img").attrs), info, is_dir) xp.setPluginCategory(plugin.handle, category) xp.setContent(plugin.handle, "videos") xp.addSortMethod(plugin.handle, xp.SORT_METHOD_LABEL_IGNORE_THE) xp.addSortMethod(plugin.handle, xp.SORT_METHOD_GENRE) xp.endOfDirectory(plugin.handle)
def parse_search_results(soup, url, total, category): # type: (BeautifulSoup, str, int, str) -> None """Adds menu items for search result data""" items = soup.find_all("div", {"data-mediatype": "movies"}) count = len(items) if count == 0 or total == 0: logger.debug("parse_search_results no results: {}".format(url)) return paginate(url, count, total, category) for item in items: container = item.find("div", "C234").extract() action = container.find("a").extract() plot = item.find_next("div", "details-ia").find("div", "C234").find("span") add_menu_item(play_film, action.find("div", "ttl").text.strip(), args={"href": action.get("href")}, art=ku.art(pas.get_url(action.find("img", "item-img")["source"])), info={"plot": plot.text if plot else "", "year": item.get("data-year", 0)}, directory=False) xbmcplugin.setContent(plugin.handle, "videos") xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE) xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_VIDEO_YEAR)
def parse_search_results(soup, url, method, category): # type: (BeautifulSoup, str, callable, str) -> None """Adds menu items for search result data""" items = soup.find_all("div", "hov") paginate(soup, url, method, category) for item in items: action = item.find("a") img = action.find("img").get("src") date, time = dws.get_date_time(action.find("span", "date").text) plot = action.find("p") add_menu_item(play_film, action.find("h2").contents[0], {"href": dws.get_url(action.get("href"))}, ku.art(dws.get_url(img)), { "plot": plot.text if plot else "", "date": date.strip(), "duration": time }, False) xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_DATE) xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_DURATION) xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE)
def show_category(): key = get_arg("key", "category") href = get_arg("href", "free") is_dir = bool(get_arg("isdir", False)) category = get_arg("title", ku.get_string(32008)) url = bfis.get_page_url(href) html = bfis.get_html(url) for card in html.findAll(*JIG[key]["card"]): action = card.find(*JIG[key]["action"]) if action is None: continue title = card.find(*JIG[key]["title"]).text.encode("utf-8") info = { "mediatype": "video", "plot": bfis.html_to_text(card.find(*JIG[key]["plot"]).text.encode("utf-8")) } if "meta" in JIG[key]: try: genre, year, duration = card.find_all(*JIG[key]["meta"], limit=3) info["genre"] = genre.text.encode("utf-8") info["year"] = bfis.text_to_int(year.text.encode("utf-8")) info["duration"] = bfis.text_to_int(duration.text.encode("utf-8")) except (ValueError, TypeError): pass add_menu_item( show_category if is_dir else play_film, title, {"href": action["href"], "title": title}, ku.art(card.find("img").attrs), info, is_dir ) xp.setPluginCategory(plugin.handle, category) xp.setContent(plugin.handle, "videos") xp.addSortMethod(plugin.handle, xp.SORT_METHOD_LABEL_IGNORE_THE) xp.addSortMethod(plugin.handle, xp.SORT_METHOD_GENRE) xp.endOfDirectory(plugin.handle)
def parse_search_results(soup, url, category): # type: (BeautifulSoup, str) -> None """Adds menu items for search result data""" paginate(soup, url, category) table = soup.find("table", "search_results") if not table: logger.debug("No result data: '{}' '{}'".format(category, url)) return data = table.extract() rows = data.find_all("tr") for row in rows: td = row.find("td", "search_results_image") if not td: continue img = td.find("img")["src"] action = row.select("h4 > a")[0] info = {"plot": row.find_all("p")[1].text} add_menu_item(play_film, action.text.title(), {"href": action["href"]}, ku.art(img), info, False) xbmcplugin.setContent(plugin.handle, "videos") xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE) xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_DURATION)
def live(): soup = dws.get_html(dws.DW_MEDIA_LIVE_URI) items = soup.find_all("div", "mediaItem") for item in items: title = item.find("input", { "name": "media_title" }).get("value").encode("utf-8") preview_image = dws.get_url( item.find("input", { "name": "preview_image" }).get("value")) add_menu_item( play_film, item.find("input", { "name": "channel_name" }).get("value"), { "m3u8": item.find("input", { "name": "file_name" }).get("value"), "title": title }, ku.art(preview_image), {"plot": title}, False) xbmcplugin.setContent(plugin.handle, "tvshows") xbmcplugin.setPluginCategory(plugin.handle, ku.localize(32006)) # Live TV xbmcplugin.endOfDirectory(plugin.handle)
def search(): query = get_arg("q") offset = int(get_arg("offset", 0)) # remove saved search item if bool(get_arg("delete", False)): bfis.remove(query) xbmc.executebuiltin("Container.Refresh()") return True # View saved search menu if bool(get_arg("menu", False)): add_menu_item(search, "[{}]".format(ku.get_string(32016)), {"new": True}) # [New Search] for item in bfis.retrieve(): text = item.encode("utf-8") add_menu_item(search, text, {"q": text}) xp.setPluginCategory(plugin.handle, ku.get_string(32007)) # Search xp.endOfDirectory(plugin.handle) return True # look-up if bool(get_arg("new", False)): query = ku.user_input() bfis.append(query) if not query: return False search_url = bfis.get_search_url(query, offset) data = bfis.get_json(search_url) if data is None: return False hits = data.get("hits", False) if not hits: return False # Results results = hits.get("hits", []) paginate(query, len(results), int(hits.get("total", 0)), offset) for element in results: data = element.get("_source", False) if not data: continue title = data.get("title", "") duration = data.get("duration", 0) # can still be NoneType * info = { "originaltitle": data.get("original_title", ""), "plot": bfis.html_to_text(data.get("standfirst", "")), "genre": data.get("genre", ""), "cast": data.get("cast", ""), "director": data.get("director", ""), "year": int(data.get("release_date", 0)), "duration": 0 if duration is None else int(duration) * 60, # * "mediatype": "video" } add_menu_item( play_film, title, {"href": data.get("url")}, ku.art(data.get("image", ["Default.png"])[0]), info, False) xp.setContent(plugin.handle, "videos") xp.setPluginCategory(plugin.handle, "{} '{}'".format(ku.get_string(32007), bfis.query_decode(query))) xp.addSortMethod(plugin.handle, xp.SORT_METHOD_LABEL_IGNORE_THE) xp.addSortMethod(plugin.handle, xp.SORT_METHOD_GENRE) xp.addSortMethod(plugin.handle, xp.SORT_METHOD_VIDEO_YEAR) xp.addSortMethod(plugin.handle, xp.SORT_METHOD_DURATION) xp.endOfDirectory(plugin.handle)