def parse_album_by_aid(self, drama_id, aid, last_ep=0): source = "http://api.tv.sohu.com/v4/album/videos/%s.json?page_size=100&api_key=695fe827ffeb7d74260a813025970bd5&plat=3&partner=1&sver=5.0.1&poid=1&page=1&with_fee_video=1&" % aid content = self.get_decoded_json(source) if not content: logging.error("sohu parse album by aid error, %s, %s" % (drama_id, aid)) return videos = content['data']['videos'] for i, v in enumerate(videos): if i + 1 <= last_ep: continue if v.get('url_super', None) is not None: url = v['url_high'] hd_url = v['url_super'] else: url = v['url_nor'] hd_url = v['url_high'] v1, v2 = UrlContentModel.instance().insert( url), UrlContentModel.instance().insert(hd_url) if v1 > 0 and v2 > 0: DramaEpisodeModel.instance().insert(drama_id, i + 1, 0, source, url, hd_url) else: logging.error("sohu get url content error, %s, %s" % (url, hd_url))
def parse(self, vid, store=True): content = self.get_decoded_html( "http://www.tudou.com/programs/view/%s" % vid) if not content: return None, None r = r'iid:\s?(\d+)' iid = self.r1(r, content) if iid == None: return urls = [ "http://vr.tudou.com/v2proxy/v2.m3u8?it=%s&st=5" % iid, "http://vr.tudou.com/v2proxy/v2.m3u8?it=%s&st=3" % iid, "http://vr.tudou.com/v2proxy/v2.m3u8?it=%s&st=2" % iid ] can_urls = [] for url in urls: if store: persistentResult = UrlContentModel.instance().insert(url) else: persistentResult = 1 if persistentResult >= 0: can_urls.append(url) if len(can_urls) >= 2: break if len(can_urls) == 0: logging.info('tudou parse error, cannot get m3u8 content') return None, None if len(can_urls) == 1: return can_urls[0], can_urls[0] else: return can_urls[1], can_urls[0]
def parse(self, vid, store=True): content = self.get_decoded_html("http://www.tudou.com/programs/view/%s" % vid) if not content: return None, None r = r'iid:\s?(\d+)' iid = self.r1(r, content) if iid == None: return urls = [ "http://vr.tudou.com/v2proxy/v2.m3u8?it=%s&st=5" % iid, "http://vr.tudou.com/v2proxy/v2.m3u8?it=%s&st=3" % iid, "http://vr.tudou.com/v2proxy/v2.m3u8?it=%s&st=2" % iid ] can_urls = [] for url in urls: if store: persistentResult = UrlContentModel.instance().insert(url) else: persistentResult = 1 if persistentResult >= 0: can_urls.append(url) if len(can_urls) >= 2: break if len(can_urls) == 0: logging.info('tudou parse error, cannot get m3u8 content') return None, None if len(can_urls) == 1: return can_urls[0], can_urls[0] else: return can_urls[1], can_urls[0]
def parse_album_by_aid(self, drama_id, aid, last_ep=0): source = ( "http://api.tv.sohu.com/v4/album/videos/%s.json?page_size=100&api_key=695fe827ffeb7d74260a813025970bd5&plat=3&partner=1&sver=5.0.1&poid=1&page=1&with_fee_video=1&" % aid ) content = self.get_decoded_json(source) if not content: logging.error("sohu parse album by aid error, %s, %s" % (drama_id, aid)) return videos = content["data"]["videos"] for i, v in enumerate(videos): if i + 1 <= last_ep: continue if v.get("url_super", None) is not None: url = v["url_high"] hd_url = v["url_super"] else: url = v["url_nor"] hd_url = v["url_high"] v1, v2 = UrlContentModel.instance().insert(url), UrlContentModel.instance().insert(hd_url) if v1 > 0 and v2 > 0: DramaEpisodeModel.instance().insert(drama_id, i + 1, 0, source, url, hd_url) else: logging.error("sohu get url content error, %s, %s" % (url, hd_url))
def __init__(self): self.tudouParser = TudouParser() self.model = DramaEpisodeModel() self.urlModel = UrlContentModel()