Commit 5ebc44bf authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

parser: Item: Remove playlist index setter

parent 91d4c039
......@@ -258,14 +258,14 @@ bool MetadataParser::addPlaylistMedias( parser::Task& task ) const
task.item().setFile( std::move( file ) );
t->commit();
auto subitems = task.item().subItems();
for ( auto i = 0u; i < subitems.size(); ++i ) // FIXME: Interrupt loop if paused
addPlaylistElement( task, playlistPtr, subitems[i], static_cast<unsigned int>( i ) + 1 );
for ( const auto& subItem : subitems ) // FIXME: Interrupt loop if paused
addPlaylistElement( task, playlistPtr, subItem );
return true;
}
void MetadataParser::addPlaylistElement( parser::Task& task, const std::shared_ptr<Playlist>& playlistPtr,
parser::Task::Item& subitem, unsigned int index ) const
const parser::Task::Item& subitem ) const
{
const auto& mrl = subitem.mrl();
LOG_INFO( "Try to add ", mrl, " to the playlist ", mrl );
......@@ -273,7 +273,7 @@ void MetadataParser::addPlaylistElement( parser::Task& task, const std::shared_p
if ( media != nullptr )
{
LOG_INFO( "Media for ", mrl, " already exists, adding it to the playlist ", mrl );
playlistPtr->add( media->id(), index );
playlistPtr->add( media->id(), subitem.parentPlaylistIndex() );
return;
}
// Create Media, etc.
......@@ -293,7 +293,7 @@ void MetadataParser::addPlaylistElement( parser::Task& task, const std::shared_p
auto externalFile = externalMedia->addExternalMrl( mrl, IFile::Type::Main );
if ( externalFile == nullptr )
LOG_ERROR( "Failed to create external file for ", mrl, " in the playlist ", task.item().mrl() );
playlistPtr->add( externalMedia->id(), index );
playlistPtr->add( externalMedia->id(), subitem.parentPlaylistIndex() );
t2->commit();
return;
}
......@@ -324,14 +324,14 @@ void MetadataParser::addPlaylistElement( parser::Task& task, const std::shared_p
{
auto probePtr = std::unique_ptr<prober::PathProbe>( new prober::PathProbe{ utils::file::stripScheme( mrl ),
isDirectory, playlistPtr, parentFolder,
utils::file::stripScheme( directoryMrl ), index, true } );
utils::file::stripScheme( directoryMrl ), subitem.parentPlaylistIndex(), true } );
FsDiscoverer discoverer( fsFactory, m_ml, nullptr, std::move( probePtr ) );
discoverer.reload( entryPoint );
return;
}
auto probePtr = std::unique_ptr<prober::PathProbe>( new prober::PathProbe{ utils::file::stripScheme( mrl ),
isDirectory, playlistPtr, parentFolder,
utils::file::stripScheme( directoryMrl ), index, false } );
utils::file::stripScheme( directoryMrl ), subitem.parentPlaylistIndex(), false } );
FsDiscoverer discoverer( fsFactory, m_ml, nullptr, std::move( probePtr ) );
if ( parentKnown == false )
{
......
......@@ -47,7 +47,7 @@ protected:
bool addPlaylistMedias( parser::Task& task ) const;
void addPlaylistElement( parser::Task& task, const std::shared_ptr<Playlist>& playlistPtr,
parser::Task::Item& subitem, unsigned int index ) const;
const parser::Task::Item& subitem ) const;
bool parseAudioFile(parser::Task& task);
bool parseVideoFile(parser::Task& task) const;
std::pair<std::shared_ptr<Artist>, std::shared_ptr<Artist>> findOrCreateArtist( parser::Task& vlcMedia ) const;
......
......@@ -190,7 +190,9 @@ void VLCMetadataService::mediaToItem( VLC::Media& media, parser::Task::Item& ite
{
auto vlcMedia = subItems->itemAtIndex( i );
assert( vlcMedia != nullptr );
parser::Task::Item subItem{ vlcMedia->mrl() };
// Always add 1 to the playlist/subitem index, as 0 is an invalid index
// in this context
parser::Task::Item subItem{ vlcMedia->mrl(), i + 1u };
mediaToItem( *vlcMedia, subItem );
item.addSubItem( std::move( subItem ) );
}
......
......@@ -62,8 +62,7 @@ Task::Task( MediaLibraryPtr ml, sqlite::Row& row )
>> m_parentFolderId
>> m_parentPlaylistId
>> parentPlaylistIndex;
m_item = Item{ std::move( mrl ) };
m_item.setParentPlaylistIndex( parentPlaylistIndex );
m_item = Item{ std::move( mrl ), parentPlaylistIndex };
}
Task::Task( MediaLibraryPtr ml, std::shared_ptr<fs::IFile> fileFs,
......@@ -137,10 +136,10 @@ Task::Item& Task::item()
return m_item;
}
Task::Item::Item( std::string mrl )
Task::Item::Item( std::string mrl, unsigned int subitemPosition )
: m_mrl( std::move( mrl ) )
, m_duration( 0 )
, m_parentPlaylistIndex( 0 )
, m_parentPlaylistIndex( subitemPosition )
{
}
......@@ -276,11 +275,6 @@ unsigned int Task::Item::parentPlaylistIndex() const
return m_parentPlaylistIndex;
}
void Task::Item::setParentPlaylistIndex( unsigned int parentPlaylistIndex )
{
m_parentPlaylistIndex = parentPlaylistIndex;
}
bool Task::restoreLinkedEntities()
{
LOG_INFO("Restoring linked entities of task ", m_id);
......
......@@ -93,7 +93,14 @@ public:
{
public:
Item() = default;
Item( std::string mrl );
/**
* @brief Item Construct a parser item with a given mrl and subitem index
* @param mrl The item's mrl
* @param subitemPosition A potential subitem index, if any, or 0 if none.
*
* The position is used to keep subitems ordering for playlists
*/
Item( std::string mrl, unsigned int subitemIndex );
Item( std::shared_ptr<fs::IFile> fileFs,
std::shared_ptr<Folder> folder, std::shared_ptr<fs::IDirectory> folderFs,
std::shared_ptr<Playlist> parentPlaylist, unsigned int parentPlaylistIndex );
......@@ -181,7 +188,6 @@ public:
void setParentPlaylist( std::shared_ptr<Playlist> parentPlaylist );
unsigned int parentPlaylistIndex() const;
void setParentPlaylistIndex( unsigned int parentPlaylistIndex );
private:
std::string m_mrl;
......
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