def get_channels(category_id): ''' ''' channels = [] log_info("Getting channel for category id: %s" % category_id) conn = sqlite3.connect(db_file_path) query = '''SELECT channel_id FROM freetvandradio_channel_category AS cc ''' # if we are showing all channels, that is category_id is 0 and show radios is disabled if int(category_id) > 0: query += "WHERE cc.category_id = %s;" % category_id conn.row_factory = lambda cursor, row: row[0] c = conn.cursor() ids = c.execute(query).fetchall() ids = ','.join(str(id) for id in ids) query_get_only_enabled = '''AND ch.enabled = 1''' if settings.show_only_enabled else '' query = '''SELECT ch.id, ch.name, ch.logo, ch.ordering, ch.enabled FROM freetvandradio_channel AS ch WHERE ch.id IN (%s) %s GROUP BY ch.id ORDER BY ch.ordering''' % ( ids, query_get_only_enabled) conn.row_factory = lambda cursor, row: Channel(row) c = conn.cursor() channels = c.execute(query).fetchall() log_error("Extracted %s channels" % len(channels)) return channels
def show_categories(): update('browse', 'Categories') if not settings.use_local_db: asset = DbAsset(url=settings.url_to_db, log_delegate=log, file_path=db_file_path) if asset.is_expired(): asset.update() log_info("Loading data from DB file: %s" % db_file_path) try: conn = sqlite3.connect(db_file_path) cursor = conn.execute('''SELECT * FROM freetvandradio_category''') li = xbmcgui.ListItem('Всички') url = make_url({"id": 0, "action": "show_channels"}) xbmcplugin.addDirectoryItem(int(sys.argv[1]), url, li, True) for row in cursor: li = xbmcgui.ListItem(row[1]) url = make_url({"id": row[0], "action": "show_channels"}) xbmcplugin.addDirectoryItem(int(sys.argv[1]), url, li, True) except Exception as er: log_error(er) notify_error(er) if not settings.use_local_db: li = xbmcgui.ListItem('******** Обнови базата данни ********') url = make_url({"action": "update_tvdb"}) xbmcplugin.addDirectoryItem(int(sys.argv[1]), url, li) xbmcplugin.endOfDirectory(int(sys.argv[1]))
def play_channel(channel_id, stream_index=0): try: urls = get_streams(id) s = urls[stream_index] li = xbmcgui.ListItem(s.name, iconImage=s.logo, thumbnailImage=s.logo, path=s.stream_url) li.setInfo(type="Video", infoLabels={"Title": s.name}) li.setProperty("IsPlayable", 'True') xbmcplugin.setResolvedUrl(handle=int(sys.argv[1]), succeeded=True, listitem=li) except Exception as er: log_error(er) notify_error(er)
def resolve(self): stream = None s = requests.session() headers = {'User-agent': self.user_agent, 'Referer':self.page_url} # If btv - custom dirty fix to force login # if self.channel_id == 2: # body = { "username": settings.btv_username, "password": settings.btv_password } # headers["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8" # r = s.post("https://btvplus.bg/lbin/social/login.php", headers=headers, data=body) # log_info(r.text) # if r.json()["resp"] != "success": # log_error("Проблем при вписването в сайта btv.bg") # return None self.player_url = self.player_url.replace("{timestamp}", str(time.time() * 100)) log_info(self.player_url) r = s.get(self.player_url, headers=headers) # log_info("body before replacing escape backslashes: " + r.text) body = r.text.replace('\\/', '/').replace("\\\"", "\"") # log_info("body after replacing escape backslashes: " + body) regex = self.regex if self.regex else '(//.*?\.m3u.*?)[\s\'"]{1}' log_info("Regex used: %s" % regex) matches = re.compile(regex).findall(body) if len(matches) > 0: log_info('Found %s matches in %s' % (len(matches), self.player_url)) if not matches[0].startswith('http'): if self.player_url.startswith("https"): stream = "https:" + matches[0] elif self.player_url.startswith("http"): stream = "http:" + matches[0] else: stream = matches[0] log_info('Extracted stream %s' % stream) else: log_error("No matches found for m3u extraction") return stream
def update_tvdb(): progress_bar = xbmcgui.DialogProgressBG() progress_bar.create(heading="Downloading db file...") msg = "Базата данни НЕ бе обновена!" try: log_info('Force-updating tvdb') asset = DbAsset(log_delegate=log, url=settings.url_to_db, file_path=db_file_path) progress_bar.update(1, "Downloading database...") res = asset.update() if res: msg = "Базата данни бе обновена успешно!" if settings.use_local_db: msg += " Използвате локална база данни!" except Exception as ex: log_error(ex) notify_error(ex, True) notify_success(msg) if progress_bar: progress_bar.close()