diff options
author | horchi <vdr@jwendel.de> | 2020-02-15 10:55:30 +0100 |
---|---|---|
committer | horchi <vdr@jwendel.de> | 2020-02-15 10:55:30 +0100 |
commit | 2387a5893be264e59e60a8f9e1c302c53b791128 (patch) | |
tree | d4d83be2ffac24eebd07af5a8854e41a592ab539 | |
parent | dddd5c42b27d936f22468f95e3da0a776451dbb7 (diff) | |
download | vdr-plugin-epg2vdr-2387a5893be264e59e60a8f9e1c302c53b791128.tar.gz vdr-plugin-epg2vdr-2387a5893be264e59e60a8f9e1c302c53b791128.tar.bz2 |
2020-02-14: version 1.1.107 (horchi,seahawk1986)\n - bugfix: Fixed cleanup of image links\n - change: Improved cleanup spead for images and links\n - bugfix: Fixed time handling for timers without event\n\n1.1.107
-rw-r--r-- | HISTORY.h | 9 | ||||
-rw-r--r-- | lib/common.c | 7 | ||||
-rw-r--r-- | lib/common.h | 1 | ||||
-rw-r--r-- | menu.h | 7 | ||||
-rw-r--r-- | ttools.c | 7 | ||||
-rw-r--r-- | update.c | 152 | ||||
-rw-r--r-- | update.h | 2 |
7 files changed, 99 insertions, 86 deletions
@@ -5,8 +5,8 @@ * */ -#define _VERSION "1.1.106" -#define VERSION_DATE "23.12.2019" +#define _VERSION "1.1.107" +#define VERSION_DATE "14.02.2020" #define DB_API 7 @@ -19,6 +19,11 @@ /* * ------------------------------------ +2020-02-14: version 1.1.107 (horchi,seahawk1986) + - bugfix: Fixed cleanup of image links + - change: Improved cleanup spead for images and links + - bugfix: Fixed time handling for timers without event + 2019-12-23: version 1.1.106 (horchi) - change: Perform timer job also if eppgd busy diff --git a/lib/common.c b/lib/common.c index a452b23..e6bafae 100644 --- a/lib/common.c +++ b/lib/common.c @@ -672,6 +672,11 @@ int l2hhmm(time_t t) return tm.tm_hour * 100 + tm.tm_min; } +time_t hhmm2L(int hhmm, time_t offset) +{ + return ((hhmm/100) * tmeSecondsPerHour) + ((hhmm%100) * tmeSecondsPerMinute) + offset; +} + //*************************************************************************** // HHMM to Pretty Time //*************************************************************************** @@ -977,7 +982,6 @@ int removeFile(const char* filename) if (unlink(filename) != 0) { tell(0, "Can't remove file '%s', '%s'", filename, strerror(errno)); - return 1; } @@ -1027,6 +1031,7 @@ xsltStylesheetPtr loadXSLT(const char* name, const char* path, int utf8) tell(0, "Info: Stylesheet '%s' loaded", xsltfile); free(xsltfile); + return stylesheet; } #endif diff --git a/lib/common.h b/lib/common.h index c8361ec..27c1772 100644 --- a/lib/common.h +++ b/lib/common.h @@ -292,6 +292,7 @@ const char* toWeekdayName(uint day); time_t hhmmOf(time_t t); int l2hhmm(time_t t); std::string hhmm2pTime(int hhmm); +time_t hhmm2L(int hhmm, time_t offset = 0); time_t midnightOf(time_t t); std::string l2pTime(time_t t, const char* format = "%d.%m.%Y %T"); std::string l2pDate(time_t t); @@ -5,8 +5,7 @@ * */ -#ifndef __EPG2VDR_MENU_H -#define __EPG2VDR_MENU_H +#pragma once #include <vdr/osdbase.h> #include <vdr/menuitems.h> @@ -549,7 +548,3 @@ class cMenuEpgMatchRecordings : public cOsdMenu virtual ~cMenuEpgMatchRecordings() {}; virtual eOSState ProcessKey(eKeys Key); }; - -//*************************************************************************** - -#endif // __EPG2VDR_MENU_H @@ -329,10 +329,13 @@ int updateRowByTimer(cDbRow* timerRow, const cTimer* t) contentOfTag(t, "directory", directory, 512); contentOfTag(t, "source", source, 40); + time_t startTime = hhmm2L(t->Start(), t->Day()); + time_t endTime = hhmm2L(t->Stop(), t->Day() + t->Stop() < t->Start() ? tmeSecondsPerDay : 0); + timerRow->setValue("VDRUUID", Epg2VdrConfig.uuid); timerRow->setValue("EVENTID", t->Event() ? (long)t->Event()->EventID() : 0); - timerRow->setValue("_STARTTIME", t->Event() ? t->Event()->StartTime() : 0); - timerRow->setValue("_ENDTIME", t->Event() ? t->StopTime() : 0); + timerRow->setValue("_STARTTIME", startTime); + timerRow->setValue("_ENDTIME", endTime); timerRow->setValue("CHANNELID", channelId); timerRow->setValue("DAY", t->Day()); timerRow->setValue("STARTTIME", t->Start()); @@ -6,6 +6,7 @@ */ #include <locale.h> +#include <unordered_set> #include <vdr/videodir.h> #include <vdr/tools.h> @@ -506,6 +507,22 @@ int cUpdate::initDb() status += selectEventById->prepare(); + // select all active events + + selectAllEvents = new cDbStatement(useeventsDb); + + // select * from eventsview + // where useid = ? + // and updflg in (.....) + + selectAllEvents->build("select "); + selectAllEvents->bind("USEID", cDBS::bndOut); + selectAllEvents->build(" from %s where ", useeventsDb->TableName()); + selectAllEvents->build("%s in (%s)", + useeventsDb->getField("UPDFLG")->getDbName(), Us::getNeeded()); + + status += selectAllEvents->prepare(); + // ... // select stream, type, lang, description @@ -790,6 +807,7 @@ int cUpdate::exitDb() delete selectAllImages; selectAllImages = 0; delete selectUpdEvents; selectUpdEvents = 0; delete selectEventById; selectEventById = 0; + delete selectAllEvents; selectAllEvents = 0; delete selectAllChannels; selectAllChannels = 0; delete selectChannelById; selectChannelById = 0; delete markUnknownChannel; markUnknownChannel = 0; @@ -1363,7 +1381,7 @@ void cUpdate::Action() if (Epg2VdrConfig.shareInWeb) { - // update timer + // update timer - even when epgd is busy! if (dbConnected() && timerTableUpdateTriggered) updateTimerTable(); @@ -2001,12 +2019,12 @@ int cUpdate::storePicturesToFs() int cUpdate::cleanupPictures() { - const char* ext = ".jpg"; - struct dirent* dirent; - DIR* dir; - char* pdir; - int iCount = 0; - int lCount = 0; + const char* ext {".jpg"}; + struct dirent* dirent {nullptr}; + DIR* dir {nullptr}; + char* pdir {nullptr}; + int iCount {0}; + int lCount {0}; imageRefDb->countWhere("", iCount); @@ -2016,27 +2034,11 @@ int cUpdate::cleanupPictures() return done; } - // ----------------------- - // remove unused images - tell(1, "Starting cleanup of images in '%s'", epgimagedir); // ----------------------- // cleanup 'images' directory - cDbStatement* stmt = new cDbStatement(imageRefDb); - - stmt->build("select "); - stmt->bind("FILEREF", cDBS::bndOut); - stmt->build(" from %s where ", imageRefDb->TableName()); - stmt->bind("IMGNAMEFS", cDBS::bndIn | cDBS::bndSet); - - if (stmt->prepare() != success) - { - delete stmt; - return fail; - } - iCount = 0; // open directory @@ -2047,29 +2049,43 @@ int cUpdate::cleanupPictures() { tell(1, "Can't open directory '%s', '%s'", pdir, strerror(errno)); free(pdir); - return done; } free(pdir); - int cnt = 0; + if (!dbConnected(yes)) + return fail; + + cDbStatement stmt(imageRefDb); + + stmt.build("select "); + stmt.bind("IMGNAMEFS", cDBS::bndOut); + stmt.build(" from %s", imageRefDb->TableName()); + + if (stmt.prepare() != success) + return fail; + + std::unordered_set<std::string> usedRefs; + + imageRefDb->clear(); - while (dbConnected() && (dirent = readdir(dir))) + for (int res = stmt.find(); res; res = stmt.fetch()) + usedRefs.insert(imageRefDb->getStrValue("IMGNAMEFS")); + + stmt.freeResult(); + + while ((dirent = readdir(dir))) { // check extension if (strncmp(dirent->d_name + strlen(dirent->d_name) - strlen(ext), ext, strlen(ext)) != 0) continue; - imageRefDb->clear(); - imageRefDb->setValue("IMGNAMEFS", dirent->d_name); - - if (!stmt->find()) + if (usedRefs.count(dirent->d_name)) { asprintf(&pdir, "%s/images/%s", epgimagedir, dirent->d_name); - - tell(2, "Remove image '%s'", pdir); + tell(2, "Removing image '%s'", pdir); if (!removeFile(pdir)) iCount++; @@ -2077,18 +2093,28 @@ int cUpdate::cleanupPictures() free(pdir); } - cnt++; - stmt->freeResult(); + stmt.freeResult(); } - delete stmt; closedir(dir); - if (!dbConnected(yes)) - return fail; - // ----------------------- - // remove wasted symlinks + // remove unused symlinks + + tell(1, "Cleanup %s symlinks", fullreload ? "all" : "old"); + + std::unordered_set<uint> useIds; + + if (!fullreload) + { + if (!dbConnected(yes)) + return fail; + + for (int res = selectAllEvents->find(); res; res = selectAllEvents->fetch()) + useIds.insert(useeventsDb->getIntValue("USEID")); + + selectAllEvents->freeResult(); + } if (!(dir = opendir(epgimagedir))) { @@ -2096,54 +2122,32 @@ int cUpdate::cleanupPictures() return done; } - tell(1, "Remove %s symlinks", fullreload ? "all" : "old"); - while ((dirent = readdir(dir))) { - // check extension - - if (strncmp(dirent->d_name + strlen(dirent->d_name) - strlen(ext), ext, strlen(ext)) != 0) - continue; - asprintf(&pdir, "%s/%s", epgimagedir, dirent->d_name); - // fileExists use access() which dereference links! - - if (isLink(pdir) && (fullreload || !fileExists(pdir))) + if (isLink(pdir)) { - if (!removeFile(pdir)) - lCount++; + if (fullreload || !fileExists(pdir)) + { + if (!removeFile(pdir)) + lCount++; + } + + else if (useIds.count(atoi(dirent->d_name)) == 0) + { + if (!removeFile(pdir)) + lCount++; + } } free(pdir); } closedir(dir); + tell(1, "Cleanup finished, removed (%d) images and (%d) symlinks", iCount, lCount); return success; } -//*************************************************************************** -// Link Needed -//*************************************************************************** - -int cUpdate::pictureLinkNeeded(const char* linkName) -{ - int found; - - if (!dbConnected()) - return yes; - - // we don't need to patch the linkname "123456_0.jpg" - // since atoi() stops at the first non numerical character ... - - imageRefDb->clear(); - imageRefDb->setValue("LFN", 0L); - imageRefDb->setBigintValue("EVENTID", atol(linkName)); - - found = imageRefDb->find(); - imageRefDb->reset(); - - return found; -} @@ -197,7 +197,6 @@ class cUpdate : public cThread, public cStatus, public cParameters int lookupVdrEventOf(int eId, const char* cId); int storePicturesToFs(); int cleanupPictures(); - int pictureLinkNeeded(const char* linkName); int getOsd2WebPort(); tChannelID toChanID(const char* chanIdStr) @@ -285,6 +284,7 @@ class cUpdate : public cThread, public cStatus, public cParameters cDbStatement* selectMasterVdr; cDbStatement* selectAllImages; cDbStatement* selectUpdEvents; + cDbStatement* selectAllEvents {nullptr}; cDbStatement* selectEventById; cDbStatement* selectAllChannels; cDbStatement* selectChannelById; |