python實現抖音多線程下載無水印視頻【附源碼】


    昨天發了一個無水印解析,評論說想要多線程下載,還是比較簡單的。 py文件同目錄下創建url.txt,把鏈接一行一行復制進去,就能批量下載。

    代碼中的延時不能去掉,由於是多線程,速度較快,延時很重要。

    

import re
import requests
from concurrent import futures
import time
headers = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.96 Safari/537.36'}
def download(_url):
    try:
        time.sleep(0.3)
        html3 = requests.head(_url,headers = headers)
        download_url = html3.headers['Location']
        video_file = requests.get(download_url,headers = headers)
        file_name = download_url.split('=')[-1]
        print(file_name)
    except:
        print('Error')
    with open(file_name + '.mp4','wb') as code:
        code.write(video_file.content)
def main():
    data_file = open('url.txt')
    data_url = data_file.read()
    data_url_list1 = data_url.split('\n')
    Threads = futures.ThreadPoolExecutor(min(Max_workers,len(data_url_list1)))
    for x in data_url_list1:
        html1 = requests.head(x)
        first_url = html1.headers['Location']
        html2 = requests.get(first_url,headers = headers)
        text_data = html2.text
        video_player_url1 = re.findall('playAddr: "(.*?)"',text_data,re.S)[0]
        video_player_url2 = video_player_url1.replace('wm','')
        #download(video_player_url2)
        Threads.submit(download,video_player_url2)
Max_workers = 5       
main()

  

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM