电脑知识|欧美黑人一区二区三区|软件|欧美黑人一级爽快片淫片高清|系统|欧美黑人狂野猛交老妇|数据库|服务器|编程开发|网络运营|知识问答|技术教程文章 - 好吧啦网

您的位置:首頁技術文章
文章詳情頁

python 下載m3u8視頻的示例代碼

瀏覽:39日期:2022-07-05 17:32:28

import requestsimport osimport datetimeimport threadingclass xiazai(): def __init__(self,url): self.url = url work_dir = os.getcwd() # print(work_dir) # 用來保存ts文件 file_dir = os.path.join(work_dir, ’file_tmp’) if not os.path.exists(file_dir): os.mkdir(file_dir) self.headers ={ ’user-agent’: ’Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.116 Safari/537.36’ } self.savefile(self.url) def savefile(self, file_url): r = requests.get(file_url, headers=self.headers) # 合成帶有hls的m3u8地址 if r.text.split(’n’)[-1] == ’’: hls_mark = r.text.split(’n’)[-2] # 以防n結尾 else: hls_mark = r.text.split(’n’)[-1] self.url_m3u8_hls = file_url.replace(’index.m3u8’, hls_mark) #file_m3u8 = url_m3u8_hls.split(’/’)[-1] self.duqu() #print(url_m3u8_hls) def duqu(self): r = requests.get(self.url_m3u8_hls, headers=self.headers).text text_bytes = r.split(’n’) # 篩選以.ts結尾的行 # 有些情況下可能是以其他格式的文件,比如png,下載后修改后綴即可 # ts_name = [i for i in text_string if i.endswith(’.ts’)] self.ts_time = [i for i in text_bytes if i.startswith(’#EXTINF’)] #self.shijian(dm_time) #print(dm_time) self.ts_neirong = [i for i in text_bytes if not i.startswith(’#’)] self.ts_neirong.pop() self.threads = [] self.threads.append(threading.Thread(target=self.xiazai)) self.threads.append(threading.Thread(target=self.shijian)) for t in self.threads: # print(t) t.start() #self.xiazai(url_m3u8_hls) # print(ts_neirong) def shijian(self): self.dm_time = 0 for i in range(len(self.ts_time)): ts_time1 = self.ts_time[i].replace(’#EXTINF:’, ’’) ts_time2 = ts_time1.replace(’,’, ’’) self.dm_time = float(ts_time2) + self.dm_time shichang_time = str(datetime.timedelta(seconds=self.dm_time)) print(’視頻時長:%s’ % shichang_time) def xiazai(self): liebiao=[] for i in range(len(self.ts_neirong)): hls_mark = self.url_m3u8_hls.split(’/’)[-1] url_xiazai = self.url_m3u8_hls.replace(hls_mark, self.ts_neirong[i]) liebiao.append(url_xiazai) #print(url_xiazai) # r = requests.get(url_xiazai, headers=self.headers) # with open(’file_tmp/’+ts_neirong[i], ’wb’) as f: # f.write(r.content) # f.close() x = self.bisector_list(liebiao, 10) self.xiancheng0=x[0] self.xiancheng1=x[1] self.xiancheng2=x[2] self.xiancheng3=x[3] self.xiancheng4=x[4] self.xiancheng5=x[5] self.xiancheng6=x[6] self.xiancheng7=x[7] self.xiancheng8=x[8] self.xiancheng9=x[9] self.threads2 = [] self.threads2.append(threading.Thread(target=self.xiancheng_xiazai1)) self.threads2.append(threading.Thread(target=self.xiancheng_xiazai2)) self.threads2.append(threading.Thread(target=self.xiancheng_xiazai3)) self.threads2.append(threading.Thread(target=self.xiancheng_xiazai4)) self.threads2.append(threading.Thread(target=self.xiancheng_xiazai5)) self.threads2.append(threading.Thread(target=self.xiancheng_xiazai6)) self.threads2.append(threading.Thread(target=self.xiancheng_xiazai7)) self.threads2.append(threading.Thread(target=self.xiancheng_xiazai8)) self.threads2.append(threading.Thread(target=self.xiancheng_xiazai9)) self.threads2.append(threading.Thread(target=self.xiancheng_xiazai10)) for t in self.threads2: # print(t) t.start() def xiancheng_xiazai1(self): #print(self.xiancheng0) for i in self.xiancheng0: #print(i) r = requests.get(i, headers=self.headers) mingzi = i.split(’/’)[-1] with open(’file_tmp/’+mingzi, ’wb’) as f:f.write(r.content) f.close() def xiancheng_xiazai2(self): #print(self.xiancheng1) for i in self.xiancheng1: #print(i) r = requests.get(i, headers=self.headers) mingzi= i.split(’/’)[-1] with open(’file_tmp/’+mingzi, ’wb’) as f:f.write(r.content) f.close() def xiancheng_xiazai3(self): #print(self.xiancheng2) for i in self.xiancheng2: #print(i) r = requests.get(i, headers=self.headers) mingzi = i.split(’/’)[-1] with open(’file_tmp/’+mingzi, ’wb’) as f:f.write(r.content) f.close() def xiancheng_xiazai4(self): #print(self.xiancheng3) for i in self.xiancheng3: #print(i) r = requests.get(i, headers=self.headers) mingzi = i.split(’/’)[-1] with open(’file_tmp/’+mingzi, ’wb’) as f:f.write(r.content) f.close() def xiancheng_xiazai5(self): #print(self.xiancheng4) for i in self.xiancheng4: #print(i) r = requests.get(i, headers=self.headers) mingzi = i.split(’/’)[-1] with open(’file_tmp/’+mingzi, ’wb’) as f:f.write(r.content) f.close() def xiancheng_xiazai6(self): #print(self.xiancheng5) for i in self.xiancheng5: #print(i) r = requests.get(i, headers=self.headers) mingzi = i.split(’/’)[-1] with open(’file_tmp/’+mingzi, ’wb’) as f:f.write(r.content) f.close() def xiancheng_xiazai7(self): #print(self.xiancheng6) for i in self.xiancheng6: #print(i) r = requests.get(i, headers=self.headers) mingzi = i.split(’/’)[-1] with open(’file_tmp/’+mingzi, ’wb’) as f:f.write(r.content) f.close() def xiancheng_xiazai8(self): #print(self.xiancheng7) for i in self.xiancheng7: #print(i) r = requests.get(i, headers=self.headers) mingzi = i.split(’/’)[-1] with open(’file_tmp/’+mingzi, ’wb’) as f:f.write(r.content) f.close() def xiancheng_xiazai9(self): #print(self.xiancheng8) for i in self.xiancheng8: #print(i) r = requests.get(i, headers=self.headers) mingzi = i.split(’/’)[-1] with open(’file_tmp/’+mingzi, ’wb’) as f:f.write(r.content) f.close() def xiancheng_xiazai10(self): #print(self.xiancheng9) for i in self.xiancheng9: #print(i) r = requests.get(i, headers=self.headers) mingzi = i.split(’/’)[-1] with open(’file_tmp/’+mingzi, ’wb’) as f:f.write(r.content) f.close() def bisector_list(self,tabulation: list, num: int): ''' 將列表平均分成幾份 :param tabulation: 列表 :param num: 份數 :return: 返回一個新的列表 ''' new_list = [] ’’’列表長度大于等于份數’’’ if len(tabulation) >= num: ’’’remainder:列表長度除以份數,取余’’’ remainder = len(tabulation) % num if remainder == 0:’’’merchant:列表長度除以分數’’’merchant = int(len(tabulation) / num)’’’將列表平均拆分’’’for i in range(1, num + 1): if i == 1: new_list.append(tabulation[:merchant]) else: new_list.append(tabulation[(i - 1) * merchant:i * merchant])return new_list else:’’’merchant:列表長度除以分數 取商’’’merchant = int(len(tabulation) // num)’’’remainder:列表長度除以份數,取余’’’remainder = int(len(tabulation) % num)’’’將列表平均拆分’’’for i in range(1, num + 1): if i == 1: new_list.append(tabulation[:merchant]) else: new_list.append(tabulation[(i - 1) * merchant:i * merchant]) ’’’將剩余數據的添加前面列表中’’’ if int(len(tabulation) - i * merchant) <= merchant: for j in tabulation[-remainder:]:new_list[tabulation[-remainder:].index(j)].append(j)return new_list else: ’’’如果列表長度小于份數’’’ for i in range(1, len(tabulation) + 1):tabulation_subset = []tabulation_subset.append(tabulation[i - 1])new_list.append(tabulation_subset) return new_listif __name__==’__main__’: xiazai(’http://iqiyi.cdn9-okzy.com/20200907/15137_ed25d8c5/index.m3u8’)

速度很慢. 40m 5分鐘 不加多線程 1小時。 可能我的m3u8不行,或者我電腦不行, 多線程是機械式的。 電腦好 可以多加幾條。

以上就是python 下載m3u8視頻的示例代碼的詳細內容,更多關于python 下載m3u8視頻的資料請關注好吧啦網其它相關文章!

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 福州甲醛检测-福建室内空气检测_环境检测_水质检测-福建中凯检测技术有限公司 | 吸污车_吸粪车_抽粪车_电动三轮吸粪车_真空吸污车_高压清洗吸污车-远大汽车制造有限公司 | 恒压供水控制柜|无负压|一体化泵站控制柜|PLC远程调试|MCGS触摸屏|自动控制方案-联致自控设备 | 高速混合机_锂电混合机_VC高效混合机-无锡鑫海干燥粉体设备有限公司 | 知名电动蝶阀,电动球阀,气动蝶阀,气动球阀生产厂家|价格透明-【固菲阀门官网】 | WTB5光栅尺-JIE WILL磁栅尺-B60数显表-常州中崴机电科技有限公司 | 北京公积金代办/租房发票/租房备案-北京金鼎源公积金提取服务中心 | 不锈钢反应釜,不锈钢反应釜厂家-价格-威海鑫泰化工机械有限公司 不干胶标签-不干胶贴纸-不干胶标签定制-不干胶标签印刷厂-弗雷曼纸业(苏州)有限公司 | 东莞海恒试验仪器设备有限公司 | 全自动端子机|刺破式端子压接机|全自动双头沾锡机|全自动插胶壳端子机-东莞市傅氏兄弟机械设备有限公司 | 济南拼接屏_山东液晶拼接屏_济南LED显示屏—维康国际官网 | 德国进口电锅炉_商用电热水器_壁挂炉_电采暖器_电热锅炉[德国宝] | 别墅图纸超市|别墅设计图纸|农村房屋设计图|农村自建房|别墅设计图纸及效果图大全 | 搅拌磨|搅拌球磨机|循环磨|循环球磨机-无锡市少宏粉体科技有限公司 | 餐饮加盟网_特色餐饮加盟店_餐饮连锁店加盟 | 无锡装修装潢公司,口碑好的装饰装修公司-无锡索美装饰设计工程有限公司 | 船用烟火信号弹-CCS防汛救生圈-船用救生抛绳器(海威救生设备) | 实战IT培训机构_IT培训班选大学生IT技术培训中心_中公优就业 | 深圳工程师职称评定条件及流程_深圳职称评审_职称评审-职称网 | 钢化玻璃膜|手机钢化膜|钢化膜厂家|手机保护膜-【东莞市大象电子科技有限公司】 | Eiafans.com_环评爱好者 环评网|环评论坛|环评报告公示网|竣工环保验收公示网|环保验收报告公示网|环保自主验收公示|环评公示网|环保公示网|注册环评工程师|环境影响评价|环评师|规划环评|环评报告|环评考试网|环评论坛 - Powered by Discuz! | 作文导航网_作文之家_满分作文_优秀作文_作文大全_作文素材_最新作文分享发布平台 | 发光字|标识设计|标牌制作|精神堡垒 - 江苏苏通广告有限公司 | 电销卡_稳定企业大语音卡-归属地可选-世纪通信 | 自动记录数据电子台秤,记忆储存重量电子桌称,设定时间记录电子秤-昆山巨天 | 冷却塔厂家_冷却塔维修_冷却塔改造_凉水塔配件填料公司- 广东康明节能空调有限公司 | 净化板-洁净板-净化板价格-净化板生产厂家-山东鸿星新材料科技股份有限公司 | 德国UST优斯特氢气检漏仪-德国舒赐乙烷检测仪-北京泽钏 | 电采暖锅炉_超低温空气源热泵_空气源热水器-鑫鲁禹电锅炉空气能热泵厂家 | 家用净水器代理批发加盟_净水机招商代理_全屋净水器定制品牌_【劳伦斯官网】 | 贵阳用友软件,贵州财务软件,贵阳ERP软件_贵州优智信息技术有限公司 | 定量包装秤,吨袋包装称,伸缩溜管,全自动包装秤,码垛机器人,无锡市邦尧机械工程有限公司 | 金属回收_废铜废铁回收_边角料回收_废不锈钢回收_废旧电缆线回收-广东益夫金属回收公司 | 旋转/数显粘度计-运动粘度测定仪-上海平轩科学仪器 | 水冷散热器_水冷电子散热器_大功率散热器_水冷板散热器厂家-河源市恒光辉散热器有限公司 | 湖南长沙商标注册专利申请,长沙公司注册代理记账首选美创! | 优宝-汽车润滑脂-轴承润滑脂-高温齿轮润滑油脂厂家 | MVR蒸发器厂家-多效蒸发器-工业废水蒸发器厂家-康景辉集团官网 | 纸箱抗压机,拉力机,脂肪测定仪,定氮仪-山东德瑞克仪器有限公司 | 螺旋压榨机-刮泥机-潜水搅拌机-电动泥斗-潜水推流器-南京格林兰环保设备有限公司 | 石家庄小程序开发_小程序开发公司_APP开发_网站制作-石家庄乘航网络科技有限公司 |