1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2025-08-17 15:19:48 +00:00

Detect content type after scanning and save to DB.

This commit is contained in:
King_DuckZ 2016-02-22 19:44:48 +01:00
parent 2e77e4dc0b
commit 22614432a9
9 changed files with 141 additions and 36 deletions

View file

@ -39,4 +39,8 @@ namespace dinlib {
}
return it_ret->second;
}
MediaTypes char_to_media_type (char parMType) {
return static_cast<MediaTypes>(parMType);
}
} //namespace dinlib

View file

@ -22,6 +22,7 @@
#include "dindexer-machinery/set_listing.hpp"
#include "dindexer-machinery/set_listing_helpers.hpp"
#include "globbing.hpp"
#include "pathname.hpp"
#include <boost/iterator/filter_iterator.hpp>
#include <boost/iterator/indirect_iterator.hpp>
#include <boost/range/empty.hpp>
@ -31,6 +32,7 @@
#include <ciso646>
#include <regex>
#include <utility>
#include <memory>
namespace mchlib {
namespace {
@ -120,6 +122,9 @@ namespace mchlib {
} //unnamed namespace
ContentTypes guess_content_type (dinlib::MediaTypes parMediaType, const ConstSetListingView& parContent, std::size_t parEntriesCount) {
if (boost::empty(parContent))
return ContentType_Empty;
std::vector<EntryChecking> checker_chain {
{ 100, &identify_video_dvd, ContentType_VideoDVD },
{ 200, &identify_video_cd, ContentType_VideoCD }
@ -137,6 +142,24 @@ namespace mchlib {
}
return ContentType_Generic;
}
ContentTypes guess_content_type (dinlib::MediaTypes parMediaType, const std::vector<FileRecordData>& parContent) {
if (parContent.empty())
return ContentType_Empty;
//TODO: assert that the first item in the list is the shortest string
std::shared_ptr<PathName> pathname(new PathName(parContent.front().abs_path));
ConstSetListingView view(parContent.begin(), parContent.end(), pathname->atom_count(), pathname);
return guess_content_type(parMediaType, view, parContent.size());
}
char content_type_to_char (mchlib::ContentTypes parCType) {
return static_cast<char>(parCType);
}
ContentTypes char_to_content_type (char parCType) {
return static_cast<ContentTypes>(parCType);
}
} //namespace mchlib
#endif

View file

@ -97,11 +97,13 @@ namespace din {
uint32_t new_group_id;
{
auto id_res = conn.query("INSERT INTO \"sets\" "
"(\"desc\",\"type\",\"app_name\") "
"VALUES ($1, $2, $3) RETURNING \"id\";",
"(\"desc\",\"type\",\"app_name\""
",\"content_type\") "
"VALUES ($1, $2, $3, $4) RETURNING \"id\";",
parSetData.name,
std::string(1, parSetData.type),
parSignature
boost::string_ref(&parSetData.type, 1),
parSignature,
boost::string_ref(&parSetData.content_type, 1)
);
assert(id_res.size() == 1);
assert(id_res[0].size() == 1);

View file

@ -26,6 +26,7 @@
#include "dindexer-machinery/machinery_info.hpp"
#include "dindexer-common/common_info.hpp"
#include "dindexer-common/settings.hpp"
#include "dindexer-machinery/guess_content_type.hpp"
#include "commandline.hpp"
#include "dbbackend.hpp"
#include <iostream>
@ -42,7 +43,7 @@
namespace {
void run_hash_calculation ( mchlib::Indexer& parIndexer, bool parShowProgress );
bool add_to_db ( const std::vector<mchlib::FileRecordData>& parData, const std::string& parSetName, char parType, const dinlib::SettingsDB& parDBSettings, bool parForce=false );
bool add_to_db ( const std::vector<mchlib::FileRecordData>& parData, const std::string& parSetName, char parType, char parContent, const dinlib::SettingsDB& parDBSettings, bool parForce=false );
} //unnamed namespace
int main (int parArgc, char* parArgv[]) {
@ -117,11 +118,15 @@ int main (int parArgc, char* parArgv[]) {
return 1;
}
else {
const auto set_type_casted = dinlib::char_to_media_type(set_type);
const mchlib::ContentTypes content = mchlib::guess_content_type(set_type_casted, indexer.record_data());
const char content_type = mchlib::content_type_to_char(content);
run_hash_calculation(indexer, verbose);
if (verbose) {
std::cout << "Writing to database...\n";
}
if (not add_to_db(indexer.record_data(), vm["setname"].as<std::string>(), set_type, settings.db)) {
if (not add_to_db(indexer.record_data(), vm["setname"].as<std::string>(), set_type, content_type, settings.db)) {
std::cerr << "Not written to DB, likely because a set with the same hash already exists\n";
}
}
@ -182,7 +187,7 @@ namespace {
#endif
}
bool add_to_db (const std::vector<mchlib::FileRecordData>& parData, const std::string& parSetName, char parType, const dinlib::SettingsDB& parDBSettings, bool parForce) {
bool add_to_db (const std::vector<mchlib::FileRecordData>& parData, const std::string& parSetName, char parType, char parContentType, const dinlib::SettingsDB& parDBSettings, bool parForce) {
using mchlib::FileRecordData;
using mchlib::SetRecordDataFull;
using mchlib::SetRecordData;
@ -197,7 +202,7 @@ namespace {
}
}
SetRecordData set_data {parSetName, parType};
SetRecordData set_data {parSetName, parType, parContentType };
const auto app_signature = dinlib::dindexer_signature();
const auto lib_signature = mchlib::lib_signature();
const std::string signature = std::string(app_signature.data(), app_signature.size()) + "/" + std::string(lib_signature.data(), lib_signature.size());