【python小白】抖音無水印視頻下載小工具(windows)

無水印視頻的方法大家都已經知道了,我很早之前也寫了一個腳本。最近學習了一下下pyside2,所以我用python寫了一個小工具。
運行圖:
 

 

 

 

from PySide2.QtWidgets import QApplication, QMessageBox,QFileDialog
from PySide2.QtUiTools import QUiLoader
import requests
import re
import json
import os
from PySide2.QtGui import  QIcon
 
 
class Download:
 
    def __init__(self):
        self.ui = QUiLoader().load('抖音無水印.ui')
        os.remove('抖音無水印.ui')
        self.ui.search.clicked.connect(self.find_share)
        self.ui.search_2.clicked.connect(self.find_hot)
        self.ui.download.clicked.connect(self.save2)
        self.ui.download_2.clicked.connect(self.save)
        self.ui.findpath.clicked.connect(self.findpath)
        self.path =os.getcwd()
        self.ui.path.setText(self.path)
 
    def findpath(self):
        filePath = QFileDialog.getExistingDirectory(self.ui, "選擇存儲路徑")
        if filePath == None or filePath == '':
            pass
        else:
            self.path = filePath
            self.ui.path.setText(self.path)
 
    def find_share(self):
        def find_url(share_url):
            headers = {
                'user-agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Mobile Safari/537.36'}
            if share_url.find('v.douyin.com') < 0:
                return share_url
            response = requests.get(url=share_url, headers=headers,
                                    allow_redirects=False)  # allow_redirects = False 不允許跳轉
            url = response.headers['Location']
            p = re.compile(r"/playwm")
            url = p.sub('/play', url, count=1)
            p2 = re.compile(r"/video/(.+?)/")
            vid = p2.findall(url)[0]
            headers = {
                'user-agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36"}
            api = '''https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids={}'''.format(vid)
            response = requests.get(api, headers=headers)
            html = response.text
            data = json.loads(html)
            video_name = data["item_list"][0]["share_info"]["share_title"]
            return url, video_name
 
        def find_play(url):
            headers = {
                'user-agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36"}
            response = requests.get(url, headers=headers)
            html = response.text
            p = re.compile(r'playAddr: [\'\"](https.+?)[\'\"]')
            v_url = p.findall(html)
            return v_url[0]
 
        def save_vid(url, name,filePath,ui):
            p = re.compile(r"/playwm")
            url = p.sub('/play', url, count=1)
            headers = {
                'user-agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Mobile Safari/537.36'}
            response = requests.get(url, headers=headers)
            r = response.content
            with open(filePath+r'\{}.mp4'.format(name), 'wb') as f:
                f.write(r)
            QMessageBox.about(self.ui,
                              '提示',
                              '{}\n下載完成!'.format(name)
                              )
            #ui.url_input.clear()
        def main(share_url,ui):
            b = find_url(share_url)
            url = b[0]
            name = b[1]
            play_url = find_play(url)
            save_vid(play_url, name, self.path,ui)
 
 
        share_url = self.ui.url_input.toPlainText()
        p = re.compile(r"(https://v.douyin.com/.+?/)")
        share_urls = p.findall(share_url)
        if share_urls == []:
            QMessageBox.about(self.ui,
                              '警告',
                              '並沒有找到分享鏈接\n或者\n分享鏈接可能有誤!'
                              )
        else:
            for i in share_urls:
                main(i,self.ui)
 
    def find_hot(self):
        url_list = []
        names_list = []
        url = 'https://www.iesdouyin.com/web/api/v2/hotsearch/billboard/aweme/'
        headers = {
            'uesr-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36',
            'referer': 'https://www.iesdouyin.com/share/billboard/?id=0&utm_source=copy&utm_campaign=client_share&utm_medium=android&share_app_name=douyin'
        }
        response = requests.get(url, headers=headers)
        html = response.text
        data = json.loads(html)['aweme_list']
        error = ['/', '"', '\\', '|', '*', '>', '<', ':']
        for i in data:
            url = i['aweme_info']['video']["play_addr"]["url_list"][0]
            url_list.append(url)
            name = i['aweme_info']['share_info']['share_title']
            for each in error:
                if each in name:
                    name = name.replace(each, ' ')
            names_list.append(name)
        self.url_list = url_list
        self.names_list = names_list
        self.ui.listWidget.clear()
        self.data = {}
        count = 0
        for i in self.names_list:
            self.ui.listWidget.addItem(i)
            self.data[i] = self.url_list[count]
            count += 1
 
 
    def save(self):
        try:
            item = self.ui.listWidget.currentItem().text()
        except:
            QMessageBox.about(self.ui,
                              '警告',
                              '請先查詢並選擇!!'
                              )
        url = self.data[item]
        headers = {
            'user-agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Mobile Safari/537.36'}
        response = requests.get(url, headers=headers)
        r = response.content
        with open(self.path+r'\{}.mp4'.format(item), 'wb') as f:
            f.write(r)
            QMessageBox.about(self.ui,
                              '提示',
                              '下載完成!'
                              )
 
    def save2(self):
        try:
            item = self.ui.listWidget.currentItem().text()
        except:
            QMessageBox.about(self.ui,
                              '警告',
                              '請先查詢並選擇!!'
                              )
        url = self.data[item]
        p = re.compile(r"/playwm")
        url = p.sub('/play', url, count=1)
        headers = {
            'user-agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Mobile Safari/537.36'}
        response = requests.get(url, headers=headers)
        r = response.content
        with open(self.path+r'\{}.mp4'.format(item), 'wb') as f:
            f.write(r)
            QMessageBox.about(self.ui,
                              '提示',
                              '下載完成!'
                              )
 
png = b'圖片的二進制數據'#這個數據我刪了,太大了,你可以隨便放一個圖片的路徑就好
bit_ui = b'ui的二進制數據'#這個UI的數據我也給刪掉了,其實就是自己用qt畫的,你可以自己隨便畫一個。
 
with open('logo_3958666.png', 'wb') as g:
    g.write(png)
with open('抖音無水印.ui', 'wb') as f:
    f.write(bit_ui)
app = QApplication([])
app.setWindowIcon(QIcon('logo_3958666.png'))
os.remove('logo_3958666.png')
d = Download()
d.ui.show()
app.exec_()
 
本帖最後由 丶霽靈 於 2020-5-11 15:48 編輯

第一次發帖,沒有什麼經驗,如果違規了請大家趕緊提醒我,我直接刪除。
無水印視頻的方法大家都已經知道了,我很早之前也寫了一個腳本。最近學習了一下下pyside2,所以我用python寫了一個小工具。
運行圖:
 

對於安全問題請大家放心,就我這python的能力,有危險的東西我也寫不出來。
算了,直接發源碼:
[Python] 純文本查看 複製代碼
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
from PySide2.QtWidgets import QApplication, QMessageBox,QFileDialog
from PySide2.QtUiTools import QUiLoader
import requests
import re
import json
import os
from PySide2.QtGui import  QIcon
 
 
class Download:
 
    def __init__(self):
        self.ui = QUiLoader().load('抖音無水印.ui')
        os.remove('抖音無水印.ui')
        self.ui.search.clicked.connect(self.find_share)
        self.ui.search_2.clicked.connect(self.find_hot)
        self.ui.download.clicked.connect(self.save2)
        self.ui.download_2.clicked.connect(self.save)
        self.ui.findpath.clicked.connect(self.findpath)
        self.path =os.getcwd()
        self.ui.path.setText(self.path)
 
    def findpath(self):
        filePath = QFileDialog.getExistingDirectory(self.ui, "選擇存儲路徑")
        if filePath == None or filePath == '':
            pass
        else:
            self.path = filePath
            self.ui.path.setText(self.path)
 
    def find_share(self):
        def find_url(share_url):
            headers = {
                'user-agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Mobile Safari/537.36'}
            if share_url.find('v.douyin.com') < 0:
                return share_url
            response = requests.get(url=share_url, headers=headers,
                                    allow_redirects=False# allow_redirects = False 不允許跳轉
            url = response.headers['Location']
            p = re.compile(r"/playwm")
            url = p.sub('/play', url, count=1)
            p2 = re.compile(r"/video/(.+?)/")
            vid = p2.findall(url)[0]
            headers = {
                'user-agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36"}
            api = '''https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids={}'''.format(vid)
            response = requests.get(api, headers=headers)
            html = response.text
            data = json.loads(html)
            video_name = data["item_list"][0]["share_info"]["share_title"]
            return url, video_name
 
        def find_play(url):
            headers = {
                'user-agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36"}
            response = requests.get(url, headers=headers)
            html = response.text
            p = re.compile(r'playAddr: [\'\"](https.+?)[\'\"]')
            v_url = p.findall(html)
            return v_url[0]
 
        def save_vid(url, name,filePath,ui):
            p = re.compile(r"/playwm")
            url = p.sub('/play', url, count=1)
            headers = {
                'user-agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Mobile Safari/537.36'}
            response = requests.get(url, headers=headers)
            r = response.content
            with open(filePath+r'\{}.mp4'.format(name), 'wb') as f:
                f.write(r)
            QMessageBox.about(self.ui,
                              '提示',
                              '{}\n下載完成!'.format(name)
                              )
            #ui.url_input.clear()
        def main(share_url,ui):
            b = find_url(share_url)
            url = b[0]
            name = b[1]
            play_url = find_play(url)
            save_vid(play_url, name, self.path,ui)
 
 
        share_url = self.ui.url_input.toPlainText()
        p = re.compile(r"(https://v.douyin.com/.+?/)")
        share_urls = p.findall(share_url)
        if share_urls == []:
            QMessageBox.about(self.ui,
                              '警告',
                              '並沒有找到分享鏈接\n或者\n分享鏈接可能有誤!'
                              )
        else:
            for i in share_urls:
                main(i,self.ui)
 
    def find_hot(self):
        url_list = []
        names_list = []
        url = 'https://www.iesdouyin.com/web/api/v2/hotsearch/billboard/aweme/'
        headers = {
            'uesr-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36',
            'referer': 'https://www.iesdouyin.com/share/billboard/?id=0&utm_source=copy&utm_campaign=client_share&utm_medium=android&share_app_name=douyin'
        }
        response = requests.get(url, headers=headers)
        html = response.text
        data = json.loads(html)['aweme_list']
        error = ['/', '"', '\\', '|', '*', '>', '<', ':']
        for i in data:
            url = i['aweme_info']['video']["play_addr"]["url_list"][0]
            url_list.append(url)
            name = i['aweme_info']['share_info']['share_title']
            for each in error:
                if each in name:
                    name = name.replace(each, ' ')
            names_list.append(name)
        self.url_list = url_list
        self.names_list = names_list
        self.ui.listWidget.clear()
        self.data = {}
        count = 0
        for i in self.names_list:
            self.ui.listWidget.addItem(i)
            self.data[i] = self.url_list[count]
            count += 1
 
 
    def save(self):
        try:
            item = self.ui.listWidget.currentItem().text()
        except:
            QMessageBox.about(self.ui,
                              '警告',
                              '請先查詢並選擇!!'
                              )
        url = self.data[item]
        headers = {
            'user-agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Mobile Safari/537.36'}
        response = requests.get(url, headers=headers)
        r = response.content
        with open(self.path+r'\{}.mp4'.format(item), 'wb') as f:
            f.write(r)
            QMessageBox.about(self.ui,
                              '提示',
                              '下載完成!'
                              )
 
    def save2(self):
        try:
            item = self.ui.listWidget.currentItem().text()
        except:
            QMessageBox.about(self.ui,
                              '警告',
                              '請先查詢並選擇!!'
                              )
        url = self.data[item]
        p = re.compile(r"/playwm")
        url = p.sub('/play', url, count=1)
        headers = {
            'user-agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Mobile Safari/537.36'}
        response = requests.get(url, headers=headers)
        r = response.content
        with open(self.path+r'\{}.mp4'.format(item), 'wb') as f:
            f.write(r)
            QMessageBox.about(self.ui,
                              '提示',
                              '下載完成!'
                              )
 
png = b'圖片的二進制數據'#這個數據我刪了,太大了,你可以隨便放一個圖片的路徑就好
bit_ui = b'ui的二進制數據'#這個UI的數據我也給刪掉了,其實就是自己用qt畫的,你可以自己隨便畫一個。
 
with open('logo_3958666.png', 'wb') as g:
    g.write(png)
with open('抖音無水印.ui', 'wb') as f:
    f.write(bit_ui)
app = QApplication([])
app.setWindowIcon(QIcon('logo_3958666.png'))
os.remove('logo_3958666.png')
d = Download()
d.ui.show()
app.exec_()



軟件大小44M,有點大。其實我的腳本很小很小,但是我用pyinstaller打包出了110M的文件,然後又用Enigma Virtual Box打包壓縮成單文件。
當然,如果我爬蟲的目標網站更新或者api返回的數據也更新了,那我這軟件就過期嘍~

我只是作爲一個業餘愛好者分享一個學習python過程中的小作品,希望大家多多包涵~

我其實最在意的是,發佈這東西應該不違法吧?(滑稽)
如果大家發現了我這軟件有問題請直接留言,我會直接刪除。


藍奏雲:https://lanzous.com/iccvi4h
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章