Reworked the project layout

This commit is contained in:
emeric
2014-10-10 20:41:34 +02:00
parent 92a176c899
commit 49ff050539
146 changed files with 156 additions and 162 deletions
+76
View File
@@ -0,0 +1,76 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <boost/gil/image.hpp>
#include <boost/gil/typedefs.hpp>
#include <boost/gil/extension/io/jpeg_io.hpp>
#include <boost/gil/extension/numeric/sampler.hpp>
#include <boost/gil/extension/numeric/resample.hpp>
#include <boost/gil/extension/io_new/jpeg_all.hpp>
#include "logger/Logger.hpp"
#include "CoverArt.hpp"
namespace CoverArt {
bool
CoverArt::scale(std::size_t size)
{
bool res = false;
if (!size)
return false;
try {
boost::gil::rgb8_image_t source;
boost::gil::rgb8_image_t dest(size, size);
// Read source
{
std::istringstream iss( std::string(_data.begin(), _data.end()));
boost::gil::read_image(iss, source, boost::gil::jpeg_tag());
}
// Resize
boost::gil::resize_view(boost::gil::const_view(source),
boost::gil::view(dest),
boost::gil::bilinear_sampler());
// Output to dest
{
std::ostringstream oss;
boost::gil::write_view(oss, boost::gil::const_view(dest), boost::gil::jpeg_tag());
std::string output = oss.str();
_data.assign(output.begin(), output.end());
}
res = true;
}
catch(std::exception& e)
{
LMS_LOG(MOD_COVER, SEV_ERROR) << "Caught exception: " << e.what();
}
return res;
}
} // namespace CoverArt
+56
View File
@@ -0,0 +1,56 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef COVER_ART_HPP
#define COVER_ART_HPP
#include <vector>
#include <string>
namespace CoverArt
{
class CoverArt
{
public:
typedef std::vector<unsigned char> data_type;
CoverArt();
CoverArt(const std::string& mime, const data_type& data) : _mimeType(mime), _data(data) {}
const std::string& getMimeType() const { return _mimeType; }
const data_type& getData() const { return _data; }
void setMimeType(const std::string& mimeType) { _mimeType = mimeType;}
void setData(const data_type& data) { _data = data; }
bool scale(std::size_t size);
private:
std::string _mimeType;
data_type _data;
};
} // namespace CoverArt
#endif
+106
View File
@@ -0,0 +1,106 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <boost/foreach.hpp>
#include "logger/Logger.hpp"
#include "av/InputFormatContext.hpp"
#include "CoverArtGrabber.hpp"
namespace CoverArt {
std::vector<CoverArt>
Grabber::getFromInputFormatContext(const Av::InputFormatContext& input)
{
std::vector<CoverArt> res;
try
{
std::vector< std::vector<unsigned char> > pictures;
input.getPictures(pictures);
BOOST_FOREACH(const std::vector<unsigned char>& 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<CoverArt>
Grabber::getFromTrack(Database::Track::pointer track)
{
std::vector<CoverArt> res;
if (!track)
return std::vector<CoverArt>();
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<CoverArt>
Grabber::getFromRelease(Database::Release::pointer release)
{
if (!release)
return std::vector<CoverArt>();
// 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<Database::Track::pointer> 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<CoverArt>();
}
} // namespace CoverArt
+45
View File
@@ -0,0 +1,45 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef COVER_ART_GRABBER_HPP
#define COVER_ART_GRABBER_HPP
#include <vector>
#include "av/InputFormatContext.hpp"
#include "database/AudioTypes.hpp"
#include "CoverArt.hpp"
namespace CoverArt {
class Grabber
{
public:
static std::vector<CoverArt> getFromInputFormatContext(const Av::InputFormatContext& input);
static std::vector<CoverArt> getFromTrack(Database::Track::pointer track);
static std::vector<CoverArt> getFromRelease(Database::Release::pointer release);
};
} // namespace CoverArt
#endif