- 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)

This commit is contained in:
Alfred Reynolds
2021-08-27 15:30:45 +12:00
parent 1211a93b64
commit 0c9721976b
7 changed files with 4 additions and 162 deletions

View File

@@ -70,7 +70,7 @@ The file format is:
"scheduler" : [ "scheduler" : [
{ {
"exclusive" : true, "exclusive" : true,
"redditrss" : "https://www.reddit.com/r/earthporn/.rss?limit=100", "path" : "/path/to/pictures/reddit_sync"
"stretch" : true, "stretch" : true,
"times": [ "times": [
{ {
@@ -115,12 +115,11 @@ Supported keys and values in the JSON configuration are:
* `opacity` : the same as the command line `-o` argument * `opacity` : the same as the command line `-o` argument
* `blur` : the same as the command line `-b` argument * `blur` : the same as the command line `-b` argument
* `debug` : set to true to enable verbose output from the program * `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. * `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. * `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 * `path` : the path to image files
* `stretch` : as above * `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 ## 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: 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:

View File

@@ -178,10 +178,6 @@ QVector<PathEntry> parsePathEntry(QJsonObject &jsonMainDoc, bool baseRecursive,
if(!imageListString.empty()) { if(!imageListString.empty()) {
entry.imageList = imageListString; entry.imageList = imageListString;
} }
std::string rssFeedURLString = ParseJSONString(schedulerJson, "redditrss");
if(!rssFeedURLString.empty()) {
entry.rssFeedURL = rssFeedURLString;
}
SetJSONBool(entry.exclusive, schedulerJson, "exclusive"); SetJSONBool(entry.exclusive, schedulerJson, "exclusive");
@@ -260,11 +256,6 @@ AppConfig loadAppConfiguration(const AppConfig &commandLineConfig) {
{ {
entry.imageList = imageListString; entry.imageList = imageListString;
} }
std::string rssFeedURLString = ParseJSONString(jsonDoc, "redditrss");
if(!rssFeedURLString.empty())
{
entry.rssFeedURL = rssFeedURLString;
}
loadedConfig.paths.append(entry); loadedConfig.paths.append(entry);
} }
loadedConfig.configPath = commandLineConfig.configPath; loadedConfig.configPath = commandLineConfig.configPath;

View File

@@ -18,7 +18,6 @@ struct Config {
struct PathEntry { struct PathEntry {
std::string path = ""; std::string path = "";
std::string imageList = ""; std::string imageList = "";
std::string rssFeedURL = "";
bool exclusive = false; // only use this entry when it is valid, skip others bool exclusive = false; // only use this entry when it is valid, skip others
bool recursive = false; bool recursive = false;
@@ -38,7 +37,7 @@ struct PathEntry {
return true; return true;
if(b.baseDisplayOptions.fitAspectAxisToWindow != baseDisplayOptions.fitAspectAxisToWindow) if(b.baseDisplayOptions.fitAspectAxisToWindow != baseDisplayOptions.fitAspectAxisToWindow)
return true; return true;
if (b.path != path || b.imageList != imageList || b.rssFeedURL != rssFeedURL) if (b.path != path || b.imageList != imageList)
return true; return true;
if (b.baseDisplayOptions.timeWindows.count() != baseDisplayOptions.timeWindows.count()) if (b.baseDisplayOptions.timeWindows.count() != baseDisplayOptions.timeWindows.count())
return true; return true;

View File

@@ -142,9 +142,6 @@ bool ImageSelector::imageInsideTimeWindow(const QVector<DisplayTimeWindow> &time
bool ImageSelector::imageMatchesFilter(const ImageDetails& imageDetails) 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()))) if(!QFileInfo::exists(QString(imageDetails.filename.c_str())))
{ {
Log("file not found: ", imageDetails.filename); Log("file not found: ", imageDetails.filename);

View File

@@ -131,11 +131,7 @@ void ConfigureWindowFromSettings(MainWindow &w, const AppConfig &appConfig)
std::unique_ptr<ImageSelector> GetSelectorForConfig(const PathEntry& path, QNetworkAccessManager& networkManagerIn) std::unique_ptr<ImageSelector> GetSelectorForConfig(const PathEntry& path, QNetworkAccessManager& networkManagerIn)
{ {
std::unique_ptr<PathTraverser> pathTraverser; std::unique_ptr<PathTraverser> pathTraverser;
if (!path.rssFeedURL.empty()) if (!path.imageList.empty())
{
pathTraverser = std::unique_ptr<PathTraverser>(new RedditRSSFeedPathTraverser(path.rssFeedURL, networkManagerIn));
}
else if (!path.imageList.empty())
{ {
pathTraverser = std::unique_ptr<PathTraverser>(new ImageListPathTraverser(path.imageList)); pathTraverser = std::unique_ptr<PathTraverser>(new ImageListPathTraverser(path.imageList));
} }

View File

@@ -114,120 +114,3 @@ ImageDisplayOptions ImageListPathTraverser::UpdateOptionsForImage(const std::str
return baseOptions; 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<RedditRSSFeedPathTraverser *>(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;
}

View File

@@ -60,27 +60,4 @@ class ImageListPathTraverser : public PathTraverser
private: private:
QStringList imageList; 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 #endif // PATHTRAVERSER_H