Commit 0386e0b4 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Metadata: Extract artwork attachment during the extraction phase

parent 270da229
......@@ -210,7 +210,7 @@ parser::Task::Status MetadataParser::run( parser::Task& task )
task.markStepCompleted( parser::Task::ParserStep::MetadataAnalysis );
// Save ourselves from the useless processing of a thumbnail later if
// we're analyzing an audio file
if ( isAudio == true && utils::file::schemeIs( "attachment://", task.media->thumbnail() ) == false )
if ( isAudio == true )
task.markStepCompleted( parser::Task::ParserStep::Thumbnailer );
if ( task.saveParserStep() == false )
return parser::Task::Status::Fatal;
......
......@@ -26,7 +26,7 @@
#include "Common.hpp"
#include "Media.h"
#include "utils/Filename.h"
namespace medialibrary
{
......@@ -58,13 +58,15 @@ medialibrary::MetadataCommon::startPlayback( parser::Task& task,
});
bool metaArtworkChanged = false;
bool watchForArtworkChange = false;
auto mem = task.vlcMedia.eventManager();
if ( task.media->type() == Media::Type::Audio )
if ( utils::file::schemeIs( "attachment", task.vlcMedia.meta( libvlc_meta_ArtworkURL ) ) == true )
{
watchForArtworkChange = true;
mem.onMetaChanged([&mutex, &cond, &metaArtworkChanged, &task]( libvlc_meta_t meta ) {
if ( meta != libvlc_meta_ArtworkURL
|| metaArtworkChanged == true
|| task.vlcMedia.meta( libvlc_meta_ArtworkURL ) == task.media->thumbnail() )
|| utils::file::schemeIs( "attachment", task.vlcMedia.meta( libvlc_meta_ArtworkURL ) ) == true )
return;
std::lock_guard<compat::Mutex> lock( mutex );
metaArtworkChanged = true;
......@@ -87,7 +89,7 @@ medialibrary::MetadataCommon::startPlayback( parser::Task& task,
// being discovered together.
if ( hasVideoTrack == false )
{
if ( task.media->type() == Media::Type::Audio )
if ( watchForArtworkChange == true )
{
cond.wait_for( lock, std::chrono::milliseconds( 500 ), [&metaArtworkChanged]() {
return metaArtworkChanged == true;
......
......@@ -30,6 +30,7 @@
#include "Media.h"
#include "utils/VLCInstance.h"
#include "metadata_services/vlc/Common.hpp"
#include "utils/Filename.h"
namespace medialibrary
{
......@@ -72,9 +73,12 @@ parser::Task::Status VLCMetadataService::run( parser::Task& task )
if ( status == VLC::Media::ParsedStatus::Failed || status == VLC::Media::ParsedStatus::Timeout )
return parser::Task::Status::Fatal;
auto tracks = task.vlcMedia.tracks();
if ( tracks.size() == 0 && task.vlcMedia.subitems()->count() == 0 )
auto artworkMrl = task.vlcMedia.meta( libvlc_meta_ArtworkURL );
if ( ( tracks.size() == 0 && task.vlcMedia.subitems()->count() == 0 ) ||
utils::file::schemeIs( "attachment://", artworkMrl ) == true )
{
LOG_WARN( "Failed to fetch any tracks for ", mrl, ". Falling back to playback" );
if ( tracks.size() == 0 && task.vlcMedia.subitems()->count() == 0 )
LOG_WARN( "Failed to fetch any tracks for ", mrl, ". Falling back to playback" );
VLC::MediaPlayer mp( task.vlcMedia );
auto resPair = MetadataCommon::startPlayback( task, mp );
if ( resPair.first != parser::Task::Status::Success )
......
......@@ -74,6 +74,8 @@ bool VLCThumbnailer::isCompleted( const parser::Task& task ) const
parser::Task::Status VLCThumbnailer::run( parser::Task& task )
{
assert( task.media->type() != Media::Type::Audio );
auto media = task.media.get();
auto file = task.file.get();
......@@ -91,7 +93,7 @@ parser::Task::Status VLCThumbnailer::run( parser::Task& task )
task.vlcMedia.addOption( ":avcodec-hw=none" );
task.vlcMedia.addOption( ":no-mkv-preload-local-dir" );
auto duration = task.vlcMedia.duration();
if ( duration > 0 && media->type() != IMedia::Type::Audio )
if ( duration > 0 )
{
std::ostringstream ss;
// Duration is in ms, start-time in seconds, and we're aiming at 1/4th of the media
......@@ -109,16 +111,6 @@ parser::Task::Status VLCThumbnailer::run( parser::Task& task )
LOG_WARN( "Failed to generate ", file->mrl(), " thumbnail: Can't start playback" );
return resPair.first;
}
else if ( resPair.second == false )
{
if ( task.media->type() == Media::Type::Audio )
{
updateAudioArtwork( task );
task.markStepCompleted( parser::Task::ParserStep::Thumbnailer );
task.saveParserStep();
}
return parser::Task::Status::Success;
}
if ( duration <= 0 )
{
......@@ -148,36 +140,6 @@ parser::Task::Status VLCThumbnailer::run( parser::Task& task )
return parser::Task::Status::Success;
}
void VLCThumbnailer::updateAudioArtwork( parser::Task& task )
{
auto artwork = task.vlcMedia.meta( libvlc_meta_ArtworkURL );
if ( artwork.empty() == true )
return;
task.media->setThumbnailCached( artwork );
task.media->save();
auto rel = AlbumTrack::fromMedia( m_ml, task.media->id() );
if ( rel == nullptr )
return;
auto album = rel->album();
if ( album->artworkMrl() == artwork )
return;
// We no not have any other IAlbum implementation, so the downcast is safe here
auto a = static_cast<Album*>( album.get() );
a->setArtworkMrl( artwork );
// If no artwork was set for the AlbumArtist, use this new one
auto artist = album->albumArtist();
if ( artist->artworkMrl().empty() == true )
{
auto artistPtr = static_cast<Artist*>( artist.get() );
artistPtr->setArtworkMrl( artwork );
}
}
parser::Task::Status VLCThumbnailer::seekAhead( VLC::MediaPlayer& mp )
{
float pos = .0f;
......
......@@ -42,7 +42,6 @@ public:
virtual bool isCompleted( const parser::Task& task ) const override;
private:
void updateAudioArtwork( parser::Task& task );
parser::Task::Status seekAhead( VLC::MediaPlayer &mp );
void setupVout( VLC::MediaPlayer &mp );
parser::Task::Status takeThumbnail( Media* media, File* file, VLC::MediaPlayer &mp );
......
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