aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/postprocessor
diff options
context:
space:
mode:
Diffstat (limited to 'youtube_dl/postprocessor')
-rw-r--r--youtube_dl/postprocessor/common.py13
-rw-r--r--youtube_dl/postprocessor/ffmpeg.py29
2 files changed, 27 insertions, 15 deletions
diff --git a/youtube_dl/postprocessor/common.py b/youtube_dl/postprocessor/common.py
index e54ae678d..ef9fdfa19 100644
--- a/youtube_dl/postprocessor/common.py
+++ b/youtube_dl/postprocessor/common.py
@@ -1,6 +1,11 @@
from __future__ import unicode_literals
-from ..utils import PostProcessingError
+import os
+
+from ..utils import (
+ PostProcessingError,
+ encodeFilename,
+)
class PostProcessor(object):
@@ -46,6 +51,12 @@ class PostProcessor(object):
"""
return None, information # by default, keep file and do nothing
+ def try_utime(self, path, atime, mtime, errnote='Cannot update utime of file'):
+ try:
+ os.utime(encodeFilename(path), (atime, mtime))
+ except Exception:
+ self._downloader.report_warning(errnote)
+
class AudioConversionError(PostProcessingError):
pass
diff --git a/youtube_dl/postprocessor/ffmpeg.py b/youtube_dl/postprocessor/ffmpeg.py
index b6f51cfd5..8e99a3c2c 100644
--- a/youtube_dl/postprocessor/ffmpeg.py
+++ b/youtube_dl/postprocessor/ffmpeg.py
@@ -3,7 +3,6 @@ from __future__ import unicode_literals
import io
import os
import subprocess
-import sys
import time
@@ -118,6 +117,10 @@ class FFmpegPostProcessor(PostProcessor):
return self._paths[self.basename]
@property
+ def probe_available(self):
+ return self.probe_basename is not None
+
+ @property
def probe_executable(self):
return self._paths[self.probe_basename]
@@ -143,7 +146,8 @@ class FFmpegPostProcessor(PostProcessor):
stderr = stderr.decode('utf-8', 'replace')
msg = stderr.strip().split('\n')[-1]
raise FFmpegPostProcessorError(msg)
- os.utime(encodeFilename(out_path), (oldest_mtime, oldest_mtime))
+ self.try_utime(out_path, oldest_mtime, oldest_mtime)
+
if self._deletetempfiles:
for ipath in input_paths:
os.remove(ipath)
@@ -169,7 +173,7 @@ class FFmpegExtractAudioPP(FFmpegPostProcessor):
def get_audio_codec(self, path):
- if not self.probe_executable:
+ if not self.probe_available:
raise PostProcessingError('ffprobe or avprobe not found. Please install one.')
try:
cmd = [
@@ -269,20 +273,17 @@ class FFmpegExtractAudioPP(FFmpegPostProcessor):
else:
self._downloader.to_screen('[' + self.basename + '] Destination: ' + new_path)
self.run_ffmpeg(path, new_path, acodec, more_opts)
- except:
- etype, e, tb = sys.exc_info()
- if isinstance(e, AudioConversionError):
- msg = 'audio conversion failed: ' + e.msg
- else:
- msg = 'error running ' + self.basename
- raise PostProcessingError(msg)
+ except AudioConversionError as e:
+ raise PostProcessingError(
+ 'audio conversion failed: ' + e.msg)
+ except Exception:
+ raise PostProcessingError('error running ' + self.basename)
# Try to update the date time for extracted audio file.
if information.get('filetime') is not None:
- try:
- os.utime(encodeFilename(new_path), (time.time(), information['filetime']))
- except:
- self._downloader.report_warning('Cannot update utime of audio file')
+ self.try_utime(
+ new_path, time.time(), information['filetime'],
+ errnote='Cannot update utime of audio file')
information['filepath'] = new_path
return self._nopostoverwrites, information