1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#ifndef TORRENTRSS_H
#define TORRENTRSS_H
#include <QObject>
#include <QThread>
#include <QDateTime>
#include "curlresult.h"
#include "library.h"
#include "torrentclient.h"
#include "config.h"
namespace TorrentRss {
class Entry {
public:
virtual ~Entry() {};
QString name;
QString url;
QDateTime date;
virtual bool isCandidateForAutoDownload(QString,int,QString, const RssConfig&) { return false;};
};
class FeedResult {
public:
FeedResult(const RssConfig& rssConfig);
virtual ~FeedResult();
QList<Entry*> entires;
void removeSameEntries(const FeedResult& other);
virtual void parse(CurlResult& result) = 0;
const RssConfig& rssConfig;
};
class Feed : public QObject {
Q_OBJECT
public:
Feed(QString url, const RssConfig& rssConfig, TvShow* tvShow = NULL);
virtual ~Feed();
virtual void fetch();
TvShow* getTvShow();
Entry* candidateForAutoDownload(const RssConfig& rssConfig);
signals:
void foundCandidateForAutoDownload(TorrentRss::Entry entry);
protected:
virtual FeedResult* createFeedResult(const RssConfig& rssConfig) = 0;
void setResult(FeedResult* result);
const RssConfig& rssConfig;
private:
FeedResult* result;
QString url;
TvShow* tvShow;
};
class Client : public QObject {
Q_OBJECT
public:
explicit Client(TorrentClient& torrentClient, Library& library, const RssConfig& rssConfig, QObject *parent = 0);
virtual ~Client();
void refetch();
void addFeed(Feed* feed);
virtual void addFeed(TvShow* show) = 0;
void removeFeed(Feed* feed);
void connectLibrary();
signals:
void torrentAvailable(TorrentRss::Entry url);
public slots:
void addFeedsForWaitingShows();
void autoDownloadEntry(TorrentRss::Entry entry);
private slots:
void tvShowChangedStatus(TvShow* show, TvShow::WatchStatus newStatus, TvShow::WatchStatus oldStatus);
protected:
QList<Feed*> feeds;
const RssConfig& rssConfig;
private:
Library& library;
TorrentClient& torrentClient;
};
class Thread : public QThread {
Q_OBJECT
public:
Thread(Client& client, QObject* parent = 0);
~Thread();
void run();
bool toldToStop;
private:
Client& client;
int refetchInterval;
int sleeped;
int sleepStep;
};
} // namespace
#endif // TORRENTRSS_H