糖豆广场舞视频下载工具Python版代码

最近听一朋友说最近在帮家里老人家下载糖豆广场舞视频到设备上播放,使用手机下载后还要拷贝到电脑再拷到设备广场舞播放设备上非常不方便,用了点时间用Python帮他写了个小工具,随便贴下代码

糖豆广场舞视频

Python代码

  1. # -*- coding:utf-8 -*-  
  2. # Time:2020/12/19 20:33  
  3. # Author:Chiser  
  4.   
  5. import requests  
  6. import os  
  7. import re  
  8.   
  9. tips = ''' 
  10. ****************************************************************** 
  11. ********************   糖豆视频下载工具 v1.0   ******************* 
  12. **************************  By:Chiser  *************************** 
  13. ****************************************************************** 
  14. '''  
  15. print(tips)  
  16. try:  
  17.     os.makedirs('./Downloader/')  
  18. except:  
  19.     pass  
  20. while True:  
  21.     url = input('请输入糖豆视频地址:')  
  22.     vid = ''.join(re.findall('vid=(.*?)&utm', url))  
  23.   
  24.     headers = {  
  25.         'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; MuMu 6.0.1 Build/V417IR) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.34 Safari/534.24',  
  26.         'Referer': 'https://share.tangdou.com/h5/play?vid=' + vid  
  27.     }  
  28.     url = 'https://api-h5.tangdou.com/sample/share/main?vid=' + vid  
  29.     response = requests.get(url, headers=headers).json()  
  30.     videos_url = response['data']['video_url']  
  31.     title = response['data']['title'] + '.mp4'  
  32.     name = {'?': '?', '*': '-', ':': ':', '"': '', '<': '【', '>': '】', '\\': '', '/': '', '|': '', ' ': ''}  
  33.   
  34.     for k, v in name.items():  
  35.         if k in title:  
  36.             title = title.replace(k, v)  
  37.     try:  
  38.         if os.path.exists('./Downloader/' + title):  
  39.             print('跳过下载!!!')  
  40.         else:  
  41.             print(title, '下载中!!!')  
  42.             response = requests.get(videos_url, stream=True)  
  43.             with open('./Downloader/' + title, 'wb') as f:  
  44.                 for chunnk in response.iter_content(chunk_size=5120):  
  45.                     f.write(chunnk)  
  46.             print(title, '下载完成!!!\n')  
  47.     except:  
  48.         pass  

后语

代码写的很渣,能用就行~奈何不会调用多线程下载,下载大视频速度有些慢,也没时间去折腾.

成品就不提供了,懒得上传~本来都不想撰写这篇文章,最终考虑还是意思意思一下~

给TA打赏
共{{data.count}}人
人已打赏
Python

python学习笔记:Python3在字符串中批量替换字符串为指定字符

2020-10-17 9:57:33

Python

Python学习笔记:Python读取本地Josn文件

2021-5-4 13:12:07

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
搜索