mirror of
https://github.com/fergalmoran/picard.git
synced 2025-12-22 09:18:18 +00:00
Apply stylistic fixes
This commit is contained in:
@@ -28,7 +28,6 @@
|
|||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
|
|
||||||
|
|
||||||
from dataclasses import astuple
|
|
||||||
from hashlib import blake2b
|
from hashlib import blake2b
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
@@ -309,8 +308,11 @@ class CoverArtImage:
|
|||||||
self.datahash = None
|
self.datahash = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
(self.width, self.height, self.mimetype, self.extension,
|
info = imageinfo.identify(data)
|
||||||
self.datalength) = astuple(imageinfo.identify(data))
|
self.width, self.height = info.width, info.height
|
||||||
|
self.mimetype = info.mime
|
||||||
|
self.extension = info.extension
|
||||||
|
self.datalength = info.datalen
|
||||||
except imageinfo.IdentificationError as e:
|
except imageinfo.IdentificationError as e:
|
||||||
raise CoverArtImageIdentificationError(e)
|
raise CoverArtImageIdentificationError(e)
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ from picard.extension_points.cover_art_processors import (
|
|||||||
ProcessingTarget,
|
ProcessingTarget,
|
||||||
get_cover_art_processors,
|
get_cover_art_processors,
|
||||||
)
|
)
|
||||||
|
from picard.util.imageinfo import IdentificationError
|
||||||
|
|
||||||
|
|
||||||
def run_image_filters(data):
|
def run_image_filters(data):
|
||||||
@@ -75,6 +76,8 @@ def run_image_processors(data, coverartimage):
|
|||||||
coverartimage,
|
coverartimage,
|
||||||
1000 * (time.time() - start_time)
|
1000 * (time.time() - start_time)
|
||||||
)
|
)
|
||||||
|
except IdentificationError as e:
|
||||||
|
raise CoverArtProcessingError(e)
|
||||||
except CoverArtProcessingError as e:
|
except CoverArtProcessingError as e:
|
||||||
coverartimage.set_tags_data(tags_data)
|
coverartimage.set_tags_data(tags_data)
|
||||||
coverartimage.set_external_file_data(file_data)
|
coverartimage.set_external_file_data(file_data)
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ class ResizeImage(ImageProcessor):
|
|||||||
)
|
)
|
||||||
image.info.width = scaled_image.width()
|
image.info.width = scaled_image.width()
|
||||||
image.info.height = scaled_image.height()
|
image.info.height = scaled_image.height()
|
||||||
|
image.info.datalen = scaled_image.sizeInBytes()
|
||||||
image.set_result(scaled_image)
|
image.set_result(scaled_image)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -63,14 +63,14 @@ class ProcessingImage:
|
|||||||
else:
|
else:
|
||||||
self._qimage = QImage.fromData(image)
|
self._qimage = QImage.fromData(image)
|
||||||
|
|
||||||
def get_result(self, image_format=None, default_format=False):
|
def get_result(self, image_format=None, default_format=False, quality=90):
|
||||||
if image_format is None:
|
if image_format is None:
|
||||||
if not default_format:
|
if not default_format:
|
||||||
return self._qimage
|
return self._qimage
|
||||||
else:
|
else:
|
||||||
image_format = self.info.format
|
image_format = self.info.format
|
||||||
buffer = QBuffer()
|
buffer = QBuffer()
|
||||||
if not self._qimage.save(buffer, image_format, quality=90):
|
if not self._qimage.save(buffer, image_format, quality=quality):
|
||||||
raise CoverArtEncodingError(f"Failed to encode into {image_format}")
|
raise CoverArtEncodingError(f"Failed to encode into {image_format}")
|
||||||
return buffer.data()
|
return buffer.data()
|
||||||
|
|
||||||
|
|||||||
@@ -74,7 +74,13 @@ class IdentifyImageType:
|
|||||||
return self._result()
|
return self._result()
|
||||||
|
|
||||||
def _result(self):
|
def _result(self):
|
||||||
return ImageInfo(int(self.w), int(self.h), self.mime, self.extension, self.datalen)
|
return ImageInfo(
|
||||||
|
width=int(self.w),
|
||||||
|
height=int(self.h),
|
||||||
|
mime=self.mime,
|
||||||
|
extension=self.extension,
|
||||||
|
datalen=self.datalen,
|
||||||
|
)
|
||||||
|
|
||||||
def match(self):
|
def match(self):
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|||||||
@@ -31,10 +31,10 @@ from picard.coverart.processing.filters import (
|
|||||||
)
|
)
|
||||||
from picard.coverart.processing.processors import ResizeImage
|
from picard.coverart.processing.processors import ResizeImage
|
||||||
from picard.extension_points.cover_art_processors import (
|
from picard.extension_points.cover_art_processors import (
|
||||||
|
CoverArtProcessingError,
|
||||||
ProcessingImage,
|
ProcessingImage,
|
||||||
ProcessingTarget,
|
ProcessingTarget,
|
||||||
)
|
)
|
||||||
from picard.util.imageinfo import IdentificationError
|
|
||||||
|
|
||||||
|
|
||||||
def create_fake_image(width, height, image_format):
|
def create_fake_image(width, height, image_format):
|
||||||
@@ -142,5 +142,5 @@ class ImageProcessorsTest(PicardTestCase):
|
|||||||
def test_identification_error(self):
|
def test_identification_error(self):
|
||||||
image = create_fake_image(0, 0, "jpg")
|
image = create_fake_image(0, 0, "jpg")
|
||||||
coverartimage = CoverArtImage()
|
coverartimage = CoverArtImage()
|
||||||
with self.assertRaises(IdentificationError):
|
with self.assertRaises(CoverArtProcessingError):
|
||||||
run_image_processors(image, coverartimage)
|
run_image_processors(image, coverartimage)
|
||||||
|
|||||||
@@ -36,7 +36,13 @@ class IdentifyTest(PicardTestCase):
|
|||||||
with open(file, 'rb') as f:
|
with open(file, 'rb') as f:
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
imageinfo.identify(f.read()),
|
imageinfo.identify(f.read()),
|
||||||
imageinfo.ImageInfo(140, 96, 'image/gif', '.gif', 5806)
|
imageinfo.ImageInfo(
|
||||||
|
width=140,
|
||||||
|
height=96,
|
||||||
|
mime='image/gif',
|
||||||
|
extension='.gif',
|
||||||
|
datalen=5806
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_png(self):
|
def test_png(self):
|
||||||
@@ -45,7 +51,13 @@ class IdentifyTest(PicardTestCase):
|
|||||||
with open(file, 'rb') as f:
|
with open(file, 'rb') as f:
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
imageinfo.identify(f.read()),
|
imageinfo.identify(f.read()),
|
||||||
imageinfo.ImageInfo(140, 96, 'image/png', '.png', 11137)
|
imageinfo.ImageInfo(
|
||||||
|
width=140,
|
||||||
|
height=96,
|
||||||
|
mime='image/png',
|
||||||
|
extension='.png',
|
||||||
|
datalen=11137
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_jpeg(self):
|
def test_jpeg(self):
|
||||||
@@ -54,7 +66,13 @@ class IdentifyTest(PicardTestCase):
|
|||||||
with open(file, 'rb') as f:
|
with open(file, 'rb') as f:
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
imageinfo.identify(f.read()),
|
imageinfo.identify(f.read()),
|
||||||
imageinfo.ImageInfo(140, 96, 'image/jpeg', '.jpg', 8550)
|
imageinfo.ImageInfo(
|
||||||
|
width=140,
|
||||||
|
height=96,
|
||||||
|
mime='image/jpeg',
|
||||||
|
extension='.jpg',
|
||||||
|
datalen=8550
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_webp_vp8(self):
|
def test_webp_vp8(self):
|
||||||
@@ -63,7 +81,13 @@ class IdentifyTest(PicardTestCase):
|
|||||||
with open(file, 'rb') as f:
|
with open(file, 'rb') as f:
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
imageinfo.identify(f.read()),
|
imageinfo.identify(f.read()),
|
||||||
imageinfo.ImageInfo(140, 96, 'image/webp', '.webp', 6178)
|
imageinfo.ImageInfo(
|
||||||
|
width=140,
|
||||||
|
height=96,
|
||||||
|
mime='image/webp',
|
||||||
|
extension='.webp',
|
||||||
|
datalen=6178
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_webp_vp8l(self):
|
def test_webp_vp8l(self):
|
||||||
@@ -72,7 +96,13 @@ class IdentifyTest(PicardTestCase):
|
|||||||
with open(file, 'rb') as f:
|
with open(file, 'rb') as f:
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
imageinfo.identify(f.read()),
|
imageinfo.identify(f.read()),
|
||||||
imageinfo.ImageInfo(140, 96, 'image/webp', '.webp', 9432)
|
imageinfo.ImageInfo(
|
||||||
|
width=140,
|
||||||
|
height=96,
|
||||||
|
mime='image/webp',
|
||||||
|
extension='.webp',
|
||||||
|
datalen=9432
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_webp_vp8x(self):
|
def test_webp_vp8x(self):
|
||||||
@@ -81,7 +111,13 @@ class IdentifyTest(PicardTestCase):
|
|||||||
with open(file, 'rb') as f:
|
with open(file, 'rb') as f:
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
imageinfo.identify(f.read()),
|
imageinfo.identify(f.read()),
|
||||||
imageinfo.ImageInfo(140, 96, 'image/webp', '.webp', 6858)
|
imageinfo.ImageInfo(
|
||||||
|
width=140,
|
||||||
|
height=96,
|
||||||
|
mime='image/webp',
|
||||||
|
extension='.webp',
|
||||||
|
datalen=6858
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_webp_insufficient_data(self):
|
def test_webp_insufficient_data(self):
|
||||||
@@ -94,7 +130,13 @@ class IdentifyTest(PicardTestCase):
|
|||||||
with open(file, 'rb') as f:
|
with open(file, 'rb') as f:
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
imageinfo.identify(f.read()),
|
imageinfo.identify(f.read()),
|
||||||
imageinfo.ImageInfo(140, 96, 'image/tiff', '.tiff', 12509)
|
imageinfo.ImageInfo(
|
||||||
|
width=140,
|
||||||
|
height=96,
|
||||||
|
mime='image/tiff',
|
||||||
|
extension='.tiff',
|
||||||
|
datalen=12509
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_pdf(self):
|
def test_pdf(self):
|
||||||
@@ -103,7 +145,13 @@ class IdentifyTest(PicardTestCase):
|
|||||||
with open(file, 'rb') as f:
|
with open(file, 'rb') as f:
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
imageinfo.identify(f.read()),
|
imageinfo.identify(f.read()),
|
||||||
imageinfo.ImageInfo(0, 0, 'application/pdf', '.pdf', 10362)
|
imageinfo.ImageInfo(
|
||||||
|
width=0,
|
||||||
|
height=0,
|
||||||
|
mime='application/pdf',
|
||||||
|
extension='.pdf',
|
||||||
|
datalen=10362
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_not_enough_data(self):
|
def test_not_enough_data(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user