鱼C论坛

 找回密码
 立即注册
查看: 1297|回复: 2

[作品展示] 【UI可执行程序版本】抖音无水印视频下载,附带源码

[复制链接]
发表于 2020-5-7 18:09:22 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
图片:
微信图片_20200507180600.png 批注 2020-05-07 180623.png
可执行单文件下载连接在最后

源码展示,我把图片变成二进制存储在了源码里面,但是太长了我就删了。ui的二进制也没了,你们可以自己去画嘛。但是核心方法都在。
  1. from PySide2.QtWidgets import QApplication, QMessageBox,QFileDialog
  2. from PySide2.QtUiTools import QUiLoader
  3. import requests
  4. import re
  5. import json
  6. import os
  7. from PySide2.QtGui import  QIcon


  8. class Download:

  9.     def __init__(self):
  10.         self.ui = QUiLoader().load('抖音无水印.ui')
  11.         os.remove('抖音无水印.ui')
  12.         self.ui.search.clicked.connect(self.find_share)
  13.         self.ui.search_2.clicked.connect(self.find_hot)
  14.         self.ui.download.clicked.connect(self.save2)
  15.         self.ui.download_2.clicked.connect(self.save)
  16.         self.ui.findpath.clicked.connect(self.findpath)
  17.         self.path =os.getcwd()
  18.         self.ui.path.setText(self.path)

  19.     def findpath(self):
  20.         filePath = QFileDialog.getExistingDirectory(self.ui, "选择存储路径")
  21.         if filePath == None or filePath == '':
  22.             pass
  23.         else:
  24.             self.path = filePath
  25.             self.ui.path.setText(self.path)

  26.     def find_share(self):
  27.         def find_url(share_url):
  28.             headers = {
  29.                 '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'}
  30.             if share_url.find('v.douyin.com') < 0:
  31.                 return share_url
  32.             response = requests.get(url=share_url, headers=headers,
  33.                                     allow_redirects=False)  # allow_redirects = False 不允许跳转
  34.             url = response.headers['Location']
  35.             p = re.compile(r"/playwm")
  36.             url = p.sub('/play', url, count=1)
  37.             p2 = re.compile(r"/video/(.+?)/")
  38.             vid = p2.findall(url)[0]
  39.             headers = {
  40.                 '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"}
  41.             api = '''https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids={}'''.format(vid)
  42.             response = requests.get(api, headers=headers)
  43.             html = response.text
  44.             data = json.loads(html)
  45.             video_name = data["item_list"][0]["share_info"]["share_title"]
  46.             return url, video_name

  47.         def find_play(url):
  48.             headers = {
  49.                 '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"}
  50.             response = requests.get(url, headers=headers)
  51.             html = response.text
  52.             p = re.compile(r'playAddr: [\'"](https.+?)[\'"]')
  53.             v_url = p.findall(html)
  54.             return v_url[0]

  55.         def save_vid(url, name,filePath,ui):
  56.             p = re.compile(r"/playwm")
  57.             url = p.sub('/play', url, count=1)
  58.             headers = {
  59.                 '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'}
  60.             response = requests.get(url, headers=headers)
  61.             r = response.content
  62.             with open(filePath+r'\{}.mp4'.format(name), 'wb') as f:
  63.                 f.write(r)
  64.             QMessageBox.about(self.ui,
  65.                               '提示',
  66.                               '{}\n下载完成!'.format(name)
  67.                               )
  68.             #ui.url_input.clear()
  69.         def main(share_url,ui):
  70.             b = find_url(share_url)
  71.             url = b[0]
  72.             name = b[1]
  73.             play_url = find_play(url)
  74.             save_vid(play_url, name, self.path,ui)


  75.         share_url = self.ui.url_input.toPlainText()
  76.         p = re.compile(r"(https://v.douyin.com/.+?/)")
  77.         share_urls = p.findall(share_url)
  78.         if share_urls == []:
  79.             QMessageBox.about(self.ui,
  80.                               '警告',
  81.                               '并没有找到分享链接\n或者\n分享链接可能有误!'
  82.                               )
  83.         else:
  84.             for i in share_urls:
  85.                 main(i,self.ui)

  86.     def find_hot(self):
  87.         url_list = []
  88.         names_list = []
  89.         url = 'https://www.iesdouyin.com/web/api/v2/hotsearch/billboard/aweme/'
  90.         headers = {
  91.             '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',
  92.             'referer': 'https://www.iesdouyin.com/share/billboard/?id=0&utm_source=copy&utm_campaign=client_share&utm_medium=android&share_app_name=douyin'
  93.         }
  94.         response = requests.get(url, headers=headers)
  95.         html = response.text
  96.         data = json.loads(html)['aweme_list']
  97.         error = ['/', '"', '\\', '|', '*', '>', '<', ':']
  98.         for i in data:
  99.             url = i['aweme_info']['video']["play_addr"]["url_list"][0]
  100.             url_list.append(url)
  101.             name = i['aweme_info']['share_info']['share_title']
  102.             for each in error:
  103.                 if each in name:
  104.                     name = name.replace(each, ' ')
  105.             names_list.append(name)
  106.         self.url_list = url_list
  107.         self.names_list = names_list
  108.         self.ui.listWidget.clear()
  109.         self.data = {}
  110.         count = 0
  111.         for i in self.names_list:
  112.             self.ui.listWidget.addItem(i)
  113.             self.data[i] = self.url_list[count]
  114.             count += 1


  115.     def save(self):
  116.         try:
  117.             item = self.ui.listWidget.currentItem().text()
  118.         except:
  119.             QMessageBox.about(self.ui,
  120.                               '警告',
  121.                               '请先查询并选择!!'
  122.                               )
  123.         url = self.data[item]
  124.         headers = {
  125.             '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'}
  126.         response = requests.get(url, headers=headers)
  127.         r = response.content
  128.         with open(self.path+r'\{}.mp4'.format(item), 'wb') as f:
  129.             f.write(r)
  130.             QMessageBox.about(self.ui,
  131.                               '提示',
  132.                               '下载完成!'
  133.                               )

  134.     def save2(self):
  135.         try:
  136.             item = self.ui.listWidget.currentItem().text()
  137.         except:
  138.             QMessageBox.about(self.ui,
  139.                               '警告',
  140.                               '请先查询并选择!!'
  141.                               )
  142.         url = self.data[item]
  143.         p = re.compile(r"/playwm")
  144.         url = p.sub('/play', url, count=1)
  145.         headers = {
  146.             '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'}
  147.         response = requests.get(url, headers=headers)
  148.         r = response.content
  149.         with open(self.path+r'\{}.mp4'.format(item), 'wb') as f:
  150.             f.write(r)
  151.             QMessageBox.about(self.ui,
  152.                               '提示',
  153.                               '下载完成!'
  154.                               )

  155. png = b'这是图片的二进制'
  156. bit_ui = b'ui自己画'

  157. with open('logo_3958666.png', 'wb') as g:
  158.     g.write(png)
  159. with open('抖音无水印.ui', 'wb') as f:
  160.     f.write(bit_ui)
  161. app = QApplication([])
  162. app.setWindowIcon(QIcon('logo_3958666.png'))
  163. os.remove('logo_3958666.png')
  164. d = Download()
  165. d.ui.show()
  166. app.exec_()

复制代码



成品链接https://lanzous.com/iccvi4h
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-5-7 18:28:11 | 显示全部楼层
沙发
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-5-7 18:33:24 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-18 22:39

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表