def main(): api_url = "http://qvod.togic.com/api/channels" payload = { "package": "com_togic_livevideo", "versionCode": "45", "access_token": "0f5efcd34fe82e1733b37310394efb758babd1a8", "deviceId": "705ade98-4dd5-e865-db03-f3d19c0ba764" } r = requests.get(api_url, params=payload) channel_list = r.json() s = sql.Sql() query = "INSERT INTO togic_source (channel, url) VALUES (%s, %s)" for channel in channel_list: channel_name = channel["title"] url_list = channel["urls"] param_list = [] for url in url_list: if "http" not in url: file_object = open("rtmp_source.txt", "w") file_object.write(url) file_object.close() elif "http://live.togic.com" in url: token_url = url + "?access_token=" + payload["access_token"] param_list.append((channel_name, token_url)) else: check_handler = easyurl.EasyUrl(url) result_url = check_handler.check_url(3) param_list.append((channel_name, url)) time.sleep(0.5) s.executemany(query, param_list) s.close()
def polymerization(): query_7po = "SELECT channel FROM 7po_source" query_pptv = "SELECT channel FROM pptv_source" query_tencent = "SELECT channel FROM tencent_source" query_togic = "SELECT channel FROM togic_source" query_vst = "SELECT channel FROM vst_source" s = sql.Sql('epg') list_7po = list(s.search(query_7po)) list_pptv = list(s.search(query_pptv)) list_tencent = list(s.search(query_tencent)) list_togic = list(s.search(query_togic)) list_vst = list(s.search(query_vst)) source_list = list( set(list_7po + list_pptv + list_tencent + list_togic + list_vst)) source_list.sort() insert_query = "INSERT INTO channel (channel) VALUES (%s)" s = sql.Sql('source') for source in source_list: s.insert(insert_query, source) s.close()
def main(): s = sql.Sql("source") payload = {"v": "top", "app": "vst", "ver": "1.0.0-D-20130816.0312"} r = requests.get(api_url, params=payload) info_dict = r.json() param_list = [] for item in info_dict["live"]: # item["name"]即url handler = handlesource.HandleSource(item["name"], "vst", s) url_list = item["urllist"].split("#") for url in url_list: # handler.set_params(url) handler.update(url) s.close()
def main(): s = sql.Sql() sql_query = "INSERT INTO pptv_source (channel, url, vid, ctx) VALUES ('%s','%s','%s', '%s')" epg_query = "INSERT INTO pptv_epg (channel, time, program) VALUES ('%s', '%s', '%s')" index_url = "http://live.pptv.com/list/tv_list" channel_url = "http://live.pptv.com/api/tv_list?cb=load.cbs.cb%s&area_id=%s&canBack=0" today = datetime.date.today() area_list = get_areas(index_url) if area_list: for area in area_list: # area是一个元组(area id, area name) has_channel = get_channels(area, channel_url) if has_channel: (channel_dict, channel_html) = has_channel for channel_name in channel_dict: vid_kk = get_channel_info(channel_dict[channel_name]) insert_info = (channel_name, channel_dict[channel_name]) + vid_kk query = sql_query % insert_info s.insert(query) epg_list = get_epg(vid_kk[0], channel_html, today) if epg_list: for time, program in epg_list: # print time, program day_time = str(today) + ' ' + time # print day_time query = epg_query % ( channel_name, day_time, program) s.insert(query) else: print channel_name, "has no epg." else: print area[1], "has no channel." else: print "get area list failure!" return False s.close()
try: r = requests.get(api_url, timeout=15) except Timeout, e: print to_error % (i + 1) continue except Exception, e: print chan_error, e exit(1) try: dom = xml.dom.minidom.parseString(r.text) root = dom.documentElement channels = root.getElementsByTagName("channel") except Exception, e: print chan_error, e exit(1) s = sql.Sql("source") for channel in channels: name = channel.getAttribute('name') handler = handlesource.HandleSource(name, "7po", s) for urlNode in channel.childNodes: url = urlNode.firstChild.wholeText handler.update(url) s.close() if __name__ == "__main__": main()