Refactored the according according to 'flake8'
This commit is contained in:
parent
6fb38337d6
commit
edcaf554b0
@ -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
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -49,41 +44,36 @@ 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(
|
||||||
data= open(thumbnail_filename, 'rb').read(),
|
data=open(thumbnail_filename, 'rb').read(),
|
||||||
mime= 'image/'+imghdr.what(thumbnail_filename),
|
mime='image/' + imghdr.what(thumbnail_filename),
|
||||||
type= PictureType.COVER_FRONT))
|
type=PictureType.COVER_FRONT))
|
||||||
|
|
||||||
meta.save() # Save the changes to file, does in-place replacement.
|
meta.save() # Save the changes to file, does in-place replacement.
|
||||||
self._downloader.to_screen('[mutagen.id3] Merged Thumbnail into "%s"' % filename)
|
self._downloader.to_screen('[mutagen.id3] Merged Thumbnail into "%s"' % filename)
|
||||||
|
|
||||||
if not self._already_have_thumbnail:
|
if not self._already_have_thumbnail:
|
||||||
os.remove(encodeFilename(thumbnail_filename))
|
os.remove(encodeFilename(thumbnail_filename))
|
||||||
|
|
||||||
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()
|
||||||
self._downloader.to_screen('[mutagen.mp4] Merged thumbnail to "%s"' % filename)
|
self._downloader.to_screen('[mutagen.mp4] Merged thumbnail to "%s"' % filename)
|
||||||
@ -93,4 +83,4 @@ class EmbedThumbnailPP(FFmpegPostProcessor):
|
|||||||
else:
|
else:
|
||||||
raise EmbedThumbnailPPError('Only mp3, m4a/mp4 are supported for thumbnail embedding for now.')
|
raise EmbedThumbnailPPError('Only mp3, m4a/mp4 are supported for thumbnail embedding for now.')
|
||||||
|
|
||||||
return [], info
|
return [], info
|
||||||
|
Loading…
x
Reference in New Issue
Block a user