aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Hagemeister <phihag@phihag.de>2011-09-15 12:43:27 +0200
committerPhilipp Hagemeister <phihag@phihag.de>2011-09-15 12:43:27 +0200
commitc99dcbd2d6c49cbc7033520207ac84d6a2514134 (patch)
tree9a7df28816c0c137395a72fb565fd0143e76d6db
parentda0db53a758ffe45767d9f8ea8faa3a605ba9458 (diff)
parent18b7f87409bf83957c84b1b553b7cfd3efff54db (diff)
Merge remote-tracking branch 'rmanola/master' (Closes: #124)
Add option to specify mp3 quality and prevent the video from being deleted
-rwxr-xr-xyoutube-dl29
1 files changed, 20 insertions, 9 deletions
diff --git a/youtube-dl b/youtube-dl
index d01b259cd..a2100aa6d 100755
--- a/youtube-dl
+++ b/youtube-dl
@@ -3293,11 +3293,13 @@ class PostProcessor(object):
class FFmpegExtractAudioPP(PostProcessor):
- def __init__(self, downloader=None, preferredcodec=None):
+ def __init__(self, downloader=None, preferredcodec=None, preferredquality=None, keepvideo=False):
PostProcessor.__init__(self, downloader)
if preferredcodec is None:
preferredcodec = 'best'
self._preferredcodec = preferredcodec
+ self._preferredquality = preferredquality
+ self._keepvideo = keepvideo
@staticmethod
def get_audio_codec(path):
@@ -3346,12 +3348,16 @@ class FFmpegExtractAudioPP(PostProcessor):
# MP3 otherwise.
acodec = 'libmp3lame'
extension = 'mp3'
- more_opts = ['-ab', '128k']
+ more_opts = []
+ if self._preferredquality is not None:
+ more_opts += ['-ab', self._preferredquality]
else:
# We convert the audio (lossy)
acodec = {'mp3': 'libmp3lame', 'aac': 'aac'}[self._preferredcodec]
extension = self._preferredcodec
- more_opts = ['-ab', '128k']
+ more_opts = []
+ if self._preferredquality is not None:
+ more_opts += ['-ab', self._preferredquality]
if self._preferredcodec == 'aac':
more_opts += ['-f', 'adts']
@@ -3371,11 +3377,12 @@ class FFmpegExtractAudioPP(PostProcessor):
except:
self._downloader.to_stderr(u'WARNING: Cannot update utime of audio file')
- try:
- os.remove(path)
- except (IOError, OSError):
- self._downloader.to_stderr(u'WARNING: Unable to remove downloaded video file')
- return None
+ if not self._keepvideo:
+ try:
+ os.remove(path)
+ except (IOError, OSError):
+ self._downloader.to_stderr(u'WARNING: Unable to remove downloaded video file')
+ return None
information['filepath'] = new_path
return information
@@ -3573,6 +3580,10 @@ def parseOpts():
help='convert video files to audio-only files (requires ffmpeg and ffprobe)')
postproc.add_option('--audio-format', metavar='FORMAT', dest='audioformat', default='best',
help='"best", "aac" or "mp3"; best by default')
+ postproc.add_option('--audio-quality', metavar='QUALITY', dest='audioquality', default='128K',
+ help='ffmpeg audio bitrate specification, 128k by default')
+ postproc.add_option('-k', '--keep-video', action='store_true', dest='keepvideo', default=False,
+ help='keeps the video file on disk after the post-processing; the video is erased by default')
parser.add_option_group(general)
@@ -3753,7 +3764,7 @@ def main():
# PostProcessors
if opts.extractaudio:
- fd.add_post_processor(FFmpegExtractAudioPP(preferredcodec=opts.audioformat))
+ fd.add_post_processor(FFmpegExtractAudioPP(preferredcodec=opts.audioformat, preferredquality=opts.audioquality, keepvideo=opts.keepvideo))
# Update version
if opts.update_self: