/* * Copyright (C) 2013 Emeric Poupon * * This file is part of LMS. * * LMS is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * LMS 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 LMS. If not, see . */ #include #include "logger/Logger.hpp" #include "av/InputFormatContext.hpp" #include "CoverArtGrabber.hpp" namespace CoverArt { std::vector Grabber::getFromInputFormatContext(const Av::InputFormatContext& input) { std::vector res; try { std::vector< std::vector > pictures; input.getPictures(pictures); BOOST_FOREACH(const std::vector& picture, pictures) res.push_back( CoverArt("application/octet-stream", picture) ); } catch(std::exception& e) { LMS_LOG(MOD_COVER, SEV_ERROR) << "Cannot get pictures: " << e.what(); } return res; } std::vector Grabber::getFromTrack(Database::Track::pointer track) { std::vector res; if (!track) return std::vector(); try { Av::InputFormatContext input(track->getPath()); return getFromInputFormatContext(input); } catch(std::exception& e) { LMS_LOG(MOD_COVER, SEV_ERROR) << "Cannot get pictures: " << e.what(); } return res; } std::vector Grabber::getFromRelease(Database::Release::pointer release) { if (!release) return std::vector(); // TODO // Check if there is an image file in the directory of the release // For now, just get the cover art from the first track of the release Wt::Dbo::collection tracks (release->getTracks()); Database::Track::pointer firstTrack; if (tracks.begin() != tracks.end()) firstTrack = *tracks.begin(); if (firstTrack) { return Grabber::getFromTrack(firstTrack); } else return std::vector(); } } // namespace CoverArt