mirror of
https://github.com/soimort/you-get.git
synced 2025-02-09 11:42:30 +03:00
refactor --output-filename argument, removed the global variable.
Signed-off-by: hanlz <7954178+hanlz@users.noreply.github.com>
This commit is contained in:
parent
582d89e2f2
commit
c9aad72034
@ -134,7 +134,6 @@ force = False
|
|||||||
player = None
|
player = None
|
||||||
extractor_proxy = None
|
extractor_proxy = None
|
||||||
cookies = None
|
cookies = None
|
||||||
output_filename = None
|
|
||||||
auto_rename = False
|
auto_rename = False
|
||||||
|
|
||||||
fake_headers = {
|
fake_headers = {
|
||||||
@ -838,9 +837,8 @@ class DummyProgressBar:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def get_output_filename(urls, title, ext, output_dir, merge):
|
def get_output_filename(urls, title, ext, output_dir, merge, output_filename=None):
|
||||||
# lame hack for the --output-filename option
|
# lame hack for the --output-filename option
|
||||||
global output_filename
|
|
||||||
if output_filename:
|
if output_filename:
|
||||||
if ext:
|
if ext:
|
||||||
return output_filename + '.' + ext
|
return output_filename + '.' + ext
|
||||||
@ -897,7 +895,7 @@ def download_urls(
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
title = tr(get_filename(title))
|
title = tr(get_filename(title))
|
||||||
output_filename = get_output_filename(urls, title, ext, output_dir, merge)
|
output_filename = get_output_filename(urls, title, ext, output_dir, merge, **kwargs)
|
||||||
output_filepath = os.path.join(output_dir, output_filename)
|
output_filepath = os.path.join(output_dir, output_filename)
|
||||||
|
|
||||||
if total_size:
|
if total_size:
|
||||||
@ -1029,7 +1027,7 @@ def download_rtmp_url(
|
|||||||
|
|
||||||
def download_url_ffmpeg(
|
def download_url_ffmpeg(
|
||||||
url, title, ext, params={}, total_size=0, output_dir='.', refer=None,
|
url, title, ext, params={}, total_size=0, output_dir='.', refer=None,
|
||||||
merge=True, faker=False, stream=True
|
merge=True, faker=False, stream=True, output_filename=None
|
||||||
):
|
):
|
||||||
assert url
|
assert url
|
||||||
if dry_run:
|
if dry_run:
|
||||||
@ -1046,7 +1044,7 @@ def download_url_ffmpeg(
|
|||||||
from .processor.ffmpeg import has_ffmpeg_installed, ffmpeg_download_stream
|
from .processor.ffmpeg import has_ffmpeg_installed, ffmpeg_download_stream
|
||||||
assert has_ffmpeg_installed(), 'FFmpeg not installed.'
|
assert has_ffmpeg_installed(), 'FFmpeg not installed.'
|
||||||
|
|
||||||
global output_filename
|
# global output_filename
|
||||||
if output_filename:
|
if output_filename:
|
||||||
dotPos = output_filename.rfind('.')
|
dotPos = output_filename.rfind('.')
|
||||||
if dotPos > 0:
|
if dotPos > 0:
|
||||||
@ -1435,7 +1433,6 @@ def script_main(download, download_playlist, **kwargs):
|
|||||||
global json_output
|
global json_output
|
||||||
global player
|
global player
|
||||||
global extractor_proxy
|
global extractor_proxy
|
||||||
global output_filename
|
|
||||||
global auto_rename
|
global auto_rename
|
||||||
|
|
||||||
output_filename = args.output_filename
|
output_filename = args.output_filename
|
||||||
@ -1497,6 +1494,8 @@ def script_main(download, download_playlist, **kwargs):
|
|||||||
extra['extractor_proxy'] = extractor_proxy
|
extra['extractor_proxy'] = extractor_proxy
|
||||||
if stream_id:
|
if stream_id:
|
||||||
extra['stream_id'] = stream_id
|
extra['stream_id'] = stream_id
|
||||||
|
if output_filename:
|
||||||
|
extra['output_filename'] = output_filename
|
||||||
download_main(
|
download_main(
|
||||||
download, download_playlist,
|
download, download_playlist,
|
||||||
URLs, args.playlist,
|
URLs, args.playlist,
|
||||||
|
3
src/you_get/extractor.py
Normal file → Executable file
3
src/you_get/extractor.py
Normal file → Executable file
@ -225,7 +225,8 @@ class VideoExtractor():
|
|||||||
download_urls(urls, self.title, ext, total_size, headers=headers,
|
download_urls(urls, self.title, ext, total_size, headers=headers,
|
||||||
output_dir=kwargs['output_dir'],
|
output_dir=kwargs['output_dir'],
|
||||||
merge=kwargs['merge'],
|
merge=kwargs['merge'],
|
||||||
av=stream_id in self.dash_streams)
|
av=stream_id in self.dash_streams,
|
||||||
|
output_filename=kwargs.get('output_filename'))
|
||||||
if 'caption' not in kwargs or not kwargs['caption']:
|
if 'caption' not in kwargs or not kwargs['caption']:
|
||||||
print('Skipping captions or danmuku.')
|
print('Skipping captions or danmuku.')
|
||||||
return
|
return
|
||||||
|
2
src/you_get/extractors/douyutv.py
Normal file → Executable file
2
src/you_get/extractors/douyutv.py
Normal file → Executable file
@ -74,7 +74,7 @@ def douyutv_download(url, output_dir='.', merge=True, info_only=False, **kwargs)
|
|||||||
|
|
||||||
print_info(site_info, title, 'flv', float('inf'))
|
print_info(site_info, title, 'flv', float('inf'))
|
||||||
if not info_only:
|
if not info_only:
|
||||||
download_url_ffmpeg(real_url, title, 'flv', params={}, output_dir=output_dir, merge=merge)
|
download_url_ffmpeg(real_url, title, 'flv', params={}, output_dir=output_dir, merge=merge, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
site_info = "douyu.com"
|
site_info = "douyu.com"
|
||||||
|
2
src/you_get/extractors/huomaotv.py
Normal file → Executable file
2
src/you_get/extractors/huomaotv.py
Normal file → Executable file
@ -28,7 +28,7 @@ def huomaotv_download(url, output_dir='.', merge=True, info_only=False, **kwargs
|
|||||||
print_info(site_info, title, 'm3u8', float('inf'))
|
print_info(site_info, title, 'm3u8', float('inf'))
|
||||||
|
|
||||||
if not info_only:
|
if not info_only:
|
||||||
download_url_ffmpeg(m3u8_url, title, 'm3u8', None, output_dir=output_dir, merge=merge)
|
download_url_ffmpeg(m3u8_url, title, 'm3u8', None, output_dir=output_dir, merge=merge, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
site_info = 'huomao.com'
|
site_info = 'huomao.com'
|
||||||
|
2
src/you_get/extractors/iqiyi.py
Normal file → Executable file
2
src/you_get/extractors/iqiyi.py
Normal file → Executable file
@ -206,7 +206,7 @@ class Iqiyi(VideoExtractor):
|
|||||||
# For legacy main()
|
# For legacy main()
|
||||||
|
|
||||||
#Here's the change!!
|
#Here's the change!!
|
||||||
download_url_ffmpeg(urls[0], self.title, 'mp4', output_dir=kwargs['output_dir'], merge=kwargs['merge'], stream=False)
|
download_url_ffmpeg(urls[0], self.title, 'mp4', output_dir=kwargs['output_dir'], merge=kwargs['merge'], stream=False, **kwargs)
|
||||||
|
|
||||||
if not kwargs['caption']:
|
if not kwargs['caption']:
|
||||||
print('Skipping captions.')
|
print('Skipping captions.')
|
||||||
|
2
src/you_get/extractors/showroom.py
Normal file → Executable file
2
src/you_get/extractors/showroom.py
Normal file → Executable file
@ -53,7 +53,7 @@ def showroom_download_by_room_id(room_id, output_dir = '.', merge = False, info_
|
|||||||
type_, ext, size = url_info(stream_url)
|
type_, ext, size = url_info(stream_url)
|
||||||
print_info(site_info, title, type_, size)
|
print_info(site_info, title, type_, size)
|
||||||
if not info_only:
|
if not info_only:
|
||||||
download_url_ffmpeg(url=stream_url, title=title, ext= 'mp4', output_dir=output_dir)
|
download_url_ffmpeg(url=stream_url, title=title, ext= 'mp4', output_dir=output_dir, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
|
2
src/you_get/extractors/universal.py
Normal file → Executable file
2
src/you_get/extractors/universal.py
Normal file → Executable file
@ -52,7 +52,7 @@ def universal_download(url, output_dir='.', merge=True, info_only=False, **kwarg
|
|||||||
print_info(site_info, page_title, type_, size)
|
print_info(site_info, page_title, type_, size)
|
||||||
if not info_only:
|
if not info_only:
|
||||||
download_url_ffmpeg(url=hls_url, title=page_title,
|
download_url_ffmpeg(url=hls_url, title=page_title,
|
||||||
ext='mp4', output_dir=output_dir)
|
ext='mp4', output_dir=output_dir, **kwargs)
|
||||||
return
|
return
|
||||||
|
|
||||||
# most common media file extensions on the Internet
|
# most common media file extensions on the Internet
|
||||||
|
2
src/you_get/extractors/youtube.py
Normal file → Executable file
2
src/you_get/extractors/youtube.py
Normal file → Executable file
@ -205,7 +205,7 @@ class YouTube(VideoExtractor):
|
|||||||
if 'info_only' in kwargs and kwargs['info_only']:
|
if 'info_only' in kwargs and kwargs['info_only']:
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
download_url_ffmpeg(hlsvp, self.title, 'mp4')
|
download_url_ffmpeg(hlsvp, self.title, 'mp4', **kwargs)
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
for stream in stream_list:
|
for stream in stream_list:
|
||||||
|
2
src/you_get/extractors/zhanqi.py
Normal file → Executable file
2
src/you_get/extractors/zhanqi.py
Normal file → Executable file
@ -33,7 +33,7 @@ def zhanqi_live(room_id, merge=True, output_dir='.', info_only=False, **kwargs):
|
|||||||
|
|
||||||
print_info(site_info, title, 'm3u8', 0, m3u8_url=m3u8_url, m3u8_type='master')
|
print_info(site_info, title, 'm3u8', 0, m3u8_url=m3u8_url, m3u8_type='master')
|
||||||
if not info_only:
|
if not info_only:
|
||||||
download_url_ffmpeg(m3u8_url, title, 'mp4', output_dir=output_dir, merge=merge)
|
download_url_ffmpeg(m3u8_url, title, 'mp4', output_dir=output_dir, merge=merge, **kwargs)
|
||||||
|
|
||||||
def zhanqi_video(video_id, output_dir='.', info_only=False, merge=True, **kwargs):
|
def zhanqi_video(video_id, output_dir='.', info_only=False, merge=True, **kwargs):
|
||||||
api_url = 'https://www.zhanqi.tv/api/static/v2.1/video/{}.json'.format(video_id)
|
api_url = 'https://www.zhanqi.tv/api/static/v2.1/video/{}.json'.format(video_id)
|
||||||
|
Loading…
Reference in New Issue
Block a user