1
0
mirror of https://github.com/l1ving/youtube-dl synced 2025-03-09 12:10:49 +08:00

Refactored the according according to 'flake8'

This commit is contained in:
shin 2019-12-26 13:43:50 +05:30
parent 6fb38337d6
commit edcaf554b0

View File

@ -3,24 +3,19 @@ from __future__ import unicode_literals
import os
import subprocess
try:
import imghdr
from mutagen.id3 import PictureType, ID3, APIC
from mutagen.mp4 import MP4, MP4Cover
from mutagen.id3 import PictureType, ID3, APIC, ID3NoHeaderError
from mutagen.mp4 import MP4, MP4Cover, MP4MetadataError
except ImportError:
raise Exception('[embedthumbnail] Mutagen isn\'t found as a dependency to embed thumbnails!')
from .ffmpeg import FFmpegPostProcessor
from ..utils import (
check_executable,
encodeArgument,
encodeFilename,
PostProcessingError,
prepend_extension,
shell_quote
PostProcessingError
)
@ -49,41 +44,36 @@ class EmbedThumbnailPP(FFmpegPostProcessor):
if info['ext'] == 'mp3':
try:
meta = ID3(filename)
except:
raise EmbedThumbnailPPError("MP3 file doesn't have a existing ID3v2 tag.")
# Update older tags (eg. ID3v1) to a newer version,
# which supports embedded-thumbnails (e.g ID3v2.3).
# NOTE: ID3v2.4 might not be supported by programs.
meta.update_to_v23()
meta = ID3(filename)
except ID3NoHeaderError:
raise EmbedThumbnailPPError("MP3 file doesn't have a existing ID3v2 tag.")
# Appends a Cover-front thumbnail, it's the most common
# type of thumbnail distributed with.
meta.add(APIC(
data= open(thumbnail_filename, 'rb').read(),
mime= 'image/'+imghdr.what(thumbnail_filename),
type= PictureType.COVER_FRONT))
meta.save() # Save the changes to file, does in-place replacement.
data=open(thumbnail_filename, 'rb').read(),
mime='image/' + imghdr.what(thumbnail_filename),
type=PictureType.COVER_FRONT))
meta.save() # Save the changes to file, does in-place replacement.
self._downloader.to_screen('[mutagen.id3] Merged Thumbnail into "%s"' % filename)
if not self._already_have_thumbnail:
os.remove(encodeFilename(thumbnail_filename))
os.remove(encodeFilename(thumbnail_filename))
elif info['ext'] in ['m4a', 'mp4']:
try:
meta = MP4(filename)
except:
except MP4MetadataError:
raise EmbedThumbnailPPError("MPEG-4 file's atomic structure for embedding isn't correct!")
# NOTE: the 'covr' atom is a non-standard MPEG-4 atom,
# Apple iTunes 'M4A' files include the 'moov.udta.meta.ilst' atom.
meta.tags['covr'] = [MP4Cover(
data= open(thumbnail_filename, 'rb').read(),
imageformat= MP4Cover.FORMAT_JPEG if \
imghdr.what(thumbnail_filename) == 'jpeg' \
else MP4Cover.FORMAT_PNG)]
data=open(thumbnail_filename, 'rb').read(),
imageformat=MP4Cover.FORMAT_JPEG if
imghdr.what(thumbnail_filename) == 'jpeg'
else MP4Cover.FORMAT_PNG)]
meta.save()
self._downloader.to_screen('[mutagen.mp4] Merged thumbnail to "%s"' % filename)
@ -93,4 +83,4 @@ class EmbedThumbnailPP(FFmpegPostProcessor):
else:
raise EmbedThumbnailPPError('Only mp3, m4a/mp4 are supported for thumbnail embedding for now.')
return [], info
return [], info