Commit 917f3e03 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

IItem: Only expose public types

Since this type is also meant to be public
parent 9f6f90a6
......@@ -164,9 +164,10 @@ parser::Status MetadataParser::run( parser::IItem& item )
assert( false );
return parser::Status::Fatal;
}
auto media = std::static_pointer_cast<Media>( item.media() );
if ( item.parentPlaylist() != nullptr )
item.parentPlaylist()->add( item.media()->id(), item.parentPlaylistIndex() );
item.parentPlaylist()->add( media->id(), item.parentPlaylistIndex() );
if ( alreadyInParser == true )
return parser::Status::Discarded;
......@@ -179,13 +180,13 @@ parser::Status MetadataParser::run( parser::IItem& item )
bool isAudio = true;
{
using TracksT = decltype( tracks );
sqlite::Tools::withRetries( 3, [this, &isAudio, &item]( TracksT tracks ) {
sqlite::Tools::withRetries( 3, [this, &isAudio, &item, &media]( TracksT tracks ) {
auto t = m_ml->getConn()->newTransaction();
for ( const auto& track : tracks )
{
if ( track.type == parser::IItem::Track::Type::Video )
{
item.media()->addVideoTrack( track.codec, track.v.width, track.v.height,
media->addVideoTrack( track.codec, track.v.width, track.v.height,
static_cast<float>( track.v.fpsNum ) /
static_cast<float>( track.v.fpsDen ),
track.language, track.description );
......@@ -194,12 +195,12 @@ parser::Status MetadataParser::run( parser::IItem& item )
else
{
assert( track.type == parser::IItem::Track::Type::Audio );
item.media()->addAudioTrack( track.codec, track.bitrate,
media->addAudioTrack( track.codec, track.bitrate,
track.a.rate, track.a.nbChannels,
track.language, track.description );
}
}
item.media()->setDuration( item.duration() );
media->setDuration( item.duration() );
t->commit();
}, std::move( tracks ) );
}
......@@ -214,10 +215,11 @@ parser::Status MetadataParser::run( parser::IItem& item )
return parser::Status::Fatal;
}
if ( item.file()->isDeleted() == true || item.media()->isDeleted() == true )
if ( std::static_pointer_cast<File>( item.file() )->isDeleted() == true ||
std::static_pointer_cast<Media>( media )->isDeleted() == true )
return parser::Status::Fatal;
m_notifier->notifyMediaCreation( item.media() );
m_notifier->notifyMediaCreation( media );
return parser::Status::Success;
}
......@@ -368,7 +370,7 @@ void MetadataParser::addPlaylistElement( parser::IItem& item,
bool MetadataParser::parseVideoFile( parser::IItem& item ) const
{
auto media = item.media().get();
auto media = static_cast<Media*>( item.media().get() );
media->setType( IMedia::Type::Video );
const auto& title = item.meta( parser::IItem::Metadata::Title );
if ( title.length() == 0 )
......@@ -377,12 +379,12 @@ bool MetadataParser::parseVideoFile( parser::IItem& item ) const
const auto& showName = item.meta( parser::IItem::Metadata::ShowName );
const auto& artworkMrl = item.meta( parser::IItem::Metadata::ArtworkUrl );
return sqlite::Tools::withRetries( 3, [this, &showName, &title, &item, &artworkMrl]() {
return sqlite::Tools::withRetries( 3, [this, &showName, &title, media, &item, &artworkMrl]() {
auto t = m_ml->getConn()->newTransaction();
item.media()->setTitleBuffered( title );
media->setTitleBuffered( title );
if ( artworkMrl.empty() == false )
item.media()->setThumbnail( artworkMrl, Thumbnail::Origin::Media );
media->setThumbnail( artworkMrl, Thumbnail::Origin::Media );
if ( showName.length() != 0 )
{
......@@ -397,14 +399,14 @@ bool MetadataParser::parseVideoFile( parser::IItem& item ) const
if ( episode != 0 )
{
std::shared_ptr<Show> s = std::static_pointer_cast<Show>( show );
s->addEpisode( *item.media(), title, episode );
s->addEpisode( *media, title, episode );
}
}
else
{
// How do we know if it's a movie or a random video?
}
item.media()->save();
media->save();
t->commit();
return true;
});
......@@ -415,12 +417,13 @@ bool MetadataParser::parseVideoFile( parser::IItem& item ) const
bool MetadataParser::parseAudioFile( parser::IItem& item )
{
item.media()->setType( IMedia::Type::Audio );
auto media = static_cast<Media*>( item.media().get() );
media->setType( IMedia::Type::Audio );
auto artworkMrl = item.meta( parser::IItem::Metadata::ArtworkUrl );
if ( artworkMrl.empty() == false )
{
item.media()->setThumbnail( artworkMrl, Thumbnail::Origin::Media );
media->setThumbnail( artworkMrl, Thumbnail::Origin::Media );
// Don't use an attachment as default artwork for album/artists
if ( utils::file::schemeIs( "attachment", artworkMrl ) )
artworkMrl.clear();
......@@ -432,7 +435,7 @@ bool MetadataParser::parseAudioFile( parser::IItem& item )
if ( artists.first == nullptr && artists.second == nullptr )
return false;
auto album = findAlbum( item, artists.first, artists.second );
return sqlite::Tools::withRetries( 3, [this, &item, &artists]( std::string artworkMrl,
return sqlite::Tools::withRetries( 3, [this, &item, &artists, media]( std::string artworkMrl,
std::shared_ptr<Album> album, std::shared_ptr<Genre> genre ) {
auto t = m_ml->getConn()->newTransaction();
if ( album == nullptr )
......@@ -455,8 +458,8 @@ bool MetadataParser::parseAudioFile( parser::IItem& item )
auto track = handleTrack( album, item, artists.second ? artists.second : artists.first,
genre.get() );
auto res = link( *item.media(), album, artists.first, artists.second );
item.media()->save();
auto res = link( *media, album, artists.first, artists.second );
media->save();
t->commit();
return res;
}, std::move( artworkMrl ), std::move( album ), std::move( genre ) );
......@@ -492,8 +495,9 @@ std::shared_ptr<Album> MetadataParser::findAlbum( parser::IItem& item, std::shar
return m_unknownArtist->unknownAlbum();
}
auto file = static_cast<File*>( item.file().get() );
if ( m_previousAlbum != nullptr && albumName == m_previousAlbum->title() &&
m_previousFolderId != 0 && item.file()->folderId() == m_previousFolderId )
m_previousFolderId != 0 && file->folderId() == m_previousFolderId )
return m_previousAlbum;
m_previousAlbum.reset();
m_previousFolderId = 0;
......@@ -579,7 +583,7 @@ std::shared_ptr<Album> MetadataParser::findAlbum( parser::IItem& item, std::shar
}
// Assume album files will be in the same folder.
auto newFileFolder = utils::file::directory( item.file()->mrl() );
auto newFileFolder = utils::file::directory( file->mrl() );
auto trackFiles = tracks[0]->files();
bool differentFolder = false;
for ( auto& f : trackFiles )
......@@ -639,7 +643,7 @@ std::shared_ptr<Album> MetadataParser::findAlbum( parser::IItem& item, std::shar
{
LOG_WARN( "Multiple candidates for album ", albumName, ". Selecting first one out of luck" );
}
m_previousFolderId = item.file()->folderId();
m_previousFolderId = file->folderId();
m_previousAlbum = albums[0];
return albums[0];
}
......@@ -705,6 +709,7 @@ std::shared_ptr<AlbumTrack> MetadataParser::handleTrack( std::shared_ptr<Album>
auto title = item.meta( parser::IItem::Metadata::Title );
const auto trackNumber = toInt( item, parser::IItem::Metadata::TrackNumber );
const auto discNumber = toInt( item, parser::IItem::Metadata::DiscNumber );
auto media = std::static_pointer_cast<Media>( item.media() );
if ( title.empty() == true )
{
LOG_WARN( "Failed to get track title" );
......@@ -715,9 +720,9 @@ std::shared_ptr<AlbumTrack> MetadataParser::handleTrack( std::shared_ptr<Album>
}
}
if ( title.empty() == false )
item.media()->setTitleBuffered( title );
media->setTitleBuffered( title );
auto track = std::static_pointer_cast<AlbumTrack>( album->addTrack( item.media(), trackNumber,
auto track = std::static_pointer_cast<AlbumTrack>( album->addTrack( media, trackNumber,
discNumber, artist->id(),
genre ) );
if ( track == nullptr )
......@@ -730,7 +735,7 @@ std::shared_ptr<AlbumTrack> MetadataParser::handleTrack( std::shared_ptr<Album>
if ( releaseDate.empty() == false )
{
auto releaseYear = atoi( releaseDate.c_str() );
item.media()->setReleaseDate( releaseYear );
media->setReleaseDate( releaseYear );
// Let the album handle multiple dates. In order to do this properly, we need
// to know if the date has been changed before, which can be known only by
// using Album class internals.
......
......@@ -28,15 +28,11 @@
#include "filesystem/IFile.h"
#include "filesystem/IDirectory.h"
#include "medialibrary/Types.h"
namespace medialibrary
{
class Folder;
class File;
class Media;
class Playlist;
namespace parser
{
......@@ -162,21 +158,21 @@ public:
* @brief media Returns the media associated with this item, if any.
* @return nullptr if the item isn't associated with a Media yet.
*/
virtual std::shared_ptr<Media> media() = 0;
virtual MediaPtr media() = 0;
/**
* @brief setMedia Assigns a Media to this item
*/
virtual void setMedia( std::shared_ptr<Media> media ) = 0;
virtual void setMedia( MediaPtr media ) = 0;
/**
* @brief file Returns the File (as in, the database entity) associated with
* this item, if any. It returns nullptr otherwise
*/
virtual std::shared_ptr<File> file() = 0;
virtual FilePtr file() = 0;
/**
* @brief setFile Assigns a File to the item
*/
virtual bool setFile( std::shared_ptr<File> file ) = 0;
virtual bool setFile( FilePtr file ) = 0;
/**
* @brief parentFolder Returns the Folder (as in the database entity)
......@@ -186,7 +182,7 @@ public:
* if it was added through its complete MRL, instead of being
* discovered through its parent folder.
*/
virtual std::shared_ptr<Folder> parentFolder() = 0;
virtual FolderPtr parentFolder() = 0;
/**
* @brief fileFs returns an fs::IFile representing the item
......@@ -210,7 +206,7 @@ public:
* playlist entity might have not been created, depending on the analysis progress.
* Usually the playlists are created after the MetadataAnalysis step.
*/
virtual std::shared_ptr<Playlist> parentPlaylist() = 0;
virtual PlaylistPtr parentPlaylist() = 0;
/**
* @brief parentPlaylistIndex Returns this item's index in a playlist, if any.
......
......@@ -174,8 +174,10 @@ void ParserWorker::mainloop()
{
LOG_INFO( "Executing ", serviceName, " task on ", task->item().mrl() );
auto chrono = std::chrono::steady_clock::now();
if ( ( task->item().file() != nullptr && task->item().file()->isDeleted() )
|| ( task->item().media() != nullptr && task->item().media()->isDeleted() ) )
auto file = std::static_pointer_cast<File>( task->item().file() );
auto media = std::static_pointer_cast<Media>( task->item().media() );
if ( ( file != nullptr && file->isDeleted() )
|| ( media != nullptr && media->isDeleted() ) )
status = parser::Status::Fatal;
else
{
......
......@@ -32,6 +32,7 @@
#include "File.h"
#include "Folder.h"
#include "Playlist.h"
#include "Media.h"
#include "parser/Task.h"
#include "utils/Filename.h"
#include "utils/Url.h"
......@@ -224,29 +225,29 @@ void Task::Item::addTrack(Task::Item::Track t)
m_tracks.emplace_back( std::move( t ) );
}
std::shared_ptr<Media> Task::Item::media()
MediaPtr Task::Item::media()
{
return m_media;
}
void Task::Item::setMedia( std::shared_ptr<Media> media )
void Task::Item::setMedia( MediaPtr media )
{
m_media = std::move( media );
}
std::shared_ptr<File> Task::Item::file()
FilePtr Task::Item::file()
{
return m_file;
}
bool Task::Item::setFile(std::shared_ptr<File> file)
bool Task::Item::setFile( FilePtr file)
{
m_file = std::move( file );
assert( m_taskCb != nullptr );
return m_taskCb->updateFileId( m_file->id() );
}
std::shared_ptr<Folder> Task::Item::parentFolder()
FolderPtr Task::Item::parentFolder()
{
return m_parentFolder;
}
......@@ -261,7 +262,7 @@ std::shared_ptr<fs::IDirectory> Task::Item::parentFolderFs()
return m_parentFolderFs;
}
std::shared_ptr<Playlist> Task::Item::parentPlaylist()
PlaylistPtr Task::Item::parentPlaylist()
{
return m_parentPlaylist;
}
......
......@@ -116,19 +116,19 @@ public:
virtual const std::vector<Track>& tracks() const override;
virtual void addTrack( Track t ) override;
virtual std::shared_ptr<Media> media() override;
virtual void setMedia( std::shared_ptr<Media> media ) override;
virtual MediaPtr media() override;
virtual void setMedia( MediaPtr media ) override;
virtual std::shared_ptr<File> file() override;
virtual bool setFile( std::shared_ptr<File> file ) override;
virtual FilePtr file() override;
virtual bool setFile( FilePtr file ) override;
virtual std::shared_ptr<Folder> parentFolder() override;
virtual FolderPtr parentFolder() override;
virtual std::shared_ptr<fs::IFile> fileFs() override;
virtual std::shared_ptr<fs::IDirectory> parentFolderFs() override;
virtual std::shared_ptr<Playlist> parentPlaylist() override;
virtual PlaylistPtr parentPlaylist() override;
virtual unsigned int parentPlaylistIndex() const override;
......@@ -140,12 +140,12 @@ public:
std::vector<Item> m_subItems;
std::vector<Track> m_tracks;
int64_t m_duration;
std::shared_ptr<Media> m_media;
std::shared_ptr<File> m_file;
MediaPtr m_media;
FilePtr m_file;
std::shared_ptr<fs::IFile> m_fileFs;
std::shared_ptr<Folder> m_parentFolder;
FolderPtr m_parentFolder;
std::shared_ptr<fs::IDirectory> m_parentFolderFs;
std::shared_ptr<Playlist> m_parentPlaylist;
PlaylistPtr m_parentPlaylist;
unsigned int m_parentPlaylistIndex;
};
......
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