1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2025-07-03 14:14:11 +00:00

Add stub code to detect VCDs, plus unit test.

This commit is contained in:
King_DuckZ 2016-02-19 21:57:43 +01:00
parent 7da13f6677
commit f31463480f
5 changed files with 179 additions and 16 deletions

View file

@ -28,12 +28,13 @@ namespace mchlib {
ContentType_Backup, ContentType_Backup,
ContentType_VideoDVD, ContentType_VideoDVD,
ContentType_VideoBD, ContentType_VideoBD,
ContentType_VideoCD,
ContentType_Unknown ContentType_Unknown
}; };
template <bool> class SetListingView; template <bool> class SetListingView;
ContentTypes guess_content_type ( dinlib::MediaTypes parMediaType, const SetListingView<true>& parContent ); ContentTypes guess_content_type ( dinlib::MediaTypes parMediaType, const SetListingView<true>& parContent, std::size_t parEntriesCount=0 );
} //namespace mchlib } //namespace mchlib
#endif #endif

View file

@ -61,16 +61,25 @@ namespace mchlib {
template <bool Const> template <bool Const>
inline inline
std::size_t count_listing_items (const SetListingView<Const>& /*parList*/) { std::size_t count_listing_items (const SetListingView<Const>& parList) {
assert(false); return std::count_if(
return 0; parList.cbegin(),
//return std::count_if( parList.cend(),
// parList.cbegin(), [] (const FileRecordData&) {
// parList.cend(), return true;
// [] (const FileRecordData&) { }
// return true; );
// } }
//);
template <bool Const>
inline
std::size_t count_listing_items_recursive (const SetListingView<Const>& parList) {
std::size_t retval = 0;
for (auto it = parList.begin(), itEND = parList.end(); it != itEND; ++it, ++retval) {
if (it->is_directory)
retval += count_listing_items_recursive(SetListingView<Const>(it));
}
return retval;
} }
} //namespace mchlib } //namespace mchlib

View file

@ -18,7 +18,7 @@
#ifndef idF5514EBEE7DA404CA2271A4AE74A28D4 #ifndef idF5514EBEE7DA404CA2271A4AE74A28D4
#define idF5514EBEE7DA404CA2271A4AE74A28D4 #define idF5514EBEE7DA404CA2271A4AE74A28D4
#include "guess_content_type.hpp" #include "dindexer-machinery/guess_content_type.hpp"
#include "dindexer-machinery/set_listing.hpp" #include "dindexer-machinery/set_listing.hpp"
#include "dindexer-machinery/set_listing_helpers.hpp" #include "dindexer-machinery/set_listing_helpers.hpp"
#include <boost/iterator/filter_iterator.hpp> #include <boost/iterator/filter_iterator.hpp>
@ -27,9 +27,12 @@
#include <functional> #include <functional>
#include <ciso646> #include <ciso646>
#include <regex> #include <regex>
#include <utility>
namespace mchlib { namespace mchlib {
namespace { namespace {
using FoundItemPair = std::pair<bool, ConstSetListingView::const_iterator>;
template <typename O, uint16_t L> template <typename O, uint16_t L>
struct IsLevelLikeO { struct IsLevelLikeO {
bool operator() ( const FileRecordData& parEntry ); bool operator() ( const FileRecordData& parEntry );
@ -65,6 +68,29 @@ namespace mchlib {
return (parEntry.path == parPath); return (parEntry.path == parPath);
} }
//std::vector<int> check_missing_content (const ConstSetListingView& parContent, const std::vector<const char*>& parCheck) {
// std::vector<int> retval;
// for (int z = 0; z < static_cast<int>(parCheck.size()), ++z) {
// auto glob_range = glob(parContent, parCheck[z]);
// if (boost::empty(glob_range)) {
// retval.push_back(z);
// }
// }
// return std::move(retval);
//}
FoundItemPair find_item (const ConstSetListingView& parContent, const char* parPath) {
auto it = std::find_if(
parContent.begin(),
parContent.end(),
[parPath](const FileRecordData& parEntry) {
return (parEntry.path == parPath);
}
);
return std::make_pair(parContent.end() != it, it);
}
bool identify_video_dvd (dinlib::MediaTypes parMediaType, const ConstSetListingView& parContent) { bool identify_video_dvd (dinlib::MediaTypes parMediaType, const ConstSetListingView& parContent) {
if (parMediaType != dinlib::MediaType_DVD) { if (parMediaType != dinlib::MediaType_DVD) {
return false; return false;
@ -87,15 +113,57 @@ namespace mchlib {
return true; return true;
} }
bool identify_video_cd (dinlib::MediaTypes parMediaType, const ConstSetListingView& parContent) {
if (parMediaType != dinlib::MediaType_CDRom)
return false;
const auto items_count = count_listing_items(parContent);
if (items_count < 4)
return false;
//const std::vector<const char*> should_have {
// "SVCD/*.VCD",
// "MPEGAV/AVSEQ??.DAT",
// "SEGMENT/ITEM???.DAT",
// "CDI"
//};
auto found = find_item(parContent, "SVCD");
if (not found.first or not found.second->is_directory)
return false;
found = find_item(parContent, "MPEGAV");
if (not found.first or not found.second->is_directory)
return false;
found = find_item(parContent, "SEGMENT");
if (not found.first or not found.second->is_directory)
return false;
found = find_item(parContent, "CDI");
if (not found.first or not found.second->is_directory)
return false;
//FileRecordData("SVCD",0,0,1,true,false),
//FileRecordData("SVCD/INFO.VCD",0,0,2,false,false),
//FileRecordData("SVCD/ENTRIES.VCD",0,0,2,false,false),
//FileRecordData("SVCD/SEARCH.DAT",0,0,2,false,false),
//FileRecordData("SVCD/PSD.VCD",0,0,2,false,false),
//FileRecordData("MPEGAV",0,0,1,true,false),
//FileRecordData("MPEGAV/AVSEQ01.DAT",0,0,2,false,false),
//FileRecordData("SEGMENT",0,0,1,true,false),
//FileRecordData("SEGMENT/ITEM001.DAT",0,0,2,false,false),
//FileRecordData("CDI",0,0,1,true,false),
//FileRecordData("KARAOKE",0,0,1,true,false)
return true;
}
} //unnamed namespace } //unnamed namespace
ContentTypes guess_content_type (dinlib::MediaTypes parMediaType, const ConstSetListingView& parContent) { ContentTypes guess_content_type (dinlib::MediaTypes parMediaType, const ConstSetListingView& parContent, std::size_t parEntriesCount) {
std::vector<EntryChecking> checker_chain { std::vector<EntryChecking> checker_chain {
{ 100, &identify_video_dvd, ContentType_VideoDVD } { 100, &identify_video_dvd, ContentType_VideoDVD },
{ 200, &identify_video_cd, ContentType_VideoCD }
}; };
assert(false); const auto total_entries = (parEntriesCount ? parEntriesCount : count_listing_items_recursive(parContent));
const auto total_entries = count_listing_items_recursive(parContent);
for (const auto& chk : checker_chain) { for (const auto& chk : checker_chain) {
if (chk.max_total_entries and chk.max_total_entries >= total_entries) { if (chk.max_total_entries and chk.max_total_entries >= total_entries) {

View file

@ -2,6 +2,7 @@ project(${bare_name}-test CXX)
add_executable(${PROJECT_NAME} add_executable(${PROJECT_NAME}
test_diriterator.cpp test_diriterator.cpp
test_guess_content_type.cpp
) )
target_include_directories(${PROJECT_NAME} SYSTEM target_include_directories(${PROJECT_NAME} SYSTEM

View file

@ -0,0 +1,84 @@
/* Copyright 2015, 2016, Michele Santullo
* This file is part of "dindexer".
*
* "dindexer" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* "dindexer" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>.
*/
#include "dindexer-machinery/guess_content_type.hpp"
#include "dindexer-machinery/set_listing.hpp"
#include <gtest/gtest.h>
#include <cstddef>
#include <vector>
namespace {
template <std::size_t N>
void detect_type (mchlib::FileRecordData (&parTestData)[N], mchlib::ContentTypes parExpected, dinlib::MediaTypes parMediaType) {
using mchlib::SetListing;
using mchlib::FileRecordData;
std::vector<FileRecordData> test_data(
std::make_move_iterator(std::begin(parTestData)),
std::make_move_iterator(std::end(parTestData))
);
SetListing dvd_listing(std::move(test_data));
const mchlib::ContentTypes detected_type =
guess_content_type(parMediaType, dvd_listing.make_cview());
EXPECT_EQ(parExpected, detected_type);
}
} //unnamed namespace
TEST(machinery, guess_content_type) {
using mchlib::FileRecordData;
{
FileRecordData test_data[] = {
FileRecordData("",0,0,0,true,false),
FileRecordData("VIDEO_TS",0,0,1,true,false),
FileRecordData("AUDIO_TS",0,0,1,true,false),
FileRecordData("VIDEO_TS/VTS_01_0.BUP",0,0,2,false,false)
};
detect_type(test_data, mchlib::ContentType_VideoDVD, dinlib::MediaType_DVD);
}
{
FileRecordData test_data[] = {
FileRecordData("",0,0,0,true,false),
FileRecordData("dummy",0,0,1,true,false),
FileRecordData("another_dir",0,0,1,true,false),
FileRecordData("some_file.bin",0,0,1,false,false),
FileRecordData("another_dir/VTS_01_0.BUP",0,0,2,false,false)
};
detect_type(test_data, mchlib::ContentType_Generic, dinlib::MediaType_Directory);
}
{
FileRecordData test_data[] = {
FileRecordData("",0,0,0,true,false),
FileRecordData("SVCD",0,0,1,true,false),
FileRecordData("SVCD/INFO.VCD",0,0,2,false,false),
FileRecordData("SVCD/ENTRIES.VCD",0,0,2,false,false),
FileRecordData("SVCD/SEARCH.DAT",0,0,2,false,false),
FileRecordData("SVCD/PSD.VCD",0,0,2,false,false),
FileRecordData("MPEGAV",0,0,1,true,false),
FileRecordData("MPEGAV/AVSEQ01.DAT",0,0,2,false,false),
FileRecordData("SEGMENT",0,0,1,true,false),
FileRecordData("SEGMENT/ITEM001.DAT",0,0,2,false,false),
FileRecordData("CDI",0,0,1,true,false),
FileRecordData("KARAOKE",0,0,1,true,false)
};
detect_type(test_data, mchlib::ContentType_VideoCD, dinlib::MediaType_CDRom);
}
}