Skip to content

Commit

Permalink
Add support for passing vectors of paths into MediaInfoList
Browse files Browse the repository at this point in the history
  • Loading branch information
hjmallon committed Feb 23, 2021
1 parent 5d833dd commit f1fcd65
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 22 deletions.
6 changes: 6 additions & 0 deletions Source/MediaInfo/MediaInfoList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ size_t MediaInfoList::Open(const String &File, const fileoptions_t Options)
return Internal->Open(File, Options);
}

//---------------------------------------------------------------------------
size_t MediaInfoList::Open (const std::vector<String> &Files, const fileoptions_t Options)
{
return Internal->Open(Files, Options);
}

//---------------------------------------------------------------------------
size_t MediaInfoList::Open_Buffer_Init (int64u File_Size_, int64u File_Offset_)
{
Expand Down
9 changes: 9 additions & 0 deletions Source/MediaInfo/MediaInfoList.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

//---------------------------------------------------------------------------
#include "MediaInfo/MediaInfo.h"
#include <vector>
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
Expand Down Expand Up @@ -68,6 +69,14 @@ public :
/// FileOption_Close = Close all already opened files before
/// @return Number of files successfuly added
size_t Open (const String &File, const fileoptions_t Options=FileOption_Nothing);
/// Open one or more files and collect information about them (technical information and tags)
/// @brief Open files
/// @param File Full name of file(s) to open \n
/// or Full name of folder(s) to open \n
/// @param Options: FileOption_Recursive = Recursive mode for folders \n
/// FileOption_Close = Close all already opened files before
/// @return Number of files successfuly added
size_t Open (const std::vector<String> &Files, const fileoptions_t Options=FileOption_Nothing);
/// Open a stream and collect information about it (technical information and tags)
/// @brief Open a stream (Init)
/// @param File_Size Estimated file size
Expand Down
56 changes: 34 additions & 22 deletions Source/MediaInfo/MediaInfoList_Internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ MediaInfoList_Internal::~MediaInfoList_Internal()

//---------------------------------------------------------------------------
size_t MediaInfoList_Internal::Open(const String &File_Name, const fileoptions_t Options)
{
vector<String> File_Names;
File_Names.push_back(File_Name);
return Open(File_Names, Options);
}

//---------------------------------------------------------------------------
size_t MediaInfoList_Internal::Open(const vector<String> &File_Names, const fileoptions_t Options)
{
//Option FileOption_Close
if (Options & FileOption_CloseAll)
Expand All @@ -86,32 +94,36 @@ size_t MediaInfoList_Internal::Open(const String &File_Name, const fileoptions_t

//Get all filenames
ZtringList List;
#if defined(MEDIAINFO_DIRECTORY_YES)
if (Dir::Exists(File_Name))
for (const auto& File_Name : File_Names)
{
List=Dir::GetAllFileNames(File_Name, (Options&FileOption_NoRecursive)?Dir::Include_Files:((Dir::dirlist_t)(Dir::Include_Files|Dir::Parse_SubDirs)));
sort(List.begin(), List.end());
#if defined(MEDIAINFO_DIRECTORY_YES)
if (Dir::Exists(File_Name))
{
ZtringList LocalList=Dir::GetAllFileNames(File_Name, (Options&FileOption_NoRecursive)?Dir::Include_Files:((Dir::dirlist_t)(Dir::Include_Files|Dir::Parse_SubDirs)));
List.insert(List.end(), LocalList.begin(), LocalList.end());
sort(List.begin(), List.end());

#if MEDIAINFO_ADVANCED
if (MediaInfoLib::Config.ParseOnlyKnownExtensions_IsSet())
{
set<Ztring> ExtensionsList=MediaInfoLib::Config.ParseOnlyKnownExtensions_GetList_Set();
bool AcceptNoExtension=ExtensionsList.find(Ztring())!=ExtensionsList.end();
for (size_t i=List.size()-1; i!=(size_t)-1; i--)
#if MEDIAINFO_ADVANCED
if (MediaInfoLib::Config.ParseOnlyKnownExtensions_IsSet())
{
const Ztring& Name=List[i];
size_t Extension_Pos=Name.rfind(__T('.'));
if (Extension_Pos!=string::npos && ExtensionsList.find(Name.substr(Extension_Pos+1))==ExtensionsList.end()
|| Extension_Pos==string::npos && !AcceptNoExtension)
List.erase(List.begin()+i);
set<Ztring> ExtensionsList=MediaInfoLib::Config.ParseOnlyKnownExtensions_GetList_Set();
bool AcceptNoExtension=ExtensionsList.find(Ztring())!=ExtensionsList.end();
for (size_t i=List.size()-1; i!=(size_t)-1; i--)
{
const Ztring& Name=List[i];
size_t Extension_Pos=Name.rfind(__T('.'));
if (Extension_Pos!=string::npos && ExtensionsList.find(Name.substr(Extension_Pos+1))==ExtensionsList.end()
|| Extension_Pos==string::npos && !AcceptNoExtension)
List.erase(List.begin()+i);
}
}
}
#endif //MEDIAINFO_ADVANCED
}
else
#endif //defined(MEDIAINFO_DIRECTORY_YES)
{
List.push_back(File_Name);
#endif //MEDIAINFO_ADVANCED
}
else
#endif //defined(MEDIAINFO_DIRECTORY_YES)
{
List.push_back(File_Name);
}
}

#if defined(MEDIAINFO_DIRECTORY_YES)
Expand Down
1 change: 1 addition & 0 deletions Source/MediaInfo/MediaInfoList_Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public :

//Files
size_t Open (const String &File, const fileoptions_t Options=FileOption_Nothing);
size_t Open (const std::vector<String> &Files, const fileoptions_t Options=FileOption_Nothing);
size_t Open_Buffer_Init (ZenLib::int64u File_Size=(ZenLib::int64u)-1, ZenLib::int64u File_Offset=0);
size_t Open_Buffer_Continue (size_t FilePos, const ZenLib::int8u* Buffer, size_t Buffer_Size);
ZenLib::int64u Open_Buffer_Continue_GoTo_Get (size_t FilePos);
Expand Down

0 comments on commit f1fcd65

Please sign in to comment.