[vlc-devel] [PATCH 05/14] medialibrary: add input_slaves to the ml hierarchy
Alaric Senat
dev.asenat at posteo.net
Fri Mar 19 11:40:00 UTC 2021
Previously, input_files's slaves where just ignored while creating
ml files.
These changes take into account these files, create them in the ml
hierarchy and link them with their relatives.
---
modules/misc/medialibrary/fs/directory.cpp | 29 +++++++++++++++++++++-
modules/misc/medialibrary/fs/directory.h | 1 +
modules/misc/medialibrary/fs/file.cpp | 28 +++++++++++++++++----
modules/misc/medialibrary/fs/file.h | 14 +++++++----
4 files changed, 61 insertions(+), 11 deletions(-)
diff --git a/modules/misc/medialibrary/fs/directory.cpp b/modules/misc/medialibrary/fs/directory.cpp
index 50ef287217..858553b273 100644
--- a/modules/misc/medialibrary/fs/directory.cpp
+++ b/modules/misc/medialibrary/fs/directory.cpp
@@ -188,6 +188,7 @@ SDDirectory::read() const
input_item_AddOption( media.get(), "show-hiddenfiles", VLC_INPUT_OPTION_TRUSTED );
input_item_AddOption( media.get(), "ignore-filetypes=''", VLC_INPUT_OPTION_TRUSTED );
+ input_item_AddOption( media.get(), "sub-autodetect-fuzzy=2", VLC_INPUT_OPTION_TRUSTED );
auto status = request_metadata_sync( m_fs.libvlc(), media.get(), &children);
if ( status == false )
@@ -199,13 +200,39 @@ SDDirectory::read() const
const char *mrl = m.get()->psz_uri;
enum input_item_type_e type = m->i_type;
if (type == ITEM_TYPE_DIRECTORY)
+ {
m_dirs.push_back(std::make_shared<SDDirectory>(mrl, m_fs));
+ }
else if (type == ITEM_TYPE_FILE)
- m_files.push_back(std::make_shared<SDFile>(mrl));
+ {
+ addFile( mrl, IFile::LinkedFileType::None, {} );
+ for ( auto i = 0; i < m->i_slaves; ++i )
+ {
+ const auto* slave = m->pp_slaves[i];
+ const auto linked_type = slave->i_type == SLAVE_TYPE_AUDIO
+ ? IFile::LinkedFileType::SoundTrack
+ : IFile::LinkedFileType::Subtitles;
+
+ addFile( slave->psz_uri, linked_type, mrl );
+ }
+ }
}
m_read_done = true;
}
+void
+SDDirectory::addFile(std::string mrl, IFile::LinkedFileType fType, std::string linkedFile) const
+{
+ if ( fType == IFile::LinkedFileType::None )
+ {
+ m_files.push_back( std::make_shared<SDFile>( std::move( mrl ) ) );
+ }
+ else
+ {
+ m_files.push_back(
+ std::make_shared<SDFile>( std::move( mrl ), fType, std::move( linkedFile ) ) );
+ }
+}
} /* namespace medialibrary */
} /* namespace vlc */
diff --git a/modules/misc/medialibrary/fs/directory.h b/modules/misc/medialibrary/fs/directory.h
index c73ef1b1a3..1409cd0d95 100644
--- a/modules/misc/medialibrary/fs/directory.h
+++ b/modules/misc/medialibrary/fs/directory.h
@@ -43,6 +43,7 @@ public:
private:
void read() const;
+ void addFile( std::string mrl, fs::IFile::LinkedFileType, std::string linkedWith ) const;
std::string m_mrl;
SDFileSystemFactory &m_fs;
diff --git a/modules/misc/medialibrary/fs/file.cpp b/modules/misc/medialibrary/fs/file.cpp
index 77b48329e5..6ae7400955 100644
--- a/modules/misc/medialibrary/fs/file.cpp
+++ b/modules/misc/medialibrary/fs/file.cpp
@@ -28,10 +28,22 @@
namespace vlc {
namespace medialibrary {
-SDFile::SDFile(const std::string &mrl)
- : m_mrl(mrl)
- , m_name(utils::fileName(mrl))
- , m_extension(utils::extension(mrl))
+SDFile::SDFile( const std::string mrl )
+ : m_mrl( std::move( mrl ) )
+ , m_name( utils::fileName( m_mrl ) )
+ , m_extension( utils::extension( m_mrl ) )
+ , m_isNetwork( m_mrl.rfind( "file://" ) != 0 )
+{
+}
+SDFile::SDFile( const std::string mrl,
+ const LinkedFileType fType,
+ const std::string linkedFile )
+ : m_mrl( std::move( mrl ) )
+ , m_name( utils::fileName( m_mrl ) )
+ , m_extension( utils::extension( m_mrl ) )
+ , m_linkedFile( std::move( linkedFile ) )
+ , m_linkedType( fType )
+ , m_isNetwork( m_mrl.rfind( "file://" ) != 0 )
{
}
@@ -59,6 +71,12 @@ SDFile::lastModificationDate() const
return 0;
}
+bool
+SDFile::isNetwork() const
+{
+ return m_isNetwork;
+}
+
int64_t
SDFile::size() const
{
@@ -67,7 +85,7 @@ SDFile::size() const
IFile::LinkedFileType SDFile::linkedType() const
{
- return IFile::LinkedFileType::None;
+ return m_linkedType;
}
const std::string &SDFile::linkedWith() const
diff --git a/modules/misc/medialibrary/fs/file.h b/modules/misc/medialibrary/fs/file.h
index 05730f6bda..97886ddbc5 100644
--- a/modules/misc/medialibrary/fs/file.h
+++ b/modules/misc/medialibrary/fs/file.h
@@ -31,22 +31,26 @@ using namespace ::medialibrary::fs;
class SDFile : public IFile
{
public:
- explicit SDFile(const std::string &mrl);
+ explicit SDFile( std::string mrl );
+ SDFile( std::string mrl, LinkedFileType, std::string linkedFile );
+
virtual ~SDFile() = default;
const std::string& mrl() const override;
const std::string& name() const override;
const std::string& extension() const override;
- time_t lastModificationDate() const override;
- int64_t size() const override;
- inline bool isNetwork() const override { return true; }
+ const std::string& linkedWith() const override;
LinkedFileType linkedType() const override;
- const std::string &linkedWith() const override;
+ bool isNetwork() const override;
+ int64_t size() const override;
+ time_t lastModificationDate() const override;
private:
std::string m_mrl;
std::string m_name;
std::string m_extension;
std::string m_linkedFile;
+ LinkedFileType m_linkedType = LinkedFileType::None;
+ bool m_isNetwork;
};
} /* namespace medialibrary */
--
2.29.2
More information about the vlc-devel
mailing list