【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
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值