mirror of
https://github.com/soimort/you-get.git
synced 2025-02-09 03:37:52 +03:00
add new option audio extraction
add option -e you can extract audio form downloaded video
This commit is contained in:
parent
61b74e3ce9
commit
a12164119d
@ -138,6 +138,8 @@ cookies = None
|
|||||||
output_filename = None
|
output_filename = None
|
||||||
auto_rename = False
|
auto_rename = False
|
||||||
insecure = False
|
insecure = False
|
||||||
|
extract_audio = False
|
||||||
|
extract_format = 'mp3'
|
||||||
|
|
||||||
fake_headers = {
|
fake_headers = {
|
||||||
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', # noqa
|
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', # noqa
|
||||||
@ -981,6 +983,9 @@ def download_urls(
|
|||||||
headers=headers, **kwargs
|
headers=headers, **kwargs
|
||||||
)
|
)
|
||||||
bar.done()
|
bar.done()
|
||||||
|
if extract_audio:
|
||||||
|
from .processor.ffmpeg import ffmpeg_extract_audio_from_video
|
||||||
|
ffmpeg_extract_audio_from_video(output_filepath, ext=extract_format)
|
||||||
else:
|
else:
|
||||||
parts = []
|
parts = []
|
||||||
print('Downloading %s ...' % tr(output_filename))
|
print('Downloading %s ...' % tr(output_filename))
|
||||||
@ -1007,6 +1012,9 @@ def download_urls(
|
|||||||
from .processor.ffmpeg import ffmpeg_concat_av
|
from .processor.ffmpeg import ffmpeg_concat_av
|
||||||
ret = ffmpeg_concat_av(parts, output_filepath, ext)
|
ret = ffmpeg_concat_av(parts, output_filepath, ext)
|
||||||
print('Merged into %s' % output_filename)
|
print('Merged into %s' % output_filename)
|
||||||
|
if extract_audio:
|
||||||
|
from .processor.ffmpeg import ffmpeg_extract_audio_from_video
|
||||||
|
ffmpeg_extract_audio_from_video(output_filepath, ext=extract_format)
|
||||||
if ret == 0:
|
if ret == 0:
|
||||||
for part in parts:
|
for part in parts:
|
||||||
os.remove(part)
|
os.remove(part)
|
||||||
@ -1021,6 +1029,9 @@ def download_urls(
|
|||||||
from .processor.join_flv import concat_flv
|
from .processor.join_flv import concat_flv
|
||||||
concat_flv(parts, output_filepath)
|
concat_flv(parts, output_filepath)
|
||||||
print('Merged into %s' % output_filename)
|
print('Merged into %s' % output_filename)
|
||||||
|
if extract_audio:
|
||||||
|
from .processor.ffmpeg import ffmpeg_extract_audio_from_video
|
||||||
|
ffmpeg_extract_audio_from_video(output_filepath, ext=extract_format)
|
||||||
except:
|
except:
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
@ -1032,11 +1043,13 @@ def download_urls(
|
|||||||
from .processor.ffmpeg import has_ffmpeg_installed
|
from .processor.ffmpeg import has_ffmpeg_installed
|
||||||
if has_ffmpeg_installed():
|
if has_ffmpeg_installed():
|
||||||
from .processor.ffmpeg import ffmpeg_concat_mp4_to_mp4
|
from .processor.ffmpeg import ffmpeg_concat_mp4_to_mp4
|
||||||
ffmpeg_concat_mp4_to_mp4(parts, output_filepath)
|
|
||||||
else:
|
else:
|
||||||
from .processor.join_mp4 import concat_mp4
|
from .processor.join_mp4 import concat_mp4
|
||||||
concat_mp4(parts, output_filepath)
|
concat_mp4(parts, output_filepath)
|
||||||
print('Merged into %s' % output_filename)
|
print('Merged into %s' % output_filename)
|
||||||
|
if extract_audio:
|
||||||
|
from .processor.ffmpeg import ffmpeg_extract_audio_from_video
|
||||||
|
ffmpeg_extract_audio_from_video(output_filepath, ext=extract_format)
|
||||||
except:
|
except:
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
@ -1053,6 +1066,9 @@ def download_urls(
|
|||||||
from .processor.join_ts import concat_ts
|
from .processor.join_ts import concat_ts
|
||||||
concat_ts(parts, output_filepath)
|
concat_ts(parts, output_filepath)
|
||||||
print('Merged into %s' % output_filename)
|
print('Merged into %s' % output_filename)
|
||||||
|
if extract_audio:
|
||||||
|
from .processor.ffmpeg import ffmpeg_extract_audio_from_video
|
||||||
|
ffmpeg_extract_audio_from_video(output_filepath, ext=extract_format)
|
||||||
except:
|
except:
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
@ -1520,11 +1536,18 @@ def script_main(download, download_playlist, **kwargs):
|
|||||||
'-a', '--auto-rename', action='store_true', default=False,
|
'-a', '--auto-rename', action='store_true', default=False,
|
||||||
help='Auto rename same name different files'
|
help='Auto rename same name different files'
|
||||||
)
|
)
|
||||||
|
|
||||||
download_grp.add_argument(
|
download_grp.add_argument(
|
||||||
'-k', '--insecure', action='store_true', default=False,
|
'-k', '--insecure', action='store_true', default=False,
|
||||||
help='ignore ssl errors'
|
help='ignore ssl errors'
|
||||||
)
|
)
|
||||||
|
download_grp.add_argument(
|
||||||
|
'-e', '--extract-audio', action='store_true', default=False,
|
||||||
|
help='extract audio from video'
|
||||||
|
)
|
||||||
|
download_grp.add_argument(
|
||||||
|
'-E', '--extract-audio-format', metavar='FORMAT', default='mp3',
|
||||||
|
help='set extracted audio format'
|
||||||
|
)
|
||||||
|
|
||||||
proxy_grp = parser.add_argument_group('Proxy options')
|
proxy_grp = parser.add_argument_group('Proxy options')
|
||||||
proxy_grp = proxy_grp.add_mutually_exclusive_group()
|
proxy_grp = proxy_grp.add_mutually_exclusive_group()
|
||||||
@ -1572,6 +1595,9 @@ def script_main(download, download_playlist, **kwargs):
|
|||||||
global output_filename
|
global output_filename
|
||||||
global auto_rename
|
global auto_rename
|
||||||
global insecure
|
global insecure
|
||||||
|
global extract_audio
|
||||||
|
global extract_format
|
||||||
|
|
||||||
output_filename = args.output_filename
|
output_filename = args.output_filename
|
||||||
extractor_proxy = args.extractor_proxy
|
extractor_proxy = args.extractor_proxy
|
||||||
|
|
||||||
@ -1600,6 +1626,9 @@ def script_main(download, download_playlist, **kwargs):
|
|||||||
if args.player:
|
if args.player:
|
||||||
player = args.player
|
player = args.player
|
||||||
caption = False
|
caption = False
|
||||||
|
if args.extract_audio:
|
||||||
|
extract_audio = True
|
||||||
|
extract_format = args.extract_audio_format
|
||||||
|
|
||||||
if args.insecure:
|
if args.insecure:
|
||||||
# ignore ssl
|
# ignore ssl
|
||||||
|
@ -264,7 +264,7 @@ def ffmpeg_download_stream(files, title, ext, params={}, output_dir='.', stream=
|
|||||||
|
|
||||||
def ffmpeg_concat_audio_and_video(files, output, ext):
|
def ffmpeg_concat_audio_and_video(files, output, ext):
|
||||||
print('Merging video and audio parts... ', end="", flush=True)
|
print('Merging video and audio parts... ', end="", flush=True)
|
||||||
if has_ffmpeg_installed:
|
if has_ffmpeg_installed():
|
||||||
params = [FFMPEG] + LOGLEVEL
|
params = [FFMPEG] + LOGLEVEL
|
||||||
params.extend(['-f', 'concat'])
|
params.extend(['-f', 'concat'])
|
||||||
params.extend(['-safe', '0']) # https://stackoverflow.com/questions/38996925/ffmpeg-concat-unsafe-file-name
|
params.extend(['-safe', '0']) # https://stackoverflow.com/questions/38996925/ffmpeg-concat-unsafe-file-name
|
||||||
@ -288,3 +288,25 @@ def ffprobe_get_media_duration(file):
|
|||||||
params.extend(['-v', 'quiet'])
|
params.extend(['-v', 'quiet'])
|
||||||
params.extend(['-of', 'csv=p=0'])
|
params.extend(['-of', 'csv=p=0'])
|
||||||
return subprocess.check_output(params, stdin=STDIN, stderr=subprocess.STDOUT).decode().strip()
|
return subprocess.check_output(params, stdin=STDIN, stderr=subprocess.STDOUT).decode().strip()
|
||||||
|
|
||||||
|
|
||||||
|
def ffmpeg_extract_audio_from_video(video_file_path, ext='mp3'):
|
||||||
|
if has_ffmpeg_installed():
|
||||||
|
print('extracting audio from video... ', end="", flush=True)
|
||||||
|
|
||||||
|
path_without_ext = os.path.splitext(video_file_path)[0]
|
||||||
|
output_path = path_without_ext+"."+ ext
|
||||||
|
|
||||||
|
params = [FFMPEG] + LOGLEVEL
|
||||||
|
params.extend(['-i', video_file_path])
|
||||||
|
params.extend(['-f', ext])
|
||||||
|
params.append(path_without_ext+"."+ext)
|
||||||
|
# os.remove(video_file_path)
|
||||||
|
return_val = subprocess.call(params, stdin=STDIN)
|
||||||
|
if return_val == 0:
|
||||||
|
print('\nextracted into ' + output_path)
|
||||||
|
else:
|
||||||
|
print("\nextract error")
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
raise EnvironmentError('\nNo ffmpeg found')
|
Loading…
Reference in New Issue
Block a user