1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2024-11-25 00:53:43 +00:00

Implement MediaType scan task.

This commit is contained in:
King_DuckZ 2016-03-03 21:31:33 +01:00
parent 5b3e15c45f
commit 6ddf79fad9
5 changed files with 114 additions and 1 deletions

View file

@ -0,0 +1,45 @@
/* 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/>.
*/
#ifndef id25B0BCA6D9464754920E1BC7C5D9DB57
#define id25B0BCA6D9464754920E1BC7C5D9DB57
#include "dindexer-machinery/scantask/base.hpp"
#include "dindexer-common/mediatypes.hpp"
#include <string>
namespace mchlib {
namespace scantask {
class MediaType : Base<dinlib::MediaTypes> {
public:
MediaType ( char parDefault, bool parForce, std::string parSearchPath );
virtual ~MediaType ( void ) noexcept = default;
private:
virtual void on_data_destroy ( dinlib::MediaTypes& parData );
virtual void on_data_create ( dinlib::MediaTypes& parData );
dinlib::MediaTypes m_default;
#if defined(WITH_MEDIA_AUTODETECT)
std::string m_search_path;
bool m_force;
#endif
};
} //namespace scantask
} //namespace mchlib
#endif

View file

@ -25,3 +25,10 @@ target_link_libraries(${PROJECT_NAME}
# RUNTIME DESTINATION bin
# ARCHIVE DESTINATION lib/static
#)
#Allow to link with .so
#see https://cmake.org/pipermail/cmake/2007-May/014350.html
#and http://stackoverflow.com/questions/6093547/what-do-r-x86-64-32s-and-r-x86-64-64-relocation-mean/6093910#6093910
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" )
set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "-fPIC")
endif()

View file

@ -16,6 +16,7 @@ add_library(${PROJECT_NAME} SHARED
set_listing.cpp
globbing.cpp
scantask/dirtree.cpp
scantask/mediatype.cpp
)
#target_include_directories(${PROJECT_NAME}
@ -27,6 +28,7 @@ target_include_directories(${PROJECT_NAME}
target_link_libraries(${PROJECT_NAME}
PRIVATE ${bare_name}-if
PRIVATE ${MAGIC_LIBRARIES}
PUBLIC ${bare_name}-common
)
target_include_directories(${PROJECT_NAME}

View file

@ -0,0 +1,58 @@
/* 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/scantask/mediatype.hpp"
//#include "dindexer-machinery/guess_content_type.hpp"
#if defined(WITH_MEDIA_AUTODETECT)
# include "dindexer-machinery/mediatype.hpp"
#endif
#include <utility>
namespace mchlib {
namespace scantask {
MediaType::MediaType (char parDefault, bool parForce, std::string parSearchPath) :
m_default(dinlib::char_to_media_type(parDefault))
#if defined(WITH_MEDIA_AUTODETECT)
, m_search_path(std::move(parSearchPath))
, m_force(parForce)
#endif
{
#if !defined(WITH_MEDIA_AUTODETECT)
static_cast<void>(parForce);
static_cast<void>(parSearchPath);
#endif
}
void MediaType::on_data_destroy (dinlib::MediaTypes& parData) {
parData = dinlib::MediaType_Other;
}
void MediaType::on_data_create (dinlib::MediaTypes& parData) {
#if defined(WITH_MEDIA_AUTODETECT)
if (m_force) {
parData = m_default;
}
else {
const auto guessed_type = mchlib::guess_media_type(std::string(m_search_path));
parData = guessed_type;
}
#else
parData = m_default;
#endif
}
} //namespace scantask
} //namespace mchlib

View file

@ -24,10 +24,10 @@
#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 "dindexer-machinery/scantask/dirtree.hpp"
#include "dindexer-machinery/scantask/mediatype.hpp"
#include <iostream>
#include <iomanip>
#include <ciso646>
@ -77,6 +77,7 @@ int main (int parArgc, char* parArgv[]) {
const std::string search_path(vm["search-path"].as<std::string>());
mchlib::scantask::DirTree scan_dirtree(search_path);
mchlib::scantask::MediaType media_type(vm["type"].as<char>(), not vm.count("type"), search_path);
#if defined(WITH_MEDIA_AUTODETECT)
//char set_type;