From 0c9721976b890a51aedb57b8fb03a9821d598192 Mon Sep 17 00:00:00 2001 From: Alfred Reynolds Date: Fri, 27 Aug 2021 15:30:45 +1200 Subject: [PATCH] - remove the reddit rss support. This is better done by a 3rd party downloader to disk (i.e https://github.com/Pomax/reddit-image-catch-up) --- README.md | 5 +- src/appconfig.cpp | 9 ---- src/appconfig.h | 3 +- src/imageselector.cpp | 3 -- src/main.cpp | 6 +-- src/pathtraverser.cpp | 117 ------------------------------------------ src/pathtraverser.h | 23 --------- 7 files changed, 4 insertions(+), 162 deletions(-) diff --git a/README.md b/README.md index 32ed439..18521a5 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ The file format is: "scheduler" : [ { "exclusive" : true, - "redditrss" : "https://www.reddit.com/r/earthporn/.rss?limit=100", + "path" : "/path/to/pictures/reddit_sync" "stretch" : true, "times": [ { @@ -115,12 +115,11 @@ Supported keys and values in the JSON configuration are: * `opacity` : the same as the command line `-o` argument * `blur` : the same as the command line `-b` argument * `debug` : set to true to enable verbose output from the program -* `scheduler` : this entry is an array of possible path values and associated settings. This key lets you manage display times/settings for a collection of paths. In the example above the top entry shows ONLY files from a Redit RSS feed between 2 and 4pm, ONLY files from the `show_peak_times` folder from 8am to 10am and then 4pm to 7pm. At all other times it alternates displaying files in the `always_show_1` and `always_show_2` folder. +* `scheduler` : this entry is an array of possible path values and associated settings. This key lets you manage display times/settings for a collection of paths. In the example above the top entry shows ONLY files from a Redit feed between 2 and 4pm, ONLY files from the `show_peak_times` folder from 8am to 10am and then 4pm to 7pm. At all other times it alternates displaying files in the `always_show_1` and `always_show_2` folder. * `exclusive` : When set to `true` only this entry will be used when it is in its valid time window. * `times` : times is a JSON array of start and end times in which it is valid to display this image. The time is in the format HH:MM:SS and is based on the systems local time. If `start` isn't defined then it defaults to the start of the day, if `end` isn't defined it defaults to the end of the day. * `path` : the path to image files * `stretch` : as above - * `redditrss` : the path to a ReditRSS feed from which images will be selected. This is designed for the EarthPorn page and others like it and is highly dependent on the Redit RSS syntax. ## Folder Options file When using the default or recursive folder mode we support having per folder display options. The options are stored in a file called "options.json" in the images folder and support a subset of the applications configuration settings: diff --git a/src/appconfig.cpp b/src/appconfig.cpp index b424fee..f495870 100644 --- a/src/appconfig.cpp +++ b/src/appconfig.cpp @@ -178,10 +178,6 @@ QVector parsePathEntry(QJsonObject &jsonMainDoc, bool baseRecursive, if(!imageListString.empty()) { entry.imageList = imageListString; } - std::string rssFeedURLString = ParseJSONString(schedulerJson, "redditrss"); - if(!rssFeedURLString.empty()) { - entry.rssFeedURL = rssFeedURLString; - } SetJSONBool(entry.exclusive, schedulerJson, "exclusive"); @@ -260,11 +256,6 @@ AppConfig loadAppConfiguration(const AppConfig &commandLineConfig) { { entry.imageList = imageListString; } - std::string rssFeedURLString = ParseJSONString(jsonDoc, "redditrss"); - if(!rssFeedURLString.empty()) - { - entry.rssFeedURL = rssFeedURLString; - } loadedConfig.paths.append(entry); } loadedConfig.configPath = commandLineConfig.configPath; diff --git a/src/appconfig.h b/src/appconfig.h index c8e7d8e..c219434 100644 --- a/src/appconfig.h +++ b/src/appconfig.h @@ -18,7 +18,6 @@ struct Config { struct PathEntry { std::string path = ""; std::string imageList = ""; - std::string rssFeedURL = ""; bool exclusive = false; // only use this entry when it is valid, skip others bool recursive = false; @@ -38,7 +37,7 @@ struct PathEntry { return true; if(b.baseDisplayOptions.fitAspectAxisToWindow != baseDisplayOptions.fitAspectAxisToWindow) return true; - if (b.path != path || b.imageList != imageList || b.rssFeedURL != rssFeedURL) + if (b.path != path || b.imageList != imageList) return true; if (b.baseDisplayOptions.timeWindows.count() != baseDisplayOptions.timeWindows.count()) return true; diff --git a/src/imageselector.cpp b/src/imageselector.cpp index a4561b6..0613470 100644 --- a/src/imageselector.cpp +++ b/src/imageselector.cpp @@ -142,9 +142,6 @@ bool ImageSelector::imageInsideTimeWindow(const QVector &time bool ImageSelector::imageMatchesFilter(const ImageDetails& imageDetails) { - if(imageDetails.filename.find("https://") != std::string::npos) - return imageInsideTimeWindow(imageDetails.options.timeWindows); - if(!QFileInfo::exists(QString(imageDetails.filename.c_str()))) { Log("file not found: ", imageDetails.filename); diff --git a/src/main.cpp b/src/main.cpp index 3c55790..e3cac1f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -131,11 +131,7 @@ void ConfigureWindowFromSettings(MainWindow &w, const AppConfig &appConfig) std::unique_ptr GetSelectorForConfig(const PathEntry& path, QNetworkAccessManager& networkManagerIn) { std::unique_ptr pathTraverser; - if (!path.rssFeedURL.empty()) - { - pathTraverser = std::unique_ptr(new RedditRSSFeedPathTraverser(path.rssFeedURL, networkManagerIn)); - } - else if (!path.imageList.empty()) + if (!path.imageList.empty()) { pathTraverser = std::unique_ptr(new ImageListPathTraverser(path.imageList)); } diff --git a/src/pathtraverser.cpp b/src/pathtraverser.cpp index 3ad6fc4..1be7974 100644 --- a/src/pathtraverser.cpp +++ b/src/pathtraverser.cpp @@ -114,120 +114,3 @@ ImageDisplayOptions ImageListPathTraverser::UpdateOptionsForImage(const std::str return baseOptions; } - -RedditRSSFeedPathTraverser::RedditRSSFeedPathTraverser(const std::string& rssFeedURLIn, QNetworkAccessManager& networkManager) : - PathTraverser(""), rssFeedURL(rssFeedURLIn), webCtrl(networkManager) -{ - connect( &webCtrl, SIGNAL (finished(QNetworkReply*)), this, SLOT (fileDownloaded(QNetworkReply*))); - RequestRSSFeed(); -} - -RedditRSSFeedPathTraverser::~RedditRSSFeedPathTraverser() -{ -} - -void RedditRSSFeedPathTraverser::RequestRSSFeed() -{ - if (pendingReply) - { - pendingReply->abort(); - } - Log("Requesting RSS feed:", rssFeedURL); - rssRequestedTime = QDateTime::currentDateTime(); - QNetworkRequest request(QUrl(rssFeedURL.c_str())); - pendingReply = webCtrl.get(request); -} - -void RedditRSSFeedPathTraverser::fileDownloaded(QNetworkReply* netReply) -{ - if (netReply != pendingReply) - return; - - pendingReply = nullptr; - - QNetworkReply::NetworkError err = netReply->error(); - if (err != QNetworkReply::NoError) - { - std::cout << "Failed to load Reddit RSS URL: " << err << std::endl; - return; - } - - QString str (netReply->readAll()); - QVariant vt = netReply->attribute(QNetworkRequest::RedirectionTargetAttribute); - netReply->deleteLater(); - if (!vt.isNull()) - { - Log("Redirected to:", vt.toUrl().toString().toStdString()); - webCtrl.get(QNetworkRequest(vt.toUrl())); - } - else - { - QDomDocument doc; - QString error; - if (!doc.setContent(str, false, &error)) - { - Log("Failed to load page:", error.toStdString()); - } - else - { - QDomElement docElem = doc.documentElement(); - QDomNodeList nodeList = docElem.elementsByTagName("entry"); - for (int iEntry = 0; iEntry < nodeList.length(); ++iEntry) - { - QDomNode node = nodeList.item(iEntry); - QDomElement e = node.toElement(); - QDomNode contentNode = e.elementsByTagName("content").item(0).firstChild(); - QDomDocument docContent; - if (!docContent.setContent(contentNode.nodeValue(), false, &error)) - { - continue; - } - - QDomNodeList addressEntries = docContent.documentElement().elementsByTagName("a"); - for (int iAddr = 0; iAddr < addressEntries.length(); ++iAddr) - { - QDomNode node = addressEntries.item(iAddr); - /*QString output; - QTextStream stream(&output); - node.save(stream, 0); - qDebug() << "nodeValue: " << output;*/ - if (node.toElement().text() == "[link]" && node.hasAttributes() ) - { - QDomAttr a = node.toElement().attributeNode("href"); - // check if the URL matches one of our supported formats - for ( const QString& format : supportedFormats ) - { - if (a.value().endsWith(format)) - { - imageURLS.append(a.value()); - } - } - } - } - } - } - } -} - - -QStringList RedditRSSFeedPathTraverser::getImages() const -{ - // refresh the feed after 5 hours - if (rssRequestedTime.secsTo(QDateTime::currentDateTime()) > 60*60*5 ) - { - const_cast(this)->RequestRSSFeed(); - } - return imageURLS; -} - -const std::string RedditRSSFeedPathTraverser::getImagePath(const std::string image) const -{ - return image; -} - -ImageDisplayOptions RedditRSSFeedPathTraverser::UpdateOptionsForImage(const std::string& filename, const ImageDisplayOptions& baseOptions) const -{ - // no per file options modification supported - Q_UNUSED(filename); - return baseOptions; -} diff --git a/src/pathtraverser.h b/src/pathtraverser.h index ef65ead..c018081 100644 --- a/src/pathtraverser.h +++ b/src/pathtraverser.h @@ -60,27 +60,4 @@ class ImageListPathTraverser : public PathTraverser private: QStringList imageList; }; - -class RedditRSSFeedPathTraverser: public QObject, public PathTraverser -{ - Q_OBJECT - public: - RedditRSSFeedPathTraverser(const std::string& rSSFeedURL,QNetworkAccessManager& networkManager); - virtual ~RedditRSSFeedPathTraverser(); - - virtual QStringList getImages() const; - virtual const std::string getImagePath(const std::string image) const; - virtual ImageDisplayOptions UpdateOptionsForImage(const std::string& filename, const ImageDisplayOptions& baseOptions) const; - - private slots: - void fileDownloaded(QNetworkReply* pReply); - private: - void RequestRSSFeed(); - std::string rssFeedURL; - QStringList imageURLS; - QNetworkAccessManager& webCtrl; - QNetworkReply *pendingReply = nullptr; - QDateTime rssRequestedTime; -}; - #endif // PATHTRAVERSER_H