def playURL(url, ref): if xarg.dl_threads: src, cookies, ref = xsrc.getSource(url, ref=ref) url = dl.createJobs(src, xdef.dldir, xarg.dl_threads) if isPlayerRunning(): if os.path.exists(xdef.playlist): playbackMode = xurl.readLocal(xdef.playbackMode, 0).lower() if len(playbackMode) > 0 and playbackMode != 'normal': os.remove(xdef.playlist) setAct('stop', None) if xarg.playbackMode: xurl.saveLocal(xdef.playbackMode, xarg.playbackMode, 0) if xarg.pagelist: playlist = xurl.readLocal(xarg.pagelist) xurl.saveLocal(xdef.playlist, playlist, 0) while url != None: nextURL = getNext(url, playlist) if nextURL: p = Process(target=xsrc.getSource, args=(nextURL, )) p.start() playURL_core(url, ref) p.join() else: playURL_core(url, ref) url = ref = getNext(url, playlist) else: playURL_core(url, ref) return
def setAct(act, val): if checkActVal(act, val) == False: print('\n[xplay][setAct] invalid command: %s %s\n' % (act, val)) return if act == 'stop' and val != '#': if os.path.exists(xdef.playlist): os.remove(xdef.playlist) if act == 'playbackMode': xurl.saveLocal(xdef.playbackMode, val, 0) if val.lower() in ['autonext', 'loopall']: playing = xurl.readLocal(xdef.playing, 0) playlist = xurl.readLocal(xdef.playlist, 0) nextURL = nextLine(playing, playlist) if nextURL: if os.fork() == 0: xsrc.getSource(nextURL) return player = getPlayer() print('\n[xplay][setAct]\n\n\t' + '%s,%s,%s' % (player, act, val)) if player == 'mpv' and xproc.checkProcessRunning('mpv'): return mpv.setAct(act, val) if player == 'omxp' and xproc.checkProcessRunning('omxplayer.bin'): return omxp.setAct(act, val) if player == 'ffplay' and xproc.checkProcessRunning('ffplay'): return ffplay.setAct(act, val)
def loadM3U8(url): txt = xurl.load(url) txt = txt.replace('\/', '/') txt = txt.replace('\\n', '\n') m = re.search(r'"m3u8":"([^"]*)"', txt) if m: m3u8 = m.group(1) local = xurl.genLocal(url, prefix='vod_list_', suffix='.m3u8') xurl.saveLocal(local, m3u8) return local results = [] for l in re.finditer(r'"l":"([^"]*)"', txt): part = l.group(1) if re.search(r'f4v\?', part): if part.startswith('http'): results.append(part) else: data_url = 'https://data.video.iqiyi.com/videos' + part for v in re.finditer(r'"l":"([^"]*)"', xurl.load(data_url)): results.append(v.group(1)) if len(results): local = xurl.genLocal(url, prefix='vod_list_', suffix='.m3u8') xurl.saveM3U8(local, results) return local return None
def upload(post_data, q): d = parse_qs(q) j = d['j'][0] if 'j' in d else None data = unquote_plus(post_data.decode('utf8'))[5:] defpath = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'jsons', os.path.basename(j)) xurl.saveLocal(defpath, data) return
def executeJSCode(code): local = xurl.genLocal(str(os.getuid), prefix='vod_code_') xurl.saveLocal(local, code) try: output = subprocess.check_output('nodejs ' + local, shell=True).rstrip('\n') except: return None output = output.replace("\/", "/") showAll(code, output) return output
def parseJson(path): print('\n[ytdl][parseJson]\n') results = [] cookies = None fd = open(path, "r") lines = fd.readlines() fd.close() for line in lines: try: data = json.loads(line) urls = data['url'] except: print('\texception') continue try: cookies = data['http_headers']['Cookie'].encode('utf8') except: cookies = None if not isinstance(urls, basestring): results.append(urls) else: encoded = re.search( r'data:application/vnd.apple.mpegurl;base64,([a-zA-Z0-9+/=]*)', urls) if encoded: local = xurl.genLocal(path, prefix='vod_list_', suffix='.m3u') decoded = base64.b64decode(encoded.group(1)) xurl.saveLocal(local, decoded) results.append(local) else: results.append(urls) if cookies: print('\thdr : %s' % (cookies)) if len(results) == 0: print('\tNo results') return None, None elif len(results) == 1: print('\tret : %s' % (results[0])) return results[0], cookies else: m3u = xurl.genLocal(path, prefix='vod_list_', suffix='.m3u8') xurl.saveM3U8(m3u, results) print('\tret : %s' % (m3u)) return m3u, cookies
def getExtractorResultJSON(results): obj = page_obj() local = '/var/tmp/vod_list_pagelist_%s' %(str(os.getpid() % 100)) links = [] for res in results: if isinstance(res, extractors.entryObj): obj.entry.append(res.__dict__) links.append(res.link) elif isinstance(res, extractors.navObj): obj.nav.append(res.__dict__) xurl.saveLocal(local, '\n'.join(links)) obj.meta = local return json.dumps(obj.__dict__)
def unpack(txt): m = re.search('(eval\(function\(p,a,c,k,e,d\)\{.+\))', txt) if m: code = m.group() func, args = parseCode(code) local = xdef.workdir+'vod_code' if os.path.exists('/usr/bin/rhino'): txt = 'function unpack(p,a,c,k,e,d)%s\nprint(unpack%s);\n' %(func, args) else: txt = 'function unpack(p,a,c,k,e,d)%s\nconsole.log(unpack%s);\n' %(func, args) xurl.saveLocal(txt, local) output = subprocess.check_output('js '+local, shell=True).rstrip('\n') output = output.replace("\/", "/") showAll(code, output) return output return None
def getSource(url, fmt, ref): txt = xurl.load(url) video = [] audio = [] video_ids = ['64', '32', '16'] audio_ids = ['30280', '30216'] video_id = None audio_id = None for m in re.finditer(r'"id":(\d+),"baseUrl":"([^"]*)"', txt): _id, _url = m.group(1), m.group(2) if _id in video_ids: if not video_id: video_id = _id if _id == video_id: video.append(_url) if _id in audio_ids: if not audio_id: audio_id = _id if _id == audio_id: audio.append(_url) local_a = xurl.genLocal(url, prefix='vod_list_', suffix='.audio.m3u8') local_v = xurl.genLocal(url, prefix='vod_list_', suffix='.video.m3u8') local = xurl.genLocal(url, prefix='vod_list_', suffix='.m3u8') xurl.saveM3U8(local_a, audio) xurl.saveM3U8(local_v, video) s = [] s.append('#EXTM3U') s.append( '#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio",LANGUAGE="eng",URI="%s"' % (local_a)) s.append('#EXT-X-STREAM-INF:AUDIO="audio"') s.append(local_v) xurl.saveLocal(local, '\n'.join(s)) return local
def playURL_core(url, ref): player = getPlayer() print('\n[xplay][%s]\n' % (player)) print('\turl : %s' % (url or '')) print('\tref : %s' % (ref or '')) if url == None or url == '': return xurl.saveLocal(xdef.playing, url, 0) if player == 'mpv': return mpv.play(url, ref) if player == 'omxp': return omxp.play(url, ref) if player == 'ffplay': return ffplay.play(url, ref) return runDBG(url, ref)
def gen_tse(): url = 'https://isin.twse.com.tw/isin/C_public.jsp?strMode=2' txt = xurl.load(url) m = re.findall(r'<tr><td bgcolor=#FAFAD2>(\w+)', txt) xurl.saveLocal('tse-code-list.txt', '\n'.join(m)) return