def CAT_LIST(force=False): if force == False: if not os.path.isfile(CHAN_LIST): addon_log('channels first download') Downloader( CHAN_LIST_URL, CHAN_LIST, addon.getLocalizedString(30053), addon.getLocalizedString(30054)) #Downloading Channel list parse_ch_data() else: now_time = time.mktime(datetime.now().timetuple()) time_created = os.stat(CHAN_LIST)[ 8] # get local play list modified date if CHAN_LIST_EXPIRE > 0 and now_time - time_created > CHAN_LIST_EXPIRE: addon_log('channels update') Downloader( CHAN_LIST_URL, CHAN_LIST, addon.getLocalizedString(30053), addon.getLocalizedString(30054)) #Downloading Channel list parse_ch_data() else: Downloader(CHAN_LIST_URL, CHAN_LIST, addon.getLocalizedString(30053), addon.getLocalizedString(30054)) #Downloading Channel list parse_ch_data() #try: # parse_ch_data() #except Exception as inst: # addon_log(inst) # pass try: sql = "SELECT id, name \ FROM categories" db_cursor.execute(sql) rec = db_cursor.fetchall() except Exception as inst: #addon_log(inst) #cannot parse the channel list xbmcgui.Dialog().ok(addon.getLocalizedString(30300), addon.getLocalizedString(30301), str(inst)) #Cannot parse channel list ! if len(rec) > 0: for id, name in rec: addDir(name, str(id), CHAN_LIST, 1) #xbmc.executebuiltin("Container.SetViewMode(500)") xbmc.executebuiltin("Container.SetViewMode(51)")
def grab_vk_stream(name, url): temp = os.path.join(ADDON_PATH, "temp.htm") Downloader(url, temp, addon.getLocalizedString(30065), name) #Downloading page for parsing stream url f = open(temp) source_txt = f.read() f.close() os.remove(temp) #addon_log(source_txt) match = re.compile('url720=(http:\/\/[\w\W]+?.mp4)&').search(source_txt) if match: stream_url = match.group(1) addon_log('720 = ' + stream_url) return stream_url match = re.compile('url480=(http:\/\/[\w\W]+?.mp4)&').search(source_txt) if match: stream_url = match.group(1) addon_log('480 = ' + stream_url) return stream_url match = re.compile('url360=(http:\/\/[\w\W]+?.mp4)&').search(source_txt) if match: stream_url = match.group(1) addon_log('360 = ' + stream_url) return stream_url match = re.compile('url240=(http:\/\/[\w\W]+?.mp4)&').search(source_txt) if match: stream_url = match.group(1) addon_log('240 = ' + stream_url) return stream_url return None
def grab_fu_stream(name, url): temp = os.path.join(ADDON_PATH, "temp.htm") Downloader(url, temp, addon.getLocalizedString(30065), name) #Downloading page for parsing stream url f = open(temp) source_txt = f.read() f.close() os.remove(temp) #addon_log(url) #addon_log(source_txt) match = re.compile('\'file\':\s*\'(http:\/\/[\w\W]+?\.flv)\'').search( source_txt) if match: stream_url = match.group(1) addon_log(stream_url) return stream_url return None
def CHANNEL_LIST(name, cat_id, schedule=False): addon_log(name) try: db_cursor.execute( 'SELECT id, name, country, language, status, \ video_resolution, video_aspect, audio_codec, video_codec, \ address, thumbnail, protocol, \ schedule_id \ FROM channels \ WHERE id_cat = ?' , \ (cat_id,) ) rec = db_cursor.fetchall() except Exception as inst: addon_log(inst) xbmcgui.Dialog().ok(addon.getLocalizedString(30300), addon.getLocalizedString(30301), str(inst)) #Cannot parse channel list ! if len(rec) > 0: for id, name, country, language, status, \ video_resolution, video_aspect, audio_codec, video_codec, \ address, thumbnail, protocol, \ schedule_id in rec: #filter by country and language #if( (((country != '') and (addon.getSetting('country_'+country) == 'true')) or #((country == '') and (addon.getSetting('country_none') == 'true')) ) and #(((language != '') and (addon.getSetting('lang_'+language) == 'true')) or #((language == '') and (addon.getSetting('lang_none') == 'true')) ) #): chan_name = name chan_url = address.strip() protocol = protocol.strip() if protocol == 'sop': protocol_color = '[COLOR lightgreen]' + protocol + '[/COLOR]' else: protocol_color = '[COLOR yellow]' + protocol + '[/COLOR]' chan_thumb = thumbnail.strip() #addon_log(chan_thumb) chan_status = status if (((SETTINGS.SHOW_OFFLINE_CH == 'true') and (int(chan_status) == 1)) or (int(chan_status) != 1)): #if we show or not offline channels based on settings logo_name = chan_name.replace(' ', '').lower() logo_name = logo_name.encode('utf8') chan_name_formatted = "[B][COLOR blue]" + chan_name + "[/COLOR][/B]" chan_name_formatted += " (" + protocol_color if (video_codec != ''): chan_name_formatted += " " + video_codec chan_name_formatted += ")" if int(chan_status) == 1: chan_name_formatted += " [COLOR red]" + addon.getLocalizedString( 30063) + "[/COLOR]" #Offline thumb_path = "" if chan_thumb and chan_thumb != "": fileName, fileExtension = os.path.splitext(chan_thumb) fileName = fileName.split("/")[-1] if fileName != "": #thumb_path=os.path.join(ADDON_PATH,"logos",fileName+fileExtension) fileExtension = fileExtension.encode('utf8') thumb_path = os.path.join(SETTINGS.ADDON_PATH, "logos", logo_name + fileExtension) if not os.path.isfile(thumb_path): if fileName != "": try: Downloader( chan_thumb, thumb_path, fileName + fileExtension, addon.getLocalizedString( 30055)) #Downloading Channel Logo except Exception as inst: pass #schedule if (schedule_id != 0) and \ (schedule or (addon.getSetting('schedule_ch_list') == 'true')) \ and (SETTINGS.DISABLE_SCHEDULE != 'true'): if (schedule): #update all by context menu update_all = True elif (addon.getSetting('schedule_ch_list') == 'true' ): #update all when we display channel list update_all = False grab_schedule(schedule_id, chan_name, update_all=update_all) if (SETTINGS.DISABLE_SCHEDULE != 'true') and (int(cat_id) < 200): schedule_txt = load_schedule(chan_name) chan_name_formatted += " " + schedule_txt addLink(id, chan_name_formatted, chan_name, chan_url, protocol, str(schedule_id), name, cat_id, 2, thumb_path, "", len(rec)) xbmc.executebuiltin("Container.SetViewMode(51)")
def grab_schedule(id_channel_port, name, force=False, update_all=False): addon_log('grab schedule') nr_days = 5 db_connection = sqlite3.connect(SCHEDULE_PATH) db_cursor = db_connection.cursor() table_name = name.replace(' ', '_').lower() sql = "CREATE TABLE IF NOT EXISTS `%s` (event_time REAL, title TEXT)" % \ (table_name) db_cursor.execute(sql) now_utc = datetime.now(timezone('UTC')) tz_ro = timezone('Europe/Bucharest') dt_ro = tz_ro.normalize(now_utc.astimezone(tz_ro)) if force == False: sql="SELECT event_time FROM `%s` ORDER BY event_time ASC LIMIT 1" % \ (table_name) db_cursor.execute(sql) rec = db_cursor.fetchone() if rec: #addon_log(rec[0]); #addon_log(time.mktime(dt_ro.timetuple())); if ((time.mktime(dt_ro.timetuple()) - rec[0]) < (60 * 60 * 24 * 2)): #update only if schedule is older than 2 days addon_log('schedule is up to date') if update_all: xbmc.executebuiltin("Notification(%s,%s,%i)" % (name, addon.getLocalizedString(30056), 1000)) #Schedule is up to date return True addon_log('update schedule') sql="DELETE FROM `%s`" % \ (table_name) db_cursor.execute(sql) month_name_to_no = { "Ianuarie": "01", "Februarie": "02", "Martie": "03", "Aprilie": "04", "Mai": "05", "Iunie": "06", "Iulie": "07", "August": "08", "Septembrie": "09", "Octombrie": "10", "Noiembrie": "11", "Decembrie": "12" } #event_year = dt_ro.year start_date = dt_ro url = "http://port.ro/pls/w/tv.channel?i_xday=" + str( nr_days) + "&i_date=%i-%02i-%02i&i_ch=%s" % ( start_date.year, start_date.month, start_date.day, id_channel_port) addon_log(url) temp = os.path.join(ADDON_PATH, "temp.htm") try: Downloader(url, temp, addon.getLocalizedString(30061), addon.getLocalizedString(30062) + " " + name) #Downloading Schedule f = open(temp) schedule_txt = f.read() f.close() os.remove(temp) except Exception as inst: schedule_txt = "" #addon_log(schedule_txt) match = re.compile(r'class="begin_time">(?P<time>.*?)</p>').search( schedule_txt) if match: now_time = match.group('time') else: now_time = "" #addon_log(now_time) next_year = None match_days = re.compile( '<td style="vertical-align:top;text-align:center">\n*\s*<p class="date_box" style="margin-bottom:0px">\n*\s*<span>\n(?P<date>.*?)\n*\s*</span><br/>(?P<content>.*?)\n*\s*</table>\n*\s*</td>', re.DOTALL).findall(schedule_txt) if match_days: i = 1 prev_event_day = None prev_event_month = None for date, content in match_days: date_obj = re.match('.*? \((.*) (.*)\)', date) event_day = date_obj.group(1).zfill(2) event_month = month_name_to_no[date_obj.group(2)] event_year = dt_ro.year if (event_day == '01') and (event_month == '01') and (( (i > 1) and (i < nr_days)) or (i > nr_days + 1)): next_year = event_year + 1 elif i == (nr_days + 1): next_year = None if next_year != None: event_year = next_year #addon_log(event_day + " " + event_month) if content: match_events_re = re.compile( 'btxt\" style=\"width:40px;margin:0px;padding:0px\">(?P<event_time>.*?)<.*?btxt\">(?P<event_title>.*?)</(?P<event_details>.*?)</td></tr>', re.DOTALL) match_events = match_events_re.findall(content) else: return False prev_event_hour = None if match_events: for event_time, event_title, event_details in match_events: if event_time == '': event_time = now_time event_hour = event_time.split(":")[0].zfill(2) event_minutes = event_time.split(":")[1] if (event_hour < prev_event_hour ): #what is after midnight is moved to the next day next_day = datetime(int(event_year), int(event_month), int(event_day)) + timedelta(days=1) #addon_log(next_day) prev_event_day = event_day prev_event_month = event_month event_day = next_day.strftime('%d') event_month = next_day.strftime('%m') #addon_log(event_day+" "+event_month+" "+str(prev_event_day)+" "+str(prev_event_month)) if (event_day == '01') and (event_month == '01') and ( prev_event_day == '31') and (prev_event_month == '12') and (event_year == dt_ro.year): event_year += 1 prev_event_day = None prev_event_month = None event_timestamp = time.mktime( time.strptime( event_day + "-" + event_month + "-" + str(event_year) + " " + event_hour + ":" + event_minutes, "%d-%m-%Y %H:%M")) #addon_log(event_time) #addon_log(event_day+" "+event_month+" "+str(event_year)+" "+event_hour+":"+event_minutes + " " + event_title) #addon_log(event_time + " " + str(event_timestamp) + " " + event_title) sql="INSERT INTO `%s` VALUES (?, ?)" % \ (table_name) st = db_cursor.execute( sql, (event_timestamp, unicode(event_title.replace("'", ""), 'iso-8859-2'))) #addon_log(sql) prev_event_hour = event_hour prev_event_day = event_day prev_event_month = event_month i += 1 db_connection.commit() db_connection.close()