色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

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

python 下載m3u8視頻的示例代碼

瀏覽:11日期: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結(jié)尾 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結(jié)尾的行 # 有些情況下可能是以其他格式的文件,比如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: 份數(shù) :return: 返回一個新的列表 ''' new_list = [] ’’’列表長度大于等于份數(shù)’’’ if len(tabulation) >= num: ’’’remainder:列表長度除以份數(shù),取余’’’ remainder = len(tabulation) % num if remainder == 0:’’’merchant:列表長度除以分數(shù)’’’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:列表長度除以分數(shù) 取商’’’merchant = int(len(tabulation) // num)’’’remainder:列表長度除以份數(shù),取余’’’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]) ’’’將剩余數(shù)據(jù)的添加前面列表中’’’ if int(len(tabulation) - i * merchant) <= merchant: for j in tabulation[-remainder:]:new_list[tabulation[-remainder:].index(j)].append(j)return new_list else: ’’’如果列表長度小于份數(shù)’’’ 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視頻的示例代碼的詳細內(nèi)容,更多關于python 下載m3u8視頻的資料請關注好吧啦網(wǎng)其它相關文章!

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 狠狠色噜狠狠狠狠色综合久 | 99久久综合狠狠综合久久一区 | 欧美精品成人3d在线 | 不卡无毒免费毛片视频观看 | 欧美13一14周岁a在线播放 | 成人在线综合 | 大学生一级一片第一次欧美 | 韩国啪啪网站 | 亚洲一级二级三级 | 日本手机在线视频 | 2级毛片 | 久久在线影院 | 在线观看国产情趣免费视频 | 精品伊人久久久久7777人 | 免费看特级淫片日本 | 五月激情丁香婷婷综合第九 | 欧美成人午夜免费完成 | 韩日一级视频 | 日本aa毛片a级毛片免费观看 | 精品午夜寂寞影院在线观看 | 欧美高清一区二区 | 国产日韩精品欧美一区 | 国产精品爱久久久久久久 | 九九热视频在线免费观看 | 欧美成在线播放 | 国产精品亚洲欧美 | 国产小片 | 国产成人在线观看免费网站 | 欧美激情视频一级视频一级毛片 | 国产真实孩交 | 久久在线视频播放 | 日韩性大片免费 | 韩国一级a毛片 | 欧美一区精品二区三区 | 老鸭窝 国产 精品 91 | 免费福利在线看黄网站 | 波多野结衣视频在线观看地址免费 | 久草在| 中文字幕在线观看亚洲日韩 | 国产精品区牛牛影院 | 日韩美香港a一级毛片 |