Commit 73e1439e authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Media: Publicly allow thumbnail to be edited

parent 94abdc9d
......@@ -126,6 +126,15 @@ class IMedia
/// The media library
///
virtual const std::string& thumbnail() = 0;
///
/// \brief setThumbnail Sets a thumbnail for the current media
/// \param mrl A mrl pointing the the thumbnail file.
/// \return true in case the thumbnail was successfully stored to database
/// false otherwise
/// This is intended to be used by applications that have their own way
/// of computing thumbnails.
///
virtual bool setThumbnail( const std::string& mrl ) = 0;
virtual unsigned int insertionDate() const = 0;
virtual unsigned int releaseDate() const = 0;
......
......@@ -350,7 +350,7 @@ void Media::setReleaseDate( unsigned int date )
m_changed = true;
}
void Media::setThumbnail(const std::string& thumbnail )
void Media::setThumbnailCached( const std::string& thumbnail )
{
if ( m_thumbnail == thumbnail )
return;
......@@ -358,6 +358,16 @@ void Media::setThumbnail(const std::string& thumbnail )
m_changed = true;
}
bool Media::setThumbnail(const std::string& thumbnail )
{
static const std::string req = "UPDATE " + policy::MediaTable::Name + " SET "
"thumbnail = ? WHERE id_media = ?";
if ( sqlite::Tools::executeUpdate( m_ml->getConn(), req, thumbnail, m_id ) == false )
return false;
m_thumbnail = thumbnail;
return true;
}
bool Media::save()
{
static const std::string req = "UPDATE " + policy::MediaTable::Name + " SET "
......
......@@ -123,6 +123,7 @@ class Media : public IMedia, public DatabaseHelpers<Media, policy::MediaTable>
unsigned int nbChannels, const std::string& language, const std::string& desc );
virtual std::vector<AudioTrackPtr> audioTracks() override;
virtual const std::string& thumbnail() override;
virtual bool setThumbnail( const std::string &thumbnail );
virtual unsigned int insertionDate() const override;
virtual unsigned int releaseDate() const override;
......@@ -131,7 +132,7 @@ class Media : public IMedia, public DatabaseHelpers<Media, policy::MediaTable>
virtual bool setMetadata( MetadataType type, int64_t value ) override;
void setReleaseDate( unsigned int date );
void setThumbnail( const std::string& thumbnail );
void setThumbnailCached( const std::string& thumbnail );
bool save();
std::shared_ptr<File> addFile( const fs::IFile& fileFs, int64_t parentFolderId,
......
......@@ -398,7 +398,7 @@ bool MetadataParser::parseAudioFile( parser::Task& task )
auto artworkMrl = task.vlcMedia.meta( libvlc_meta_ArtworkURL );
if ( artworkMrl.empty() == false )
{
task.media->setThumbnail( artworkMrl );
task.media->setThumbnailCached( artworkMrl );
// Don't use an attachment as default artwork for album/artists
if ( utils::file::schemeIs( "attachment", artworkMrl ) )
artworkMrl.clear();
......
......@@ -252,7 +252,7 @@ void VLCThumbnailer::updateAudioArtwork( parser::Task& task )
if ( artwork.empty() == true )
return;
task.media->setThumbnail( artwork );
task.media->setThumbnailCached( artwork );
task.media->save();
auto rel = AlbumTrack::fromMedia( m_ml, task.media->id() );
if ( rel == nullptr )
......@@ -384,7 +384,7 @@ parser::Task::Status VLCThumbnailer::compress( Media* media, File* file )
hOffset, vOffset ) == false )
return parser::Task::Status::Fatal;
media->setThumbnail( path );
media->setThumbnailCached( path );
return parser::Task::Status::Success;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment