Skip to content

Commit

Permalink
add yinyuetai
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlesPikachu committed Jul 12, 2019
1 parent 4f8d094 commit 1fb8a1b
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 9 deletions.
8 changes: 6 additions & 2 deletions Cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(self, **kwargs):
当前路径下的videos文件夹内
************************************************************
'''
self.RESOURCES = ['腾讯视频']
self.RESOURCES = ['腾讯视频', '音悦台MV']
self.platform_now = None
self.platform_now_name = None
self.is_select_platform = False
Expand All @@ -40,7 +40,9 @@ def run(self):
print(self.INFO)
url = self.__input('[%s-INFO]: 请输入视频链接 --> ' % self.platform_now_name)
try:
self.__download(url, 'videos')
res = self.__download(url, 'videos')
if not res:
raise RuntimeError('error')
except:
print('<ERROR>--链接解析失败, 请确定输入的链接与平台对应--<ERROR>')
'''下载视频'''
Expand All @@ -56,6 +58,8 @@ def __selectPlatform(self):
platform_idx = self.__input('请选择平台号(1-%d):' % len(self.RESOURCES))
if platform_idx == '1':
return tecent.tecent(), 'tecent'
elif platform_idx == '2':
return yinyuetai.yinyuetai(), 'yinyuetai'
else:
print('<ERROR>--平台号输入有误, 请重新输入--<ERROR>')
'''处理用户输入'''
Expand Down
2 changes: 1 addition & 1 deletion LOG/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
- Detail: Support downloading tecent video.
#### 2019-07-12
- Version: V2.0.0
- Detail: Clear the code
- Detail: Clean the code
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ prepare
# Support
- [x] [tecent](https://v.qq.com/)
- [x] [yinyuetai](http://www.yinyuetai.com)
# Usage
#### Step1
Expand Down Expand Up @@ -37,7 +38,7 @@ run cmd.py, for example:
![img](./Screenshot/cmd.png)
# Log
see Log dir → [click](./Log)
see Log dir → [click](./LOG)
# More
#### WeChat Official Accounts
Expand Down
2 changes: 1 addition & 1 deletion platforms/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__all__ = ['tecent']
__all__ = ['tecent', 'yinyuetai']
4 changes: 2 additions & 2 deletions platforms/tecent.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __getvideoinfos(self, url):
fc = info_json['vl']['vi'][0]['cl']['fc']
fn = info_json['vl']['vi'][0]['fn']
except:
return [None, None]
return ['', '']
assert fn.split('.')[0] == lnk
constant, video_type = fn.split('.')[-2], fn.split('.')[-1]
flag = True
Expand All @@ -87,7 +87,7 @@ def __getvideoinfos(self, url):
key = res_json['v1']['vi'][0]['fvkey']
download_url_part = '{}{}?vkey={}'.format(url, lnk+'.'+video_type, key)
except:
download_url_part = None
download_url_part = ''
else:
key = res_json.get('key')
download_url_part = '{}{}?vkey={}'.format(url, fn, key)
Expand Down
57 changes: 57 additions & 0 deletions platforms/yinyuetai.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
'''
Function:
音悦台MV下载: http://www.yinyuetai.com
Author:
Charles
微信公众号:
Charles的皮卡丘
'''
import re
import requests
from utils.utils import *


'''
Input:
--url: 视频地址
--savepath: 视频下载后保存的路径
Output:
--is_success: 下载是否成功的BOOL值
'''
class yinyuetai():
def __init__(self):
self.headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36'
}
self.info_url = 'http://www.yinyuetai.com/insite/get-video-info?flex=true&videoId={}'
'''外部调用'''
def get(self, url, savepath='videos'):
video_infos = self.__getvideoinfos(url)
is_success = self.__download(video_infos, savepath)
return is_success
'''下载'''
def __download(self, video_infos, savepath):
checkFolder(savepath)
download_url = video_infos[0]
video_name = 'yinyuetai_' + video_infos[1] + '.mp4'
try:
is_success = downloadBASE(url=download_url, savename=video_name, savepath=savepath, headers=self.headers, stream=True, verify=False)
except:
is_success = False
return is_success
'''获得视频信息'''
def __getvideoinfos(self, url):
mvid = url.split('/')[-1]
res = requests.get(self.info_url.format(mvid), headers=self.headers)
pattern = re.compile(r'http://\w*?\.yinyuetai\.com/uploads/videos/common/.*?(?=&br)')
re_result = re.findall(pattern, res.text)
# 选择质量最佳的视频
download_url = re_result[-1]
video_infos = [download_url, mvid]
return video_infos


'''test'''
if __name__ == '__main__':
url = 'http://v.yinyuetai.com/video/3247548'
yinyuetai().get(url, savepath='videos')
4 changes: 2 additions & 2 deletions utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

'''进度条下载'''
# -------------------------------------------------------------------------------------------
def downloaderBASE(url, savename, savepath, headers, stream=True, verify=False):
def downloadBASE(url, savename, savepath, headers, stream=True, verify=False):
checkFolder(savepath)
with closing(requests.get(url, headers=headers, stream=stream, verify=verify)) as res:
total_size = int(res.headers['content-length'])
Expand Down Expand Up @@ -106,7 +106,7 @@ def downloadTMS(video_urls, savename, savepath='videos', max_retries=5, headers=
is_success = False
break
video_url = video_urls[i]
flag = downloaderBASE(video_url, savename='temp_%d.%s' % (i, savename.split('.')[-1]), savepath=savepath, headers=headers, stream=True, verify=False)
flag = downloadBASE(video_url, savename='temp_%d.%s' % (i, savename.split('.')[-1]), savepath=savepath, headers=headers, stream=True, verify=False)
if not flag:
i -= 1
max_retries -= 1
Expand Down

0 comments on commit 1fb8a1b

Please sign in to comment.