mirror of
https://github.com/ytdl-org/youtube-dl
synced 2025-01-06 03:20:10 +09:00
Transform in place. Tag in mimetype.
This commit is contained in:
parent
9ca71e76ba
commit
80a88a15ab
@ -4,6 +4,7 @@ from __future__ import unicode_literals
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import imghdr
|
||||||
|
|
||||||
from .ffmpeg import FFmpegPostProcessor
|
from .ffmpeg import FFmpegPostProcessor
|
||||||
|
|
||||||
@ -18,7 +19,6 @@ from ..utils import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from base64 import b64encode
|
from base64 import b64encode
|
||||||
from shutil import copyfile
|
|
||||||
|
|
||||||
|
|
||||||
class EmbedThumbnailPPError(PostProcessingError):
|
class EmbedThumbnailPPError(PostProcessingError):
|
||||||
@ -136,13 +136,12 @@ class EmbedThumbnailPP(FFmpegPostProcessor):
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
raise EmbedThumbnailPPError('mutagen was not found. Please install.')
|
raise EmbedThumbnailPPError('mutagen was not found. Please install.')
|
||||||
|
|
||||||
# to prevent the behaviour of in-place modification of Mutagen
|
aufile = {'opus': OggOpus, 'flac': FLAC, 'ogg': OggVorbis}[info['ext']](filename)
|
||||||
copyfile(filename, temp_filename)
|
thumbfile = open(thumbnail_filename, 'rb')
|
||||||
|
|
||||||
aufile = {'opus': OggOpus, 'flac': FLAC, 'ogg': OggVorbis}[info['ext']](temp_filename)
|
|
||||||
|
|
||||||
covart = Picture()
|
covart = Picture()
|
||||||
covart.data = open(thumbnail_filename, 'rb').read()
|
covart.mime = 'image/' + imghdr.what(thumbfile)
|
||||||
|
covart.data = thumbfile.read()
|
||||||
covart.type = 3 # as the front cover
|
covart.type = 3 # as the front cover
|
||||||
|
|
||||||
if info['ext'] == 'flac':
|
if info['ext'] == 'flac':
|
||||||
@ -156,8 +155,6 @@ class EmbedThumbnailPP(FFmpegPostProcessor):
|
|||||||
|
|
||||||
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.rename(encodeFilename(temp_filename), encodeFilename(filename))
|
|
||||||
else:
|
else:
|
||||||
raise EmbedThumbnailPPError('Only mp3, m4a/mp4, ogg, opus and flac are supported for thumbnail embedding for now.')
|
raise EmbedThumbnailPPError('Only mp3, m4a/mp4, ogg, opus and flac are supported for thumbnail embedding for now.')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user