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 os
import subprocess
try: try:
import imghdr import imghdr
from mutagen.id3 import PictureType, ID3, APIC from mutagen.id3 import PictureType, ID3, APIC, ID3NoHeaderError
from mutagen.mp4 import MP4, MP4Cover from mutagen.mp4 import MP4, MP4Cover, MP4MetadataError
except ImportError: except ImportError:
raise Exception('[embedthumbnail] Mutagen isn\'t found as a dependency to embed thumbnails!') raise Exception('[embedthumbnail] Mutagen isn\'t found as a dependency to embed thumbnails!')
from .ffmpeg import FFmpegPostProcessor from .ffmpeg import FFmpegPostProcessor
from ..utils import ( from ..utils import (
check_executable,
encodeArgument,
encodeFilename, encodeFilename,
PostProcessingError, PostProcessingError
prepend_extension,
shell_quote
) )
@ -50,14 +45,9 @@ class EmbedThumbnailPP(FFmpegPostProcessor):
if info['ext'] == 'mp3': if info['ext'] == 'mp3':
try: try:
meta = ID3(filename) meta = ID3(filename)
except: except ID3NoHeaderError:
raise EmbedThumbnailPPError("MP3 file doesn't have a existing ID3v2 tag.") 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 # Appends a Cover-front thumbnail, it's the most common
# type of thumbnail distributed with. # type of thumbnail distributed with.
meta.add(APIC( meta.add(APIC(
@ -74,15 +64,15 @@ class EmbedThumbnailPP(FFmpegPostProcessor):
elif info['ext'] in ['m4a', 'mp4']: elif info['ext'] in ['m4a', 'mp4']:
try: try:
meta = MP4(filename) meta = MP4(filename)
except: except MP4MetadataError:
raise EmbedThumbnailPPError("MPEG-4 file's atomic structure for embedding isn't correct!") raise EmbedThumbnailPPError("MPEG-4 file's atomic structure for embedding isn't correct!")
# NOTE: the 'covr' atom is a non-standard MPEG-4 atom, # NOTE: the 'covr' atom is a non-standard MPEG-4 atom,
# Apple iTunes 'M4A' files include the 'moov.udta.meta.ilst' atom. # Apple iTunes 'M4A' files include the 'moov.udta.meta.ilst' atom.
meta.tags['covr'] = [MP4Cover( meta.tags['covr'] = [MP4Cover(
data=open(thumbnail_filename, 'rb').read(), data=open(thumbnail_filename, 'rb').read(),
imageformat= MP4Cover.FORMAT_JPEG if \ imageformat=MP4Cover.FORMAT_JPEG if
imghdr.what(thumbnail_filename) == 'jpeg' \ imghdr.what(thumbnail_filename) == 'jpeg'
else MP4Cover.FORMAT_PNG)] else MP4Cover.FORMAT_PNG)]
meta.save() meta.save()