Remove duplicated code
This commit is contained in:
parent
7ec1e417ca
commit
d5bb4d18fc
@ -40,6 +40,9 @@ class EmbedThumbnailPP(FFmpegPostProcessor):
|
|||||||
'Skipping embedding the thumbnail because the file is missing.')
|
'Skipping embedding the thumbnail because the file is missing.')
|
||||||
return [], info
|
return [], info
|
||||||
|
|
||||||
|
if info['ext'] not in ['mp3', 'mkv', 'm4a', 'mp4']:
|
||||||
|
raise EmbedThumbnailPPError('Only mp3, m4a/mp4 and mkv are supported for thumbnail embedding for now.')
|
||||||
|
|
||||||
if info['ext'] == 'mkv':
|
if info['ext'] == 'mkv':
|
||||||
if thumbnail_filename.endswith(('.jpe', '.jpeg', '.jpg', '.jfif')):
|
if thumbnail_filename.endswith(('.jpe', '.jpeg', '.jpg', '.jfif')):
|
||||||
mimetype = 'image/jpeg'
|
mimetype = 'image/jpeg'
|
||||||
@ -59,35 +62,29 @@ class EmbedThumbnailPP(FFmpegPostProcessor):
|
|||||||
# No orientation detection nor dimensions checking/convertion
|
# No orientation detection nor dimensions checking/convertion
|
||||||
'-metadata:s:t', 'filename=cover_land.{}'.format(extension),
|
'-metadata:s:t', 'filename=cover_land.{}'.format(extension),
|
||||||
# If not given : "[matroska @ 000001458de38840] Attachment stream 2 has no mimetype tag and it cannot be deduced from the codec id."
|
# If not given : "[matroska @ 000001458de38840] Attachment stream 2 has no mimetype tag and it cannot be deduced from the codec id."
|
||||||
'-metadata:s:t', 'mimetype={}'.format(mimetype),
|
'-metadata:s:t', 'mimetype=%s' % mimetype,
|
||||||
# Use metadata "title" so it is set as MATROSKA_ID_FILEDESC - optional
|
# Use metadata "title" so it is set as MATROSKA_ID_FILEDESC - optional
|
||||||
# https://github.com/FFmpeg/FFmpeg/blob/9cfdf0e3322b9a451277cf36406ac4a8e4e3da74/libavformat/matroskaenc.c#L1762
|
# https://github.com/FFmpeg/FFmpeg/blob/9cfdf0e3322b9a451277cf36406ac4a8e4e3da74/libavformat/matroskaenc.c#L1762
|
||||||
'-metadata:s:t', 'title=Thumbnail']
|
'-metadata:s:t', 'title=Thumbnail']
|
||||||
|
input_paths = [filename]
|
||||||
self._downloader.to_screen('[ffmpeg] Adding thumbnail to "%s"' % filename)
|
|
||||||
|
|
||||||
self.run_ffmpeg(filename, temp_filename, options)
|
|
||||||
|
|
||||||
if not self._already_have_thumbnail:
|
|
||||||
os.remove(encodeFilename(thumbnail_filename))
|
|
||||||
os.remove(encodeFilename(filename))
|
|
||||||
os.rename(encodeFilename(temp_filename), encodeFilename(filename))
|
|
||||||
|
|
||||||
elif info['ext'] == 'mp3':
|
elif info['ext'] == 'mp3':
|
||||||
options = [
|
options = [
|
||||||
'-c', 'copy', '-map', '0', '-map', '1',
|
'-c', 'copy', '-map', '0', '-map', '1',
|
||||||
'-metadata:s:v', 'title="Album cover"', '-metadata:s:v', 'comment="Cover (Front)"']
|
'-metadata:s:v', 'title="Album cover"', '-metadata:s:v', 'comment="Cover (Front)"']
|
||||||
|
input_paths = [filename, thumbnail_filename]
|
||||||
|
|
||||||
|
if info['ext'] in ['mkv', 'mp3']:
|
||||||
self._downloader.to_screen('[ffmpeg] Adding thumbnail to "%s"' % filename)
|
self._downloader.to_screen('[ffmpeg] Adding thumbnail to "%s"' % filename)
|
||||||
|
|
||||||
self.run_ffmpeg_multiple_files([filename, thumbnail_filename], temp_filename, options)
|
self.run_ffmpeg_multiple_files(input_paths, temp_filename, options)
|
||||||
|
|
||||||
if not self._already_have_thumbnail:
|
if not self._already_have_thumbnail:
|
||||||
os.remove(encodeFilename(thumbnail_filename))
|
os.remove(encodeFilename(thumbnail_filename))
|
||||||
os.remove(encodeFilename(filename))
|
os.remove(encodeFilename(filename))
|
||||||
os.rename(encodeFilename(temp_filename), encodeFilename(filename))
|
os.rename(encodeFilename(temp_filename), encodeFilename(filename))
|
||||||
|
|
||||||
elif info['ext'] in ['m4a', 'mp4']:
|
if info['ext'] in ['m4a', 'mp4']:
|
||||||
if not check_executable('AtomicParsley', ['-v']):
|
if not check_executable('AtomicParsley', ['-v']):
|
||||||
raise EmbedThumbnailPPError('AtomicParsley was not found. Please install.')
|
raise EmbedThumbnailPPError('AtomicParsley was not found. Please install.')
|
||||||
|
|
||||||
@ -119,7 +116,5 @@ class EmbedThumbnailPP(FFmpegPostProcessor):
|
|||||||
else:
|
else:
|
||||||
os.remove(encodeFilename(filename))
|
os.remove(encodeFilename(filename))
|
||||||
os.rename(encodeFilename(temp_filename), encodeFilename(filename))
|
os.rename(encodeFilename(temp_filename), encodeFilename(filename))
|
||||||
else:
|
|
||||||
raise EmbedThumbnailPPError('Only mp3, m4a/mp4 and mkv are supported for thumbnail embedding for now.')
|
|
||||||
|
|
||||||
return [], info
|
return [], info
|
||||||
|
Loading…
x
Reference in New Issue
Block a user