def list_shows_stations_shows(stationId, page, label): xbmcplugin.setPluginCategory(_handle, label) page = int(page) page_size = int(addon.getSetting("page_size")) station = get_station_from_stationId(stationId) data = call_api(url="https://api.mujrozhlas.cz/stations/" + stationId + "/shows?page[limit]=" + str(page_size) + "&page[offset]=" + str((page - 1) * page_size)) if "err" in data: xbmcgui.Dialog().notification("ČRo", "Problém při získání pořadů", xbmcgui.NOTIFICATION_ERROR, 4000) sys.exit() if "data" in data and len(data["data"]) > 0: items_count = int(data["meta"]["count"]) for show in data["data"]: cast = [] list_item = xbmcgui.ListItem(label=show["attributes"]["title"]) list_item.setArt({ "thumb": show["attributes"]["asset"]["url"], "icon": show["attributes"]["asset"]["url"] }) list_item.setInfo( "video", { "title": show["attributes"]["title"], "director": [show["attributes"]["asset"]["credit"]["author"]], "plot": show["attributes"]["description"], "studio": station }) if "participants" in show["relationships"] and len( show["relationships"]["participants"]["data"]) > 0: for person in show["relationships"]["participants"]["data"]: cast.append(get_person(person["id"])) list_item.setInfo("video", {"cast": cast}) url = get_url(action='list_show', showId=show["id"], page=1, label=encode(show["attributes"]["title"])) menus = [ ("Přidat k oblíbeným pořadům", "RunPlugin(plugin://plugin.audio.cro?action=add_favourites&showId=" + str(show["id"]) + "&others=0)"), ("Přidat k ostatním obl. pořadům", "RunPlugin(plugin://plugin.audio.cro?action=add_favourites&showId=" + str(show["id"]) + "&others=1)") ] list_item.addContextMenuItems(menus) xbmcplugin.addDirectoryItem(_handle, url, list_item, True) if page * page_size <= items_count: list_item = xbmcgui.ListItem(label="Následující strana") url = get_url(action='list_shows_stations_shows', stationId=stationId, page=page + 1, label=label) xbmcplugin.addDirectoryItem(_handle, url, list_item, True) xbmcplugin.endOfDirectory(_handle) else: xbmcgui.Dialog().notification("ČRo", "Nenalezen žádný pořad", xbmcgui.NOTIFICATION_WARNING, 4000) sys.exit()
def list_search(label): list_item = xbmcgui.ListItem(label="Podle názvu") url = get_url(action='list_search_title', label="Vyhledávání podle názvu") xbmcplugin.addDirectoryItem(_handle, url, list_item, True) list_item = xbmcgui.ListItem(label="Podle osoby") url = get_url(action='list_search_person', label="Vyhledávání podle osoby") xbmcplugin.addDirectoryItem(_handle, url, list_item, True) xbmcplugin.endOfDirectory(_handle)
def list_program_week(stationId, startdate, enddate, label): xbmcplugin.setPluginCategory(_handle, label) mindate, maxdate = get_minmax_days(stationId) startDoW = parse_datetime(startdate) - timedelta(days=7) - timedelta( days=parse_datetime(startdate).weekday()) endDoW = startDoW + timedelta(days=6) if endDoW >= mindate: list_item = xbmcgui.ListItem(label="<<<") url = get_url(action='list_program_week', stationId=stationId, startdate=startDoW.strftime("%d.%m.%Y"), enddate=endDoW.strftime("%d.%m.%Y"), label=label) xbmcplugin.addDirectoryItem(_handle, url, list_item, True) for i in range(7): day = parse_datetime(startdate) + timedelta(days=i) if day <= maxdate and day >= mindate: if datetime.now().strftime("%d.%m.%Y") == day.strftime("%d.%m.%Y"): list_item = xbmcgui.ListItem(label="Dnes") else: list_item = xbmcgui.ListItem(label=day.strftime("%d.%m.%Y")) url = get_url(action='list_program_day', stationId=stationId, day=day.strftime("%d.%m.%Y"), label=label + day.strftime("%d.%m.%Y")) xbmcplugin.addDirectoryItem(_handle, url, list_item, True) list_item = xbmcgui.ListItem(label="Přejít na datum") url = get_url(action='program_set_week', stationId=stationId, startdate=startdate, enddate=enddate, label=label) xbmcplugin.addDirectoryItem(_handle, url, list_item, True) startDoW = parse_datetime(startdate) + timedelta(days=7) - timedelta( days=parse_datetime(startdate).weekday()) endDoW = startDoW + timedelta(days=6) if startDoW <= maxdate: list_item = xbmcgui.ListItem(label=">>>") url = get_url(action='list_program_week', stationId=stationId, startdate=startDoW.strftime("%d.%m.%Y"), enddate=endDoW.strftime("%d.%m.%Y"), label=label) xbmcplugin.addDirectoryItem(_handle, url, list_item, True) xbmcplugin.endOfDirectory(_handle)
def list_topics(label): xbmcplugin.setPluginCategory(_handle, label) data = call_api(url="https://api.mujrozhlas.cz/topics") if "err" in data: xbmcgui.Dialog().notification("ČRo", "Problém při získání seznamu témat", xbmcgui.NOTIFICATION_ERROR, 4000) sys.exit() if "data" in data and len(data["data"]) > 0: for topic in data["data"]: if "attributes" in topic and "title" in topic[ "attributes"] and len(topic["attributes"]["title"]) > 0: topicId = topic["id"] list_item = xbmcgui.ListItem( label=topic["attributes"]["title"]) url = get_url(action='list_topic', topicId=topicId, label=label + " / " + encode(topic["attributes"]["title"])) list_item.setArt({ "thumb": topic["attributes"]["asset"]["url"], "icon": topic["attributes"]["asset"]["url"] }) xbmcplugin.addDirectoryItem(_handle, url, list_item, True) xbmcplugin.endOfDirectory(_handle) else: xbmcgui.Dialog().notification("ČRo", "Problém při získání seznamu témat", xbmcgui.NOTIFICATION_ERROR, 4000) sys.exit()
def signin(): if check_env(): usr = (get_env_values())['username'] pwd = (get_env_values())['password'] else: usr = get_username() pwd = get_password() json_data = {"username": usr, "password": pwd} url = util.get_url('login') try: respons = requests.post(url, json_data) respons = respons.json() except Exception as e: msg = "Login failure ! \n" + str(e) print(msg) return util.generate_respons(False, msg) else: if respons["code"] != 200: print(respons["message"]) return util.generate_respons(False, respons["message"]) data = respons["data"] send_todb(data['user_id'], data['project_id']) now = datetime.datetime.now() timestamp = now.strftime("%Y%m%d%H%M%S%f") create_env_file(usr, pwd, data["user_id"], data["project_id"], data["token"], timestamp) generate_session(data["user_id"], data["project_id"], data["token"]) return util.generate_respons(True, "success", data)
def get_data(endpoint, key=None, tags=None, value=None): headers = auth.get_headers() url = util.get_url(endpoint) try: res = requests.get(url=url, headers=headers['data']) res = res.json() res = res['data'] check = bool(tags) & bool(value) data = list() if key != None and not check: data = list() for i in res: data.append(i[key]) elif key == None and check: data = list() for i in res: if i[tags] == value: data = i elif bool(key) & check: for i in res: if i[tags] == value: data.append(i[key]) else: data = res return util.generate_respons(True, "success", data) except Exception as e: util.log_err(e) return util.generate_respons(False, str(e))
def send_todb(user_id, project_id): data = {"project_id": project_id, "user_id": user_id} headers = {'Content-Type': "application/json"} try: url = util.get_url('user') requests.post(url=url, data=json.dumps(data), headers=headers) except Exception as e: util.log_err(str(e))
def list_show(showId, page, label, mark_new = 0): page = int(page) page_size = int(addon.getSetting("page_size")) show = get_show(showId) xbmcplugin.setPluginCategory(_handle, label) data = call_api(url = "https://api.mujrozhlas.cz/shows/" + showId + "/episodes?sort=-since&page[limit]=" + str(page_size) + "&page[offset]=" + str((page-1)*page_size)) if "err" in data: xbmcgui.Dialog().notification("ČRo","Problém při získání pořadů", xbmcgui.NOTIFICATION_ERROR, 4000) sys.exit() if "data" in data and len(data["data"]) > 0: items_count = int(data["meta"]["count"]) for episode in data["data"]: if "attributes" in episode and "title" in episode["attributes"] and len(episode["attributes"]["title"]) > 0: starttime = parse_date(episode["attributes"]["since"]) if "mirroredSerial" in episode["attributes"] and "totalParts" in episode["attributes"]["mirroredSerial"] and "part" in episode["attributes"]: parts = " (" + str(episode["attributes"]["part"]) + "/" + str(episode["attributes"]["mirroredSerial"]["totalParts"]) + ") " else: parts = "" title = episode["attributes"]["title"] + parts + " (" + starttime.strftime("%d.%m.%Y %H:%M") + ")" from libs.favourites import get_listened link = episode["attributes"]["audioLinks"][0]["url"] if int(mark_new) == 1 and not get_listened(episode["id"]): list_item = xbmcgui.ListItem(label="* " + title) else: list_item = xbmcgui.ListItem(label=title) list_item.setArt({ "thumb" : show["img"], "icon" : show["img"] }) list_item.setInfo( "video", { "tvshowtitle" : show["title"], "title" : title, "aired" : starttime.strftime("%Y-%m-%d"), "director" : [show["director"]] , "plot" : show["description"], "studio" : show["station"] }) if len(show["cast"]) > 0: list_item.setInfo( "video", { "cast" : show["cast"] }) list_item.setProperty("IsPlayable", "true") list_item.setContentLookup(False) url = get_url(action='play', url = encode(link), showId = showId, episodeId = episode["id"], title = encode(title), img = show["img"]) if PY2: xbmcplugin.addDirectoryItem(_handle, url, list_item, False) else: xbmcplugin.addDirectoryItem(_handle, url, list_item, True) if page * page_size <= items_count: list_item = xbmcgui.ListItem(label="Následující strana") url = get_url(action='list_show', showId = showId, page = page + 1, label = label, mark_new = mark_new) xbmcplugin.addDirectoryItem(_handle, url, list_item, True) xbmcplugin.endOfDirectory(_handle, cacheToDisc = False) else: xbmcgui.Dialog().notification("ČRo","Problém při získání pořadů", xbmcgui.NOTIFICATION_ERROR, 4000) sys.exit()
def list_shows_stations(label): xbmcplugin.setPluginCategory(_handle, label) stations, stations_nums = get_stations(filtered=1) for num in sorted(stations_nums.keys()): list_item = xbmcgui.ListItem(label=stations[stations_nums[num]]["title"]) url = get_url(action='list_shows_stations_shows', stationId = stations[stations_nums[num]]["id"], page = 1, label = encode(stations[stations_nums[num]]["title"])) list_item.setArt({ "thumb" : stations[stations_nums[num]]["img"], "icon" : stations[stations_nums[num]]["img"] }) xbmcplugin.addDirectoryItem(_handle, url, list_item, True) xbmcplugin.endOfDirectory(_handle)
def do_search(query, label): xbmcplugin.setPluginCategory(_handle, label) if query == "-----": input = xbmc.Keyboard("", "Hledat") input.doModal() if not input.isConfirmed(): return query = input.getText() if len(query) == 0: xbmcgui.Dialog().notification( "ČRo", "Je potřeba zadat vyhledávaný řetězec", xbmcgui.NOTIFICATION_ERROR, 4000) return else: save_search_history(query) shows = {} shows_ordered = {} shows, shows_ordered = search_episodes(shows, shows_ordered, "title", query) #shows, shows_ordered = search_episodes(shows, shows_ordered, "description", query) shows, shows_ordered = search_shows(shows, shows_ordered, "title", query) #shows, shows_ordered = search_shows(shows, shows_ordered, "description", query) if len(shows) > 0: for key in sorted(shows_ordered, key=shows.get('id')): show = shows[key] list_item = xbmcgui.ListItem(label=show["title"]) list_item.setArt({"thumb": show["img"], "icon": show["img"]}) list_item.setInfo( "video", { "title": show["title"], "director": [show["director"]], "plot": show["description"], "studio": show["station"] }) if len(show["cast"]) > 0: list_item.setInfo("video", {"cast": show["cast"]}) menus = [ ("Přidat k oblíbeným pořadům", "RunPlugin(plugin://plugin.audio.cro?action=add_favourites&showId=" + str(show["id"]) + "&others=0)"), ("Přidat k ostatním obl. pořadům", "RunPlugin(plugin://plugin.audio.cro?action=add_favourites&showId=" + str(show["id"]) + "&others=1)") ] list_item.addContextMenuItems(menus) url = get_url(action='list_show', showId=show["id"], page=1, label=encode(show["title"])) xbmcplugin.addDirectoryItem(_handle, url, list_item, True) else: xbmcgui.Dialog().notification("ČRo", "Nic nebylo nalezeno", xbmcgui.NOTIFICATION_WARNING, 4000) xbmcplugin.endOfDirectory(_handle)
def send_request(endpoint, data): headers = get_headers() headers = headers['data'] url = get_url(endpoint) try: result = requests.post(url=url, data=json.dumps(data), headers=headers) respons = result.json() except Exception as e: respons = generate_respons(False, str(e)) return respons
def list_search_person(label): xbmcplugin.setPluginCategory(_handle, label) list_item = xbmcgui.ListItem(label="Nové hledání") url = get_url(action='do_search', query="-----", label=label + " / " + "Nové hledání") xbmcplugin.addDirectoryItem(_handle, url, list_item, True) history = load_search_history_person() for item in history: list_item = xbmcgui.ListItem(label=item) url = get_url(action='do_search_person', query=item, label=label + " / " + item) list_item.addContextMenuItems([( "Smazat", "RunPlugin(plugin://plugin.audio.cro?action=delete_search_person&query=" + quote(item) + ")")]) xbmcplugin.addDirectoryItem(_handle, url, list_item, True) xbmcplugin.endOfDirectory(_handle, cacheToDisc=False)
def listing_endpoint(endpoint): with open('libs/templates/var.json', 'r') as f: var_json = json.load(f) url = util.get_url(endpoint) headers = auth.get_headers() result = requests.get(url, headers=headers['data']) result = result.json() result = result['data'] key = var_json['key'][endpoint] st = '' if result: for i in result: st += i[key] + '\t' else: "No value available" return st
def searchId(endpoint, name): data = dict() data = jsonmodel['search'][endpoint]['data'] url = get_url(endpoint) keys = list(data['where']['tags'].keys()) headers = get_headers() headers = headers['data'] for i in keys: if 'id' not in i: key = i data['where']['tags'][key] = str(name) try: res = requests.post(url=url, data=json.dumps(data), headers=headers) res = res.json() res = res['data'] respons = res[0][get_idkey(endpoint, headers=headers)] except Exception as e: return generate_respons(False, str(e)) return generate_respons(True, 'success', respons)
def list_stations(label): xbmcplugin.setPluginCategory(_handle, label) stations, stations_nums = get_stations(filtered=0) for num in sorted(stations_nums.keys()): if int(stations[stations_nums[num]]["enabled"]) == 0: list_item = xbmcgui.ListItem( label="[COLOR red]" + stations[stations_nums[num]]["title"] + "[/COLOR]") else: list_item = xbmcgui.ListItem( label=stations[stations_nums[num]]["title"]) url = get_url(action='toogle_station', stationId=stations[stations_nums[num]]["id"]) list_item.setArt({ "thumb": stations[stations_nums[num]]["img"], "icon": stations[stations_nums[num]]["img"] }) xbmcplugin.addDirectoryItem(_handle, url, list_item, False) xbmcplugin.endOfDirectory(_handle)
def list_program(label): now = datetime.now() startDoW = now - timedelta(days=now.weekday()) endDoW = startDoW + timedelta(days=6) xbmcplugin.setPluginCategory(_handle, label) stations, stations_nums = get_stations(filtered=1) for num in sorted(stations_nums.keys()): list_item = xbmcgui.ListItem( label=stations[stations_nums[num]]["title"]) url = get_url(action='list_program_week', stationId=stations[stations_nums[num]]["id"], startdate=startDoW.strftime("%d.%m.%Y"), enddate=endDoW.strftime("%d.%m.%Y"), label=encode(stations[stations_nums[num]]["title"])) list_item.setArt({ "thumb": stations[stations_nums[num]]["img"], "icon": stations[stations_nums[num]]["img"] }) xbmcplugin.addDirectoryItem(_handle, url, list_item, True) xbmcplugin.endOfDirectory(_handle)
def list_live(label): xbmcplugin.setPluginCategory(_handle, label) stations, stations_nums = get_stations(filtered=1) schedule = get_current_schedule() urls = get_urls() for num in sorted(stations_nums.keys()): info = {} if stations[stations_nums[num]]["id"] in urls: if stations[stations_nums[num]]["id"] in schedule: title = stations[ stations_nums[num]]["title"] + " - " + schedule[stations[ stations_nums[num]]["id"]]["show"] + " (" + schedule[ stations[stations_nums[num]] ["id"]]["start"] + " - " + schedule[stations[ stations_nums[num]]["id"]]["end"] + ")" info = { "title": schedule[stations[stations_nums[num]]["id"]]["show"], "plot": schedule[stations[stations_nums[num]]["id"]]["title"] } else: title = stations[stations_nums[num]]["title"] list_item = xbmcgui.ListItem(label=title) if "img" in stations[stations_nums[num]] and len( stations[stations_nums[num]]["img"]) > 0: img = stations[stations_nums[num]]["img"] list_item.setArt({"thumb": img, "icon": img}) else: img = "xxx" url = get_url(action='play_live', url=urls[stations[stations_nums[num]]["id"]], title=encode(title), img=img) if len(info) > 0: list_item.setInfo("music", info) xbmcplugin.addDirectoryItem(_handle, url, list_item, True) xbmcplugin.endOfDirectory(_handle)
def list_menu(): icons_dir = os.path.join(addon.getAddonInfo('path'), 'resources', 'images') list_item = xbmcgui.ListItem(label="Živě") url = get_url(action='list_live', label="Živě") list_item.setArt({ "thumb": os.path.join(icons_dir, 'live.png'), "icon": os.path.join(icons_dir, 'live.png') }) xbmcplugin.addDirectoryItem(_handle, url, list_item, True) # list_item = xbmcgui.ListItem(label="Program") # url = get_url(action='list_program', label = "Program") # xbmcplugin.addDirectoryItem(_handle, url, list_item, True) list_item = xbmcgui.ListItem(label="Pořady") url = get_url(action='list_shows_stations', label="Pořady") list_item.setArt({ "thumb": os.path.join(icons_dir, 'shows.png'), "icon": os.path.join(icons_dir, 'shows.png') }) xbmcplugin.addDirectoryItem(_handle, url, list_item, True) list_item = xbmcgui.ListItem(label="Témata") url = get_url(action='list_topics', label="Témata") list_item.setArt({ "thumb": os.path.join(icons_dir, 'themes.png'), "icon": os.path.join(icons_dir, 'themes.png') }) xbmcplugin.addDirectoryItem(_handle, url, list_item, True) list_item = xbmcgui.ListItem(label="Vyhledávání") url = get_url(action='list_search_title', label="Vyhledávání") list_item.setArt({ "thumb": os.path.join(icons_dir, 'search.png'), "icon": os.path.join(icons_dir, 'search.png') }) xbmcplugin.addDirectoryItem(_handle, url, list_item, True) list_item = xbmcgui.ListItem(label="Oblíbené pořady") url = get_url(action='list_favourites', label="Oblíbené") list_item.setArt({ "thumb": os.path.join(icons_dir, 'favourites.png'), "icon": os.path.join(icons_dir, 'favourites.png') }) xbmcplugin.addDirectoryItem(_handle, url, list_item, True) others_favourites = get_favourites(others=1) if len(others_favourites) > 0: list_item = xbmcgui.ListItem(label="Ostatní oblíbené pořady") url = get_url(action='list_favourites', label="Ostatní", others=1) list_item.setArt({ "thumb": os.path.join(icons_dir, 'favourites_others.png'), "icon": os.path.join(icons_dir, 'favourites_others.png') }) xbmcplugin.addDirectoryItem(_handle, url, list_item, True) if addon.getSetting("hide_favourites_new") == "false": list_item = xbmcgui.ListItem( label="Nejnovější epizody oblíbených pořadů") url = get_url(action='list_favourites_new', label="Nejnovější") list_item.setArt({ "thumb": os.path.join(icons_dir, 'favourites_new.png'), "icon": os.path.join(icons_dir, 'favourites_new.png') }) xbmcplugin.addDirectoryItem(_handle, url, list_item, True) if addon.getSetting("hide_stations_settings") == "false": list_item = xbmcgui.ListItem(label="Nastavení stanic") url = get_url(action='list_stations', label="Nastavení stanic") list_item.setArt({ "thumb": os.path.join(icons_dir, 'settings.png'), "icon": os.path.join(icons_dir, 'settings.png') }) xbmcplugin.addDirectoryItem(_handle, url, list_item, True) xbmcplugin.endOfDirectory(_handle)
def list_topic_recommended(topicId, filtr, label): xbmcplugin.setPluginCategory(_handle, label) data = call_api(url="https://api.mujrozhlas.cz/topics/" + topicId) if "err" in data: xbmcgui.Dialog().notification("ČRo", "Problém při získání pořadů", xbmcgui.NOTIFICATION_ERROR, 4000) sys.exit() if "data" in data and len(data["data"]) > 0 and "attributes" in data[ "data"] and "widgets" in data["data"]["attributes"]: for widget in data["data"]["attributes"]["widgets"]: if "attributes" in widget and "title" in widget[ "attributes"] and encode( widget["attributes"]["title"]) == filtr: if "items" in widget["attributes"]: items = widget["attributes"]["items"] elif "entities" in widget["attributes"]: items = widget["attributes"]["entities"] for item in items: if "entity" in item and "type" in item["entity"]: if item["entity"]["type"] == "show": show = get_show(item["entity"]["id"]) list_item = xbmcgui.ListItem(label=show["title"]) list_item.setArt({ "thumb": show["img"], "icon": show["img"] }) list_item.setInfo( "video", { "title": show["title"], "director": [show["director"]], "plot": show["description"], "studio": show["station"] }) if len(show["cast"]) > 0: list_item.setInfo("video", {"cast": show["cast"]}) menus = [ ("Přidat k oblíbeným pořadům", "RunPlugin(plugin://plugin.audio.cro?action=add_favourites&showId=" + str(show["id"]) + "&others=0)"), ("Přidat k ostatním obl. pořadům", "RunPlugin(plugin://plugin.audio.cro?action=add_favourites&showId=" + str(show["id"]) + "&others=1)") ] list_item.addContextMenuItems(menus) url = get_url(action='list_show', showId=show["id"], page=1, label=encode(show["title"])) xbmcplugin.addDirectoryItem( _handle, url, list_item, True) if item["entity"]["type"] == "episode": show = get_show(item["entity"]["relationships"] ["show"]["data"]["id"]) starttime = parse_date( item["entity"]["attributes"]["since"]) title = item["entity"]["attributes"][ "mirroredShow"]["title"] + " - " + item[ "entity"]["attributes"][ "title"] + " (" + starttime.strftime( "%d.%m.%Y %H:%M") + ")" list_item = xbmcgui.ListItem(label=title) url = item["entity"]["attributes"]["audioLinks"][ 0]["url"] list_item.setArt({ "thumb": show["img"], "icon": show["img"] }) list_item.setInfo( "video", { "tvshowtitle": show["title"], "title": title, "aired": starttime.strftime("%Y-%m-%d"), "director": [show["director"]], "plot": show["description"], "studio": show["station"] }) if len(show["cast"]) > 0: list_item.setInfo("video", {"cast": show["cast"]}) list_item.setProperty("IsPlayable", "true") list_item.setContentLookup(False) url = get_url(action='play', url=url, showId=show["id"], episodeId=item["entity"]["id"], title=encode(title), img=show["img"]) if PY2: xbmcplugin.addDirectoryItem( _handle, url, list_item, False) else: xbmcplugin.addDirectoryItem( _handle, url, list_item, True) if "type" in item and item["type"] == "episode": show = get_show( item["relationships"]["show"]["data"]["id"]) starttime = parse_date(item["attributes"]["since"]) title = item["attributes"]["mirroredShow"][ "title"] + " - " + item["attributes"][ "title"] + " (" + starttime.strftime( "%d.%m.%Y %H:%M") + ")" url = item["attributes"]["audioLinks"][0]["url"] list_item = xbmcgui.ListItem(label=title) list_item.setArt({ "thumb": show["img"], "icon": show["img"] }) list_item.setInfo( "video", { "tvshowtitle": show["title"], "title": title, "aired": starttime.strftime("%Y-%m-%d"), "director": [show["director"]], "plot": show["description"], "studio": show["station"] }) if len(show["cast"]) > 0: list_item.setInfo("video", {"cast": show["cast"]}) list_item.setProperty("IsPlayable", "true") list_item.setContentLookup(False) url = get_url(action='play', url=url, showId=show["id"], episodeId=item["id"], title=encode(title), img=show["img"]) if PY2: xbmcplugin.addDirectoryItem( _handle, url, list_item, False) else: xbmcplugin.addDirectoryItem( _handle, url, list_item, True) xbmcplugin.endOfDirectory(_handle) else: xbmcgui.Dialog().notification("ČRo", "Problém při získání pořadů", xbmcgui.NOTIFICATION_ERROR, 4000) sys.exit()
def list_topic(topicId, label): xbmcplugin.setPluginCategory(_handle, label) data = call_api(url="https://api.mujrozhlas.cz/topics/" + topicId + "/episodes?page[limit]=100") if "err" in data: xbmcgui.Dialog().notification("ČRo", "Problém při získání pořadů", xbmcgui.NOTIFICATION_ERROR, 4000) sys.exit() if "data" in data and len(data["data"]) > 0: widgets = get_widgets(topicId) for widget in widgets: list_item = xbmcgui.ListItem(label=widget) list_item.setProperty("IsPlayable", "false") url = get_url(action='list_topic_recommended', topicId=topicId, filtr=encode(widget), label=label + " / " + encode(widget)) xbmcplugin.addDirectoryItem(_handle, url, list_item, True) shows = {} shows_added = [] for episode in data["data"]: if "attributes" in episode and "title" in episode[ "attributes"] and len(episode["attributes"]["title"]) > 0: if episode["relationships"]["show"]["data"][ "id"] not in shows_added: show = get_show( episode["relationships"]["show"]["data"]["id"]) shows.update({show["title"]: show}) shows_added.append(show["id"]) for key in sorted(shows.keys()): show = shows[key] list_item = xbmcgui.ListItem(label=show["title"]) list_item.setArt({"thumb": show["img"], "icon": show["img"]}) list_item.setInfo( "video", { "title": show["title"], "director": [show["director"]], "plot": show["description"], "studio": show["station"] }) if len(show["cast"]) > 0: list_item.setInfo("video", {"cast": show["cast"]}) menus = [ ("Přidat k oblíbeným pořadům", "RunPlugin(plugin://plugin.audio.cro?action=add_favourites&showId=" + str(show["id"]) + "&others=0)"), ("Přidat k ostatním obl. pořadům", "RunPlugin(plugin://plugin.audio.cro?action=add_favourites&showId=" + str(show["id"]) + "&others=1)") ] list_item.addContextMenuItems(menus) url = get_url(action='list_show', showId=show["id"], page=1, label=encode(show["title"])) list_item.setContentLookup(False) xbmcplugin.addDirectoryItem(_handle, url, list_item, True) xbmcplugin.endOfDirectory(_handle) else: xbmcgui.Dialog().notification("ČRo", "Problém při získání pořadů", xbmcgui.NOTIFICATION_ERROR, 4000) sys.exit()
def tying_zone(user_id,id_zone): header = (get_headers())['data'] header['user-id'] = str(user_id) data = {"id_zone" : str(id_zone)} url = get_url('userzone') res = requests.post(url = url, data = data, headers = header)
def list_shows_menu(label): list_item = xbmcgui.ListItem(label="Stanice") url = get_url(action='list_shows_stations', label="Stanice") xbmcplugin.addDirectoryItem(_handle, url, list_item, True) xbmcplugin.endOfDirectory(_handle)
def list_favourites(label, others=0): xbmcplugin.setPluginCategory(_handle, label) favourites = get_favourites(int(others)) favourites_ordered = {} for key in favourites: favourites_ordered.update({key: favourites[key]["title"]}) for showId in sorted(favourites_ordered, key=favourites_ordered.get): show = favourites[showId] if addon.getSetting( "hide_unlistened_favourites") == "false" and others == 0: unlistened = get_unlistened_count(showId) if unlistened > 0: list_item = xbmcgui.ListItem(label=show["title"] + " (" + str(unlistened) + decode(" nových)")) elif unlistened == 0: list_item = xbmcgui.ListItem(label=show["title"]) else: list_item = xbmcgui.ListItem(label=show["title"] + ' (nenalezený pořad)') else: list_item = xbmcgui.ListItem(label=show["title"]) list_item.setArt({"thumb": show["img"], "icon": show["img"]}) list_item.setInfo( "video", { "title": show["title"], "director": [show["director"]], "plot": show["description"], "studio": show["station"] }) if len(show["cast"]) > 0: list_item.setInfo("video", {"cast": show["cast"]}) menus = [( "Odstranit z oblíbených", "RunPlugin(plugin://plugin.audio.cro?action=delete_favourites&showId=" + str(show["id"]) + ")")] if others == 0: menus.append(( "Přesunout do ostatních", "RunPlugin(plugin://plugin.audio.cro?action=set_others&showId=" + str(show["id"]) + "&val=1" + ")")) else: menus.append(( "Přesunout z ostatních", "RunPlugin(plugin://plugin.audio.cro?action=set_others&showId=" + str(show["id"]) + "&val=0" + ")")) if addon.getSetting( "hide_unlistened_favourites") == "false" and others == 0: menus.append(( "Označit epizody jako poslechnuté", "RunPlugin(plugin://plugin.audio.cro?action=set_listened_all&showId=" + str(show["id"]) + ")")) list_item.addContextMenuItems(menus) if addon.getSetting( "hide_unlistened_favourites") == "false" and others == 0: url = get_url(action='list_show', showId=show["id"], page=1, label=encode(show["title"]), mark_new=1) else: url = get_url(action='list_show', showId=show["id"], page=1, label=encode(show["title"]), mark_new=0) list_item.setContentLookup(False) xbmcplugin.addDirectoryItem(_handle, url, list_item, True) xbmcplugin.endOfDirectory(_handle, cacheToDisc=False)
def list_favourites_new(label): items = int(addon.getSetting("favourites_new_count")) xbmcplugin.setPluginCategory(_handle, label) favourites = get_favourites(others=0) episodes = {} episodes_ordered = {} for showId in favourites: show = favourites[showId] data = call_api(url="https://api.mujrozhlas.cz/shows/" + showId + "/episodes?sort=-since&page[limit]=" + str(items)) if "err" in data: xbmcgui.Dialog().notification( "ČRo", "Pořad " + show["title"] + " nebyl nalezený", xbmcgui.NOTIFICATION_ERROR, 4000) # sys.exit() if "data" in data and len(data["data"]) > 0: for episode in data["data"]: if "attributes" in episode and "title" in episode[ "attributes"] and len( episode["attributes"]["title"]) > 0: starttime = parse_date(episode["attributes"]["since"]) starttime_ts = time.mktime(starttime.timetuple()) episodes_ordered.update({episode["id"]: starttime_ts}) if "mirroredSerial" in episode[ "attributes"] and "totalParts" in episode[ "attributes"][ "mirroredSerial"] and "part" in episode[ "attributes"]: parts = " (" + str( episode["attributes"]["part"]) + "/" + str( episode["attributes"]["mirroredSerial"] ["totalParts"]) + ") " else: parts = "" title = episode["attributes"][ "title"] + parts + " (" + starttime.strftime( "%d.%m.%Y %H:%M") + ")" link = episode["attributes"]["audioLinks"][0]["url"] episodes.update({ episode["id"]: { "showId": showId, "link": link, "img": show["img"], "tvshowtitle": show["title"], "title": title, "aired": starttime.strftime("%Y-%m-%d"), "director": [show["director"]], "plot": show["description"], "studio": show["station"] } }) if len(episodes) > 0: for key in sorted(episodes_ordered, key=episodes_ordered.get, reverse=True): list_item = xbmcgui.ListItem(label=episodes[key]["title"]) list_item.setArt({ "thumb": episodes[key]["img"], "icon": episodes[key]["img"] }) list_item.setInfo( "video", { "tvshowtitle": episodes[key]["tvshowtitle"], "title": episodes[key]["title"], "aired": episodes[key]["aired"], "director": episodes[key]["director"], "plot": episodes[key]["plot"], "studio": episodes[key]["studio"] }) list_item.setProperty("IsPlayable", "true") list_item.setContentLookup(False) url = get_url(action='play', url=encode(episodes[key]["link"]), showId=episodes[key]["showId"], episodeId=key, title=encode(episodes[key]["title"]), img=episodes[key]["img"]) if PY2: xbmcplugin.addDirectoryItem(_handle, url, list_item, False) else: xbmcplugin.addDirectoryItem(_handle, url, list_item, True) xbmcplugin.endOfDirectory(_handle)