banner
andrewji8

Being towards death

Heed not to the tree-rustling and leaf-lashing rain, Why not stroll along, whistle and sing under its rein. Lighter and better suited than horses are straw sandals and a bamboo staff, Who's afraid? A palm-leaf plaited cape provides enough to misty weather in life sustain. A thorny spring breeze sobers up the spirit, I feel a slight chill, The setting sun over the mountain offers greetings still. Looking back over the bleak passage survived, The return in time Shall not be affected by windswept rain or shine.
telegram
twitter
github

pythonのマルチプロセスを使用して、TikTokのショートビデオをダウンロードします。

废话少说、直接にアップロードします
抖音公式ウェブサイト:https://www.douyin.com/

image

640_result

ビデオリンクアドレスをコピーします

テキストボックスに貼り付け、その後ボタンをクリックします。ボタンの上にはダウンロードが成功したか失敗したかが表示されます。

640 (1)

この時点で、ビデオファイルは正常にダウンロードされます。

640 (2)
完全なコード:


import wx
import re
import requests
from multiprocessing import Pool

req=requests.session()

def download_video(url, save_path):
    response = requests.get(url, stream=True)
    if response.status_code == 200:
        with open(save_path, 'wb') as file:
            for chunk in response.iter_content(1024):
                file.write(chunk)
        t='ダウンロード成功'
    else:
        t='ダウンロード失敗'
    return t

def get_mid_string(html, start_str, end):
    try:
        start = html.find(start_str)
        if start >= 0:
            start += len(start_str)
            end = html.find(end, start)
            if end >= 0:
                return html[start:end].strip()
    except:
        return None

def remove_special_characters(text):
    pattern = r'[\\/:*?"<>|]'
    cleaned_text = re.sub(pattern, '', text)
    return cleaned_text

def keep_characters_before_hash(text):
    parts = text.split('#', 1)
    return parts[0]

def download_with_multiprocessing(url):
    a=req.get('https://api.douyin.wtf/api?url={}'.format(url))
    title = get_mid_string(a.text, '"desc":"', '"')
    title1 = remove_special_characters(title)
    title2 = keep_characters_before_hash(title1)
    video_url = get_mid_string(a.text, 'nwm_video_url":"', '"')
    save_path = f'./{title2}.mp4'
    return download_video(video_url, save_path)

class Frame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, title='抖音下载', size=(400, 300), name='frame', style=541072960)
        self.启动窗口 = wx.Panel(self)
        self.Centre()
        self.编辑框1 =  wx.TextCtrl(self.启动窗口, size=(269, 221), pos=(7, 7), value='', name='text', style=1073741856)
        self.标签1 = wx.StaticText(self.启动窗口, size=(80, 107), pos=(292, 16), label='默认保存与\n程序相同文\n件夹', name='staticText', style=2321)
        self.标签1.SetForegroundColour((255, 0, 0, 255))
        self.按钮1 = wx.Button(self.启动窗口, size=(80, 32), pos=(287, 215), label='按钮', name='button')
        self.按钮1.Bind(wx.EVT_BUTTON, self.按钮1_按钮被单击)
        self.编辑框2 = wx.TextCtrl(self.启动窗口, size=(98, 22), pos=(282, 134), value='', name='text', style=16)

    def 按钮1_按钮被单击(self, event):
        c=self.编辑框1.GetValue()
        pattern = r'[a-zA-Z]+://[^"\'\s]*'
        urls = re.findall(pattern,c)
        with Pool(len(urls)) as pool:
            results = pool.map(download_with_multiprocessing, urls)

        s = '\n'.join(results)
        self.编辑框2.SetValue(s)

class myApp(wx.App):
    def OnInit(self):
        self.frame = Frame()
        self.frame.Show(True)
        return True

if __name__ == '__main__':
    app = myApp()
    app.MainLoo
読み込み中...
文章は、創作者によって署名され、ブロックチェーンに安全に保存されています。