Beispiel #1
0
def test_round_trips_album_metadata_and_tracks_to_disk(project_file, mp3):
    album_file = project_file("album.tgit")
    original_tracks = (build.track(mp3(), track_title=title)
                       for title in ("1st", "2nd", "3rd"))

    original_album = build.album(filename=album_file,
                                 version="1.11.0",
                                 type=Album.Type.FLAC,
                                 lead_performer="Artist",
                                 images=[sample_front_cover],
                                 tracks=original_tracks)

    local_project.save_project(
        original_album, track_name=lambda track: track.track_title + ".mp3")
    delete_from_disk(*original_tracks)
    stored_album = local_project.load_project(album_file)

    assert_that(stored_album.type, equal_to(Album.Type.FLAC), "type")
    assert_that(stored_album.lead_performer, equal_to("Artist"),
                "lead performer")
    assert_that(stored_album.images, contains(Image(*sample_front_cover)),
                "images")
    assert_that(
        stored_album.tracks,
        contains(
            has_filename(project_file(TRACKS_FOLDER_NAME, "1st.mp3")),
            has_filename(project_file(TRACKS_FOLDER_NAME, "2nd.mp3")),
            has_filename(project_file(TRACKS_FOLDER_NAME, "3rd.mp3")),
        ), "tracks")
Beispiel #2
0
def test_round_trips_track_and_album_metadata(mp3):
    album = build.album(
        release_name="Album Title",
        lead_performer="Album Artist",
        isnis={"Album Artist": "0000000123456789"},
        ipis={"Album Lyricist": "9876543210000000"},
        images=[build.image(mime="image/jpeg", data=b"<image data>")])
    track = build.track(filename=mp3(),
                        track_title="Track Title",
                        album=album,
                        lyricist=["Album Lyricist"])

    tagging.save_track(track)

    track = tagging.load_track(track.filename)
    assert_that(
        track.metadata,
        has_entries(release_name="Album Title",
                    lead_performer="Album Artist",
                    isnis={"Album Artist": "0000000123456789"},
                    ipis={"Album Lyricist": "9876543210000000"},
                    track_title="Track Title"), "metadata tags")
    assert_that(track.metadata.images,
                contains(Image(mime="image/jpeg", data=b"<image data>")),
                "attached pictures")
Beispiel #3
0
 def _read_cover_art(self):
     self._settings.beginGroup("thumbnail")
     mime = self._settings.value("mime_type")
     data = self._settings.value("data")
     type_ = self._settings.value("type")
     desc = self._settings.value("description")
     self._settings.endGroup()
     return Image(mime, data, type_, desc)
def test_reads_cover_pictures_from_apic_frames(mp3):
    metadata = container.load(
        mp3(APIC_FRONT=("image/jpeg", "Front", b"front-cover.jpg"),
            APIC_BACK=("image/jpeg", "Back", b"back-cover.jpg")))

    assert_that(
        metadata.images,
        contains_inanyorder(
            Image("image/jpeg",
                  b"front-cover.jpg",
                  type_=Image.FRONT_COVER,
                  desc="Front"),
            Image("image/jpeg",
                  b"back-cover.jpg",
                  type_=Image.BACK_COVER,
                  desc="Back"),
        ))
Beispiel #5
0
def test_reads_attached_pictures_from_picture_field(flac):
    metadata = container.load(
        flac(PICTURES=(("image/jpeg", PictureType.FRONT_COVER, "Front",
                        b"front-cover.jpg"),
                       ("image/jpeg", PictureType.BACK_COVER, "Back",
                        b"back-cover.jpg"))))

    assert_that(
        metadata.images,
        contains_inanyorder(
            Image("image/jpeg",
                  b"front-cover.jpg",
                  type_=Image.FRONT_COVER,
                  desc="Front"),
            Image("image/jpeg",
                  b"back-cover.jpg",
                  type_=Image.BACK_COVER,
                  desc="Back"),
        ))
def test_stores_several_pictures_sharing_the_same_description(mp3):
    filename = mp3()
    metadata = Metadata()
    metadata.addImage("image/jpeg", b"salers.jpg", desc="Front Cover")
    metadata.addImage("image/jpeg", b"ragber.jpg", desc="Front Cover")

    container.save(filename, metadata)

    assert_that(
        container.load(filename).images,
        contains_inanyorder(
            Image("image/jpeg",
                  b"salers.jpg",
                  type_=Image.OTHER,
                  desc="Front Cover"),
            Image("image/jpeg",
                  b"ragber.jpg",
                  type_=Image.OTHER,
                  desc="Front Cover (2)"),
        ))
Beispiel #7
0
def test_stores_several_pictures(flac):
    filename = flac()
    metadata = Metadata()
    metadata.addImage("image/jpeg", b"front-1.jpg", desc="Front Cover")
    metadata.addImage("image/jpeg", b"front-2.jpg", desc="Front Cover")

    container.save(filename, metadata)

    assert_that(
        container.load(filename).images,
        contains_inanyorder(
            Image("image/jpeg",
                  b"front-1.jpg",
                  type_=Image.OTHER,
                  desc="Front Cover"),
            Image("image/jpeg",
                  b"front-2.jpg",
                  type_=Image.OTHER,
                  desc="Front Cover (2)"),
        ))
Beispiel #8
0
def scale(image, width, height):
    edited = QImage.fromData(image.data, format_for(image.mime))
    if edited.isNull():
        return image

    scaled = edited.scaled(width, height, Qt.KeepAspectRatio, Qt.SmoothTransformation)

    buffer = QBuffer()
    buffer.open(QIODevice.WriteOnly)
    scaled.save(buffer, format_for(image.mime))
    buffer.close()
    return Image(mime=image.mime, data=buffer.data(), desc=image.desc, type_=image.type)
Beispiel #9
0
def test_snapshots_thumbnail_of_project_main_cover(scaler):
    project = make_project(
        images=[make_image(mime="image/png", data=b'<image data>')])
    scaler.should_receive("scale").with_args(
        matching(image_with(mime="image/png", data=b'<image data>')), 64,
        64).and_return(Image(mime="image/png", data=b'<scaled image data>'))

    snapshot = ProjectSnapshot.of(project, image_editor=scaler)

    project.remove_images()
    assert_that(snapshot.cover_art,
                image_with(mime="image/png", data=b'<scaled image data>'),
                "snapshot's thumbnail")
Beispiel #10
0
    def contains_track(self, album, filename, front_cover=None, **tags):
        if not exists(self.file(album, TRACKS_FOLDER_NAME, filename)):
            raise AssertionError("Track file '{}' not found in workspace".format(filename))

        track = tagging.load_track(self.file(album, TRACKS_FOLDER_NAME, filename))
        images = []
        # todo use builders and metadata
        if front_cover:
            image, desc = front_cover
            mime = fs.guess_mime_type(image)
            images.append(Image(mime, fs.read(image), type_=Image.FRONT_COVER, desc=desc))

        assert_that(track.metadata, has_entries(tags), "metadata tags")
        assert_that(track.metadata.images, contains(*images), "attached pictures")
Beispiel #11
0
def test_signals_state_changes_to_listener():
    _assert_notifies_of_metadata_change("release_name", "Album")
    _assert_notifies_of_metadata_change("lead_performer", "Artist")
    _assert_notifies_of_metadata_change("guest_performers",
                                        [("Musician", "Instrument")])
    _assert_notifies_of_metadata_change("label_name", "Label")
    _assert_notifies_of_metadata_change("release_time", "Released")
    _assert_notifies_of_metadata_change("original_release_time",
                                        "Original Release")
    _assert_notifies_of_metadata_change("upc", "Barcode")
    _assert_notifies_of_metadata_change("isnis",
                                        {"Joel Miller": "0000000123456789"})
    _assert_notifies_of_metadata_change("ipis",
                                        {"Joel Miller": "0000000123456789"})
    _assert_notifies_of_images_change(Image("image/jpeg", "front-cover.jpg"))
Beispiel #12
0
def image_file(path):
    return Image(mime=fs.guess_mime_type(path),
                 data=fs.read(path),
                 desc=os.path.basename(path))
Beispiel #13
0
def null_image():
    return Image(mime="image/png", data=b'')
Beispiel #14
0
def test_assumes_front_cover_image_for_artwork_without_a_description():
    artwork = Image("image/png", b"...", Image.FRONT_COVER, "")

    assert_that(naming.artwork_scheme(artwork), equal_to("Front Cover.png"),
                "name of picture file")
Beispiel #15
0
def test_names_artwork_file_with_desc_and_mime_type():
    artwork = Image("image/png", b"...", Image.FRONT_COVER, "Front Cover")

    assert_that(naming.artwork_scheme(artwork), equal_to("Front Cover.png"),
                "name of picture file")
Beispiel #16
0
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

from PyQt5.QtGui import QPixmap, QImage

from tgit import imager
from tgit.metadata import Image
from tgit.ui import resources

INVALID_IMAGE = Image("image/png", resources.load(":/images/broken"))
PLACEHOLDER_IMAGE = Image("image/png", resources.load(":/images/placeholder"))


def broken(width, height):
    return from_image(imager.scale(INVALID_IMAGE, width, height))


def none(width, height):
    return from_image(imager.scale(PLACEHOLDER_IMAGE, width, height))


def from_image(image):
    return QPixmap.fromImage(QImage.fromData(image.data))