解析爱奇艺视频的Python代码
要解析爱奇艺视频,可以使用Python的第三方库`you-get`。首先需要安装`you-get`库,可以通过以下命令安装: ```bash pip install you-get ``` 然后,可以使用以下Python代码来下载爱奇艺视频: ```python import os def download_iqiyi_video(url, output_dir='.'): command = f'you-get -o {output_dir} {url}' os.system(command) if __name__ == '__main__': video_url = '爱奇艺视频链接' # 替换为实际的爱奇艺视频链接 output_directory = '下载的视频存放目录' # 替换为实际的下载目录 download_iqiyi_video(video_url, output_directory) ``` 将上述代码保存为一个`.py`文件,然后在命令行
最新吾爱大佬分享的一段iqiyi视频解析Python代码,转载分享给大家参考。
代码说明
m3u8下载部分:pip install m3u8download-hecoter
使用需要nodejs
项目链接:https://GitHub.com/hecoter/videoParse/tree/main/iqiyi
python代码
importrequestsimportreimporttimefromnode_vm2importNodeVMfromm3u8download_hecoterimportm3u8downloadclassIQIYI:def__init__(self,url,title='',Cookie=''):self.title=titleself.Cookie='P00001=dbDGm3tbOctQELNen4XiwyzaLzc3Sm1AaLjdhrwm24bgKivBbMNXyv0YLxOSkdKlwEPUl2d'self.Cookie_P00003=''self.Cookie_QC005=''self.Cookie_dfp=''self.url=urldefget_vf(self,url):withopen('295_decrypt.js','r',encoding='utf-8')asf:js=f.read()module=NodeVM.code(js)vf=module.call_member('cmd5x',url)returnf'{url}&vf={vf}'defgetm3u8(self,shareurl):headers={'user-agent':'Mozilla/5.0(WindowsNT10.0;Win64;x64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/89.0.4389.114Safari/537.36Edg/89.0.774.75','cookie':self.Cookie}response=requests.get(url=shareurl,headers=headers).textm3u8=re.findall('"m3u8":"(.+?)"',response)[0].replace('/','').replace('','/')m3u8s=m3u8.split('/n')m3u8='n'.join(m3u8s)vsizes=re.findall('"vsize":(d+)',response)vs=[]forvsizeinvsizes:vs.append(int(int(vsize)/1024/1024))vssize=str(max(vs))+'MB'scrsz=re.findall('"scrsz":"(.+?)"',response)[0]title=self.title+'_'+scrsz+'_'+vssizewithopen(f'{title}.m3u8','w',encoding='utf-8')asf:f.write(m3u8)##下载部分m3u8download(m3u8url=f'{title}.m3u8',title=title)defparse(self):response=requests.get(self.url).texttry:self.title=re.findall('<metaname="irTitle"content="(.+?)"/>',response)[0]except:self.title=''tvid=re.findall('"tvId":(d+)',response)[0]vid=re.findall('"vid":"(.+?)"',response)[0]tm=int(time.time()*1000)#k_ft2=8191url_with_dash_but_vf2=f'/jp/dash?tvid={tvid}&bid=860&vid={vid}&src=03020031010000000000&vt=0&rs=1&uid={self.Cookie_P00003}&ori=pcw&ps=0&k_uid={self.Cookie_QC005}&pt=0&d=0&s=&lid=&cf=&ct=&k_tag=1&ost=0&ppt=0&dfp={self.Cookie_dfp}&locale=zh_cn&k_err_retries=0&qd_v=2&tm={tm}&qdy=a&qds=0&k_ft2=8191&callback=hecoter&ut=1'vf=self.get_vf(url_with_dash_but_vf2)infourl='https://cache.video.iqiyi.com'+vfself.getm3u8(infourl)iqiyi=IQIYI(url='https://www.iqiyi.com/v_nwky80cww4.html',Cookie='').parse()