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 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 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 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 section(): # type: () -> None """Handles the various sections such as years, genre, series, etc""" href = get_arg("href", False) token = get_arg("token", False) category = get_arg("category") if not href and token: # Section menu soup = mias.get_html(mias.get_search_url()) element = soup.find("ul", {"id": token}) if not element: logger.debug("No menu data: {}".format(token)) return items = element.extract().findAll("li") for item in items: action = item.find("a") if not action: continue title = action.text.title() add_menu_item(section, title, args={ "href": action["href"], "category": title }) else: # Section playable items url = mias.get_url(href) soup = mias.get_html(url) parse_search_results(soup, url, category) xbmcplugin.setPluginCategory(plugin.handle, category) xbmcplugin.endOfDirectory(plugin.handle)
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 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 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 play_film(): # type: () -> None """Show playable item""" href = get_arg("href") url = mias.get_url(href) details = mias.get_info(url) mias.recents.append(url) list_item = ListItem(path=details["m3u8"]) list_item.setInfo("video", details["info"]) xbmcplugin.setResolvedUrl(plugin.handle, True, list_item)
def new(): # type: () -> None """Shows new playable items menu""" href = get_arg("href", ngs.NG_URI) soup = ngs.get_html(ngs.get_url(href)) parse_search_results( soup.find("div", { "id": "grid-frame" }).extract(), ku.localize(32006), new) xbmcplugin.setPluginCategory(plugin.handle, ku.localize(32006)) 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 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 play_film(): # type: () -> None """Show playable item""" href = get_arg("href") url = pas.get_url(href) soup = pas.get_html(url) data = pas.get_info(soup) if not data.get("video"): logger.debug("play_film error: {}".format(href)) return if pas.RECENT_SAVED: pas.recents.append(url) list_item = ListItem(path=data.get("video")) list_item.setInfo("video", data.get("info")) xbmcplugin.setResolvedUrl(plugin.handle, True, list_item)
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 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 themes(): """List of directory menu items for each theme""" url = jafc.get_url(get_arg("href")) data = jafc.get_html(url) element = data.find("ul", { "class": ["category-condition-keyword", "work-favorites-condition-keyword"] }) for item in element.find_all("li"): action = item.find("a") span = action.find("span") if span: span.extract() add_menu_item( films, action.text, args={"href": action["href"], "title": action.text}) xbmcplugin.setPluginCategory(plugin.handle, get_arg("title")) xbmcplugin.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 section(): # type: () -> None """Show category menu and category playable items""" href = get_arg("href") category = get_arg("category", ku.localize(32002)) if not href: # category menu soup = ngs.get_html(ngs.NG_URI) menu = soup.find("ul", "dropdown-menu").extract() for item in menu.find_all("li"): action = item.find("a") add_menu_item(section, action.text, args={ "href": action.get("href"), "category": action.text }) else: # playable items soup = ngs.get_html(ngs.get_url(href)) parse_search_results(soup, category, section) xbmcplugin.setPluginCategory(plugin.handle, category) xbmcplugin.endOfDirectory(plugin.handle)
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)