diff --git a/src/gui/epgview.cpp b/src/gui/epgview.cpp index 1a6d6b04f..84bed94b9 100644 --- a/src/gui/epgview.cpp +++ b/src/gui/epgview.cpp @@ -41,6 +41,7 @@ #include "timerlist.h" #include #include +#include #include #include @@ -1220,7 +1221,7 @@ int CEpgData::show(const t_channel_id channel_id, uint64_t a_id, time_t* a_start picname = movie_filename.substr(0, _pos) + ".jpg"; } else - picname = imdb->getFilename(channel, epgData.eventID); + picname = CMDBTools::getInstance()->getFilename(channel, epgData.eventID); CFileHelpers fh; if (!fh.copyFile(imdb->posterfile.c_str(), picname.c_str(), 0644)) diff --git a/src/gui/mdb-imdb.cpp b/src/gui/mdb-imdb.cpp index ffb78fb0d..492ab3045 100644 --- a/src/gui/mdb-imdb.cpp +++ b/src/gui/mdb-imdb.cpp @@ -475,79 +475,6 @@ int CIMDB::getStars() return (int)(atof(imdbRating.c_str()) * 10); } -std::string CIMDB::getFilename(CZapitChannel *channel, uint64_t id) -{ - char fname[512]; // UTF-8 - char buf[256]; - unsigned int pos = 0; - - if (check_dir(g_settings.network_nfs_recordingdir.c_str())) - return (""); - - snprintf(fname, sizeof(fname), "%s/", g_settings.network_nfs_recordingdir.c_str()); - pos = strlen(fname); - - // %C == channel, %T == title, %I == info1, %d == date, %t == time_t - std::string FilenameTemplate = g_settings.recording_filename_template; - if (FilenameTemplate.empty()) - FilenameTemplate = "%C_%T_%d_%t"; - - StringReplace(FilenameTemplate, "%d", ""); - StringReplace(FilenameTemplate, "%t", ""); - StringReplace(FilenameTemplate, "__", "_"); - - std::string channel_name = channel->getName(); - if (!(channel_name.empty())) - { - strcpy(buf, UTF8_TO_FILESYSTEM_ENCODING(channel_name.c_str())); - ZapitTools::replace_char(buf); - StringReplace(FilenameTemplate, "%C", buf); - } - else - StringReplace(FilenameTemplate, "%C", "no_channel"); - - CShortEPGData epgdata; - if (CEitManager::getInstance()->getEPGidShort(id, &epgdata)) - { - if (!(epgdata.title.empty())) - { - strcpy(buf, epgdata.title.c_str()); - ZapitTools::replace_char(buf); - StringReplace(FilenameTemplate, "%T", buf); - } - else - StringReplace(FilenameTemplate, "%T", "no_title"); - - if (!(epgdata.info1.empty())) - { - strcpy(buf, epgdata.info1.c_str()); - ZapitTools::replace_char(buf); - StringReplace(FilenameTemplate, "%I", buf); - } - else - StringReplace(FilenameTemplate, "%I", "no_info"); - } - - strcpy(&(fname[pos]), UTF8_TO_FILESYSTEM_ENCODING(FilenameTemplate.c_str())); - - pos = strlen(fname); - - strcpy(&(fname[pos]), ".jpg"); - - return (fname); -} - -void CIMDB::StringReplace(std::string &str, const std::string search, const std::string rstr) -{ - std::string::size_type ptr = 0; - std::string::size_type pos = 0; - while ((ptr = str.find(search, pos)) != std::string::npos) - { - str.replace(ptr, search.length(), rstr); - pos = ptr + rstr.length(); - } -} - void CIMDB::cleanup() { if (access(search_outfile.c_str(), F_OK) == 0) diff --git a/src/gui/mdb-imdb.h b/src/gui/mdb-imdb.h index 6db940d79..938de530e 100644 --- a/src/gui/mdb-imdb.h +++ b/src/gui/mdb-imdb.h @@ -59,8 +59,6 @@ class CIMDB std::string posterfile; int getMovieDetails(const std::string &epgTitle); - std::string getFilename(CZapitChannel *channel, uint64_t id); - void StringReplace(std::string &str, const std::string search, const std::string rstr); void cleanup(); std::string getPoster() { return posterfile; } diff --git a/src/system/Makefile.am b/src/system/Makefile.am index 300c33317..02caba258 100644 --- a/src/system/Makefile.am +++ b/src/system/Makefile.am @@ -36,6 +36,7 @@ libneutrino_system_a_SOURCES = \ luaserver.cpp \ localize.cpp \ helpers.cpp \ + mdb-tools.cpp \ ping.cpp \ proc_tools.cpp \ settings.cpp \ diff --git a/src/system/mdb-tools.cpp b/src/system/mdb-tools.cpp new file mode 100644 index 000000000..efbcef96d --- /dev/null +++ b/src/system/mdb-tools.cpp @@ -0,0 +1,115 @@ +/* + Movie Database - Tools + + (C) 2009-2016 NG-Team + (C) 2016 NI-Team + + License: GPL + + This program 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 2 of the License, or + (at your option) any later version. + + This program 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 this program. If not, see . + +*/ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include + +#include + +#include +#include +#include + +#include "mdb-tools.h" + +CMDBTools *CMDBTools::getInstance() +{ + static CMDBTools *mdbtools = NULL; + if (!mdbtools) + mdbtools = new CMDBTools(); + return mdbtools; +} + +CMDBTools::CMDBTools() +{ +} + +CMDBTools::~CMDBTools() +{ +} + +std::string CMDBTools::getFilename(CZapitChannel *channel, uint64_t id) +{ + char fname[512]; + char buf[256]; + unsigned int pos = 0; + + if (check_dir(g_settings.network_nfs_recordingdir.c_str())) + return (""); + + snprintf(fname, sizeof(fname), "%s/", g_settings.network_nfs_recordingdir.c_str()); + pos = strlen(fname); + + // %C == channel, %T == title, %I == info1, %d == date, %t == time_t + std::string FilenameTemplate = g_settings.recording_filename_template; + if (FilenameTemplate.empty()) + FilenameTemplate = "%C_%T_%d_%t"; + + FilenameTemplate = str_replace("%d", "", FilenameTemplate); + FilenameTemplate = str_replace("%t", "", FilenameTemplate); + FilenameTemplate = str_replace("__", "_", FilenameTemplate); + + std::string channel_name = channel->getName(); + if (!(channel_name.empty())) + { + strcpy(buf, UTF8_TO_FILESYSTEM_ENCODING(channel_name.c_str())); + ZapitTools::replace_char(buf); + FilenameTemplate = str_replace("%C", buf, FilenameTemplate); + } + else + FilenameTemplate = str_replace("%C", "no_channel", FilenameTemplate); + + CShortEPGData epgdata; + if (CEitManager::getInstance()->getEPGidShort(id, &epgdata)) + { + if (!(epgdata.title.empty())) + { + strcpy(buf, epgdata.title.c_str()); + ZapitTools::replace_char(buf); + FilenameTemplate = str_replace("%T", buf, FilenameTemplate); + } + else + FilenameTemplate = str_replace("%T", "no_title", FilenameTemplate); + + if (!(epgdata.info1.empty())) + { + strcpy(buf, epgdata.info1.c_str()); + ZapitTools::replace_char(buf); + FilenameTemplate = str_replace("%I", buf, FilenameTemplate); + } + else + FilenameTemplate = str_replace("%I", "no_info", FilenameTemplate); + } + + strcpy(&(fname[pos]), UTF8_TO_FILESYSTEM_ENCODING(FilenameTemplate.c_str())); + + pos = strlen(fname); + + strcpy(&(fname[pos]), ".jpg"); + + return (fname); +} diff --git a/src/system/mdb-tools.h b/src/system/mdb-tools.h new file mode 100644 index 000000000..de9087a28 --- /dev/null +++ b/src/system/mdb-tools.h @@ -0,0 +1,39 @@ +/* + Movie Database - Tools + + (C) 2009-2016 NG-Team + (C) 2016 NI-Team + + License: GPL + + This program 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 2 of the License, or + (at your option) any later version. + + This program 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 this program. If not, see . + +*/ + +#ifndef __mdb_tools__ +#define __mdb_tools__ + +class CMDBTools +{ + private: + + public: + CMDBTools(); + ~CMDBTools(); + static CMDBTools *getInstance(); + + std::string getFilename(CZapitChannel *channel, uint64_t id); +}; + +#endif