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
)
@ -50,14 +45,9 @@ class EmbedThumbnailPP(FFmpegPostProcessor):
if info['ext'] == 'mp3':
try:
meta = ID3(filename)
except:
except ID3NoHeaderError:
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()
# Appends a Cover-front thumbnail, it's the most common
# type of thumbnail distributed with.
meta.add(APIC(
@ -74,15 +64,15 @@ class EmbedThumbnailPP(FFmpegPostProcessor):
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' \
imageformat=MP4Cover.FORMAT_JPEG if
imghdr.what(thumbnail_filename) == 'jpeg'
else MP4Cover.FORMAT_PNG)]
meta.save()