Skip to content

Commit

Permalink
更新多个模块,下载器更新
Browse files Browse the repository at this point in the history
  • Loading branch information
xhunmon committed Feb 28, 2022
1 parent 9783e6e commit 2ca898f
Show file tree
Hide file tree
Showing 64 changed files with 3,018 additions and 5,719 deletions.
8 changes: 5 additions & 3 deletions 001-Downloader/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# 资源下载器
本项目主要通过网络上开源的项目聚合成了一个跨平台的下载工具,可批量下载抖音、快手和YouTube视音频资源。下载地址:
本项目主要通过网络上开源的项目聚合成了一个跨平台的下载工具,可批量下载抖音、快手视音频资源。下载地址:

MacOS:[Downloader1.0.1-mac](https://github.com/xhunmon/PythonIsTools/releases/download/v1.0.1/downloader1.0.1-mac)
MacOS:[Downloader1.0.3-mac](https://github.com/xhunmon/PythonIsTools/releases/download/v1.0.3/Downloader1.0.3.app)

Window:[downloader1.0.1-window.exe](https://github.com/xhunmon/PythonIsTools/releases/download/v1.0.1/downloader1.0.1-window.exe)
Window:[downloader1.0.1-window.exe](https://github.com/xhunmon/PythonIsTools/releases/download/v1.0.1/downloader1.0.1-window.exe) (已停用,待更新)

效果如图:

Expand All @@ -25,6 +25,8 @@ pyinstaller -F -i res/logo.ico main.py -w
#③:再次进行打包,参考installer-mac.sh
pyinstaller -F -i res/logo.ico main.spec -w
```
打包脚本与配置已放在 `doc` 目录下,需要拷贝出根目录进行打包。

注意:
pyinstaller打包工具的版本与python版本、python所需第三方库以及操作系统会存在各种问题,所以需要看日志查找问题。例如:打包后运用,发现导入pyppeteer报错,通过降低版本后能正常使用:pip install pyppeteer==0.2.2

Expand Down
6 changes: 3 additions & 3 deletions 001-Downloader/config.ini
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# 常用配置模块
[common]
#软件使用截止日期
expired_time=2022/12/15 23:59:59
expired_time=2025/12/15 23:59:59

#app的版本名称
version_name=1.0.2
version_name=1.0.3

#app的版本号
version_code=102
version_code=103
30 changes: 0 additions & 30 deletions 001-Downloader/doc/installer-window.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@ exe = EXE(pyz,
target_arch=None,
codesign_identity=None,
entitlements_file=None , icon='res/logo.ico')
app = BUNDLE(exe,
name='Downloader.app',
icon='res/logo.ico',
bundle_identifier=None)
9 changes: 9 additions & 0 deletions 001-Downloader/doc/mac-sh/pyinstaller.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

pyinstaller -F -i res/logo.ico main.spec main.py -w \
-p type_enum.py \
-p ui.py \
-p utils.py \
-p downloader.py \
-p douyin/dy_download.py \
-p kuaishou/ks_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@ exe = EXE(pyz,
target_arch=None,
codesign_identity=None,
entitlements_file=None , icon='res\\logo.ico')
app = BUNDLE(exe,
name='Downloader.exe',
icon='res\\logo.ico',
bundle_identifier=None)
9 changes: 9 additions & 0 deletions 001-Downloader/doc/win-sh/pyinstaller.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

pyinstaller -F -i res\\logo.ico -w main.spec main.py
-p type_enum.py
-p ui.py
-p utils.py
-p downloader.py
-p douyin\\dy_download.py
-p kuaishou\\ks_download.py
89 changes: 49 additions & 40 deletions 001-Downloader/douyin/dy_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
import os
import re
import time
from urllib import parse

import requests
import requests_html

from downloader import Downloader

Expand Down Expand Up @@ -132,6 +130,7 @@ def get_data(self, api_post_url, max_cursor):
Downloader.print_ui('[ 用户 ]:' + str(self.nickname) + '\r')
max_cursor = html['max_cursor']
result = html['aweme_list']
self.count = len(result)
Downloader.print_ui('----抓获数据成功----\r')

# 处理第一页视频信息
Expand All @@ -150,7 +149,8 @@ def next_data(self, max_cursor):
return
user_url = self.user
# 获取用户sec_uid
key = re.findall('/user/(.*?)\?', str(user_url))[0]
# key = re.findall('/user/(.*?)\?', str(user_url))[0]
key = re.findall('/user/(.*?)$', str(user_url))[0]
if not key:
key = user_url[28:83]

Expand All @@ -165,20 +165,22 @@ def next_data(self, max_cursor):
self.end = True
return
index += 1
Downloader.print_ui('----正在对' + max_cursor + '页进行第 %d 次尝试----\r' % index)
# Downloader.print_ui('----正在对' + max_cursor + '页进行第 %d 次尝试----\r' % index)
Downloader.print_ui('----正在对{}页进行第 {} 次尝试----\r'.format(max_cursor, index))
time.sleep(0.3)
response = requests.get(url=api_naxt_post_url, headers=self.headers)
html = json.loads(response.content.decode())
if self.end == False:
# 下一页值
max_cursor = html['max_cursor']
result = html['aweme_list']
Downloader.print_ui('----' + max_cursor + '页抓获数据成功----\r')
self.count = len(result)
Downloader.print_ui('----{}页抓获数据成功----\r'.format(max_cursor))
# 处理下一页视频信息
self.video_info(result, max_cursor)
else:
self.end == True
Downloader.print_ui('----' + max_cursor + '页抓获数据失败----\r')
self.end = True
Downloader.print_ui('----{}页抓获数据失败----\r'.format(max_cursor))
# sys.exit()

# 处理视频信息
Expand Down Expand Up @@ -224,40 +226,47 @@ def videos_download(self, count, author_list, video_list, aweme_id, nickname, ma
except:
pass
Downloader.add_downloading_count()
try:
jx_url = f'https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids={aweme_id[i]}' # 官方接口
js = json.loads(requests.get(url=jx_url, headers=self.headers).text)
music_url = str(js['item_list'][0]['music']['play_url']['url_list'][0])
music_title = str(js['item_list'][0]['music']['author'])
if self.musicarg == "yes": # 保留音频
music = requests.get(music_url) # 保存音频
start = time.time() # 下载开始时间
size = 0 # 初始化已下载大小
chunk_size = 1024 # 每次下载的数据大小
content_size = int(music.headers['content-length']) # 下载文件总大小
if music.status_code == 200: # 判断是否响应成功
Downloader.print_ui('[ 音频 ]:' + author_list[i] + '[文件 大小]:{size:.2f} MB'.format(
size=content_size / chunk_size / 1024)) # 开始下载,显示下载文件大小
# m_url = pre_save + music_title + '-[' + author_list[i] + '].mp3'
m_url = os.path.join(pre_save,
nickname[i] + "-" + music_title + '-[' + author_list[i] + '].mp3')
Downloader.print_ui("路径:" + m_url)
with open(m_url, 'wb') as file: # 显示进度条
for data in music.iter_content(chunk_size=chunk_size):
file.write(data)
size += len(data)
Downloader.print_ui('\r' + music_title + '\n[下载进度]:%s%.2f%%' % (
'>' * int(size * 50 / content_size), float(size / content_size * 100)))
end = time.time() # 下载结束时间
Downloader.print_ui('\n' + music_title + '\n[下载完成]:耗时: %.2f秒\n' % (end - start)) # 输出下载用时时间
Downloader.add_success_count()
except Exception as error:
# Downloader.print_ui2(error)
Downloader.print_ui('该页音频没有' + str(self.count) + '个,已为您跳过\r')
Downloader.add_failed_count()
break
# try:
# jx_url = f'https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids={aweme_id[i]}' # 官方接口
# js = json.loads(requests.get(url=jx_url, headers=self.headers).text)
# music_url = str(js['item_list'][0]['music']['play_url']['url_list'][0])
# music_title = str(js['item_list'][0]['music']['author'])
# if self.musicarg == "yes": # 保留音频
# music = requests.get(music_url) # 保存音频
# start = time.time() # 下载开始时间
# size = 0 # 初始化已下载大小
# chunk_size = 1024 # 每次下载的数据大小
# content_size = int(music.headers['content-length']) # 下载文件总大小
# if music.status_code == 200: # 判断是否响应成功
# Downloader.print_ui('[ 音频 ]:' + author_list[i] + '[文件 大小]:{size:.2f} MB'.format(
# size=content_size / chunk_size / 1024)) # 开始下载,显示下载文件大小
# # m_url = pre_save + music_title + '-[' + author_list[i] + '].mp3'
# m_url = os.path.join(pre_save,
# nickname[i] + "-" + music_title + '-[' + author_list[i] + '].mp3')
# Downloader.print_ui("路径:" + m_url)
# with open(m_url, 'wb') as file: # 显示进度条
# for data in music.iter_content(chunk_size=chunk_size):
# file.write(data)
# size += len(data)
# Downloader.print_ui('\r' + music_title + '\n[下载进度]:%s%.2f%%' % (
# '>' * int(size * 50 / content_size), float(size / content_size * 100)))
# end = time.time() # 下载结束时间
# Downloader.print_ui('\n' + music_title + '\n[下载完成]:耗时: %.2f秒\n' % (end - start)) # 输出下载用时时间
# Downloader.add_success_count()
# except Exception as error:
# # Downloader.print_ui2(error)
# Downloader.print_ui('该页音频没有' + str(self.count) + '个\r')
# # Downloader.add_failed_count()
# # break

try:
v_url = os.path.join(pre_save, nickname[i] + "-" + '[' + author_list[i] + '].mp4')
# 如果本地已经有了就跳过
if os.path.exists(v_url):
Downloader.print_ui('{}-已存在!'.format(v_url))
Downloader.add_success_count()
continue

video = requests.get(video_list[i], headers=self.headers) # 保存视频
start = time.time() # 下载开始时间
size = 0 # 初始化已下载大小
Expand All @@ -267,7 +276,7 @@ def videos_download(self, count, author_list, video_list, aweme_id, nickname, ma
Downloader.print_ui(
'[ 视频 ]:' + nickname[i] + '-' + author_list[i] + '[文件 大小]:{size:.2f} MB'.format(
size=content_size / 1024 / 1024)) # 开始下载,显示下载文件大小
v_url = os.path.join(pre_save, nickname[i] + "-" + '[' + author_list[i] + '].mp4')
# v_url = os.path.join(pre_save, nickname[i] + "-" + '[' + author_list[i] + '].mp4')
# v_url = pre_save + '[' + author_list[i] + '].mp4'
Downloader.print_ui("路径:" + v_url)
with open(v_url, 'wb') as file: # 显示进度条
Expand Down
9 changes: 4 additions & 5 deletions 001-Downloader/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ def print_hint():
Downloader.print_ui(
"""
使用说明:
1、youtube下载需要先让电脑连接外网,地址如:https://www.youtube.com/watch?v=jKhP750VdXw
2、快手下载用户批量视频如:https://www.kuaishou.com/profile/xxx
3、快手下载单条视频如:https://www.kuaishou.com/short-video/xxx
4、抖音下载用户批量视频如:https://www.douyin.com/user/xxx
5、抖音下载单条视频如:https://www.douyin.com/video/xxx
1、快手下载用户批量视频如:https://www.kuaishou.com/profile/xxx
2、快手下载单条视频如:https://www.kuaishou.com/short-video/xxx
3、抖音下载用户批量视频如:https://www.douyin.com/user/xxx
4、抖音下载单条视频如:https://www.douyin.com/video/xxx
"""
)

Expand Down
30 changes: 0 additions & 30 deletions 001-Downloader/installer-mac.sh

This file was deleted.

1 change: 1 addition & 0 deletions 001-Downloader/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# 主模块执行
if __name__ == "__main__":
path = os.path.dirname(os.path.realpath(sys.argv[0]))
# path = os.path.dirname('/Users/Qincji/Documents/zmt/')
app = Ui()
app.set_dir(path)
# to do
Expand Down
19 changes: 0 additions & 19 deletions 001-Downloader/pytube/__init__.py

This file was deleted.

Loading

0 comments on commit 2ca898f

Please sign in to comment.