国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

python 下載m3u8視頻的示例代碼

瀏覽:35日期: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) # 用來(lái)保存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(’視頻時(shí)長(zhǎng):%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: 返回一個(gè)新的列表 ''' new_list = [] ’’’列表長(zhǎng)度大于等于份數(shù)’’’ if len(tabulation) >= num: ’’’remainder:列表長(zhǎng)度除以份數(shù),取余’’’ remainder = len(tabulation) % num if remainder == 0:’’’merchant:列表長(zhǎng)度除以分?jǐn)?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:列表長(zhǎng)度除以分?jǐn)?shù) 取商’’’merchant = int(len(tabulation) // num)’’’remainder:列表長(zhǎng)度除以份數(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: ’’’如果列表長(zhǎng)度小于份數(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小時(shí)。 可能我的m3u8不行,或者我電腦不行, 多線程是機(jī)械式的。 電腦好 可以多加幾條。

以上就是python 下載m3u8視頻的示例代碼的詳細(xì)內(nèi)容,更多關(guān)于python 下載m3u8視頻的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 国产日韩欧美 | 成人一区二区免费中文字幕 | 视频一区二区三区自拍 | 亚洲欧美日韩久久精品第一区 | 国产精品亚洲二线在线播放 | 国产一级毛片视频在线! | 18视频在线观看 | 成人a一级毛片免费看 | 九九视频精品全部免费播放 | 中文字幕在线乱码不卡区区 | 中文字幕曰韩一区二区不卡 | 天堂一区二区三区精品 | 日产国产精品亚洲系列 | 波多野结衣一区二区三区88 | 91精品国产91久久久久久青草 | 精品视频国产狼人视频 | 欧美一级美片在线观看免费 | 欧美精品久久久久久久久大尺度 | 久久精品一区二区影院 | 成人男女啪啪免费观看网站 | 免费播放巨茎人妖不卡片 | 日本不卡在线一区二区三区视频 | 欧美精品一区二区三区免费观看 | 岛国在线永久免费视频 | 国产日韩美国成人 | 久草视频免费在线观看 | 国内自拍第一页 | 亚洲国产成人久久笫一页 | 精品国产爱久久 | 国内精品久久久久久久久蜜桃 | 性盈盈影院影院67194 | 国产三级国产精品国产国在线观看 | 亚洲第一区视频在线观看 | 美国三级网站 | 男女午夜性爽快免费视频不卡 | 日韩成人免费在线视频 | 亚洲aⅴ在线| 暖暖免费高清日本一区二区三区 | 娇喘嗯嗯~轻点啊视频福利 | 亚洲精品天堂在线观看 | 亚洲欧美日韩国产精品影院 |