- 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

@@ -178,10 +178,6 @@ QVector<PathEntry> 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;

View File

@@ -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;

View File

@@ -142,9 +142,6 @@ bool ImageSelector::imageInsideTimeWindow(const QVector<DisplayTimeWindow> &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);

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<PathTraverser> pathTraverser;
if (!path.rssFeedURL.empty())
{
pathTraverser = std::unique_ptr<PathTraverser>(new RedditRSSFeedPathTraverser(path.rssFeedURL, networkManagerIn));
}
else if (!path.imageList.empty())
if (!path.imageList.empty())
{
pathTraverser = std::unique_ptr<PathTraverser>(new ImageListPathTraverser(path.imageList));
}

View File

@@ -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<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:
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