美文网首页
下载抖音

下载抖音

作者: 月夜星空下 | 来源:发表于2020-07-01 13:26 被阅读0次
    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_()
    

    相关文章

      网友评论

          本文标题:下载抖音

          本文链接:https://www.haomeiwen.com/subject/ssvcqktx.html