Mercurial > minori
comparison src/gui/pages/torrents.cc @ 202:71832ffe425a
animia: re-add kvm fd source
this is all being merged from my wildly out-of-date laptop. SORRY!
in other news, I edited the CI file to install the wayland client
as well, so the linux CI build might finally get wayland stuff.
| author | Paper <paper@paper.us.eu.org> |
|---|---|
| date | Tue, 02 Jan 2024 06:05:06 -0500 |
| parents | 01d259b9c89f |
| children | 53211cb1e7f5 |
comparison
equal
deleted
inserted
replaced
| 201:8f6f8dd2eb23 | 202:71832ffe425a |
|---|---|
| 2 #include "core/strings.h" | 2 #include "core/strings.h" |
| 3 #include "core/http.h" | 3 #include "core/http.h" |
| 4 #include "core/session.h" | 4 #include "core/session.h" |
| 5 #include "gui/widgets/text.h" | 5 #include "gui/widgets/text.h" |
| 6 #include "track/media.h" | 6 #include "track/media.h" |
| 7 #include "pugixml.hpp" | 7 |
| 8 #include <QVBoxLayout> | 8 #include <QVBoxLayout> |
| 9 #include <QToolBar> | 9 #include <QToolBar> |
| 10 #include <QTreeView> | 10 #include <QTreeView> |
| 11 #include <QMainWindow> | 11 #include <QMainWindow> |
| 12 #include <QByteArray> | 12 #include <QByteArray> |
| 13 #include <QDataStream> | 13 #include <QDataStream> |
| 14 #include <QThreadPool> | 14 #include <QThreadPool> |
| 15 #include <QDebug> | 15 #include <QDebug> |
| 16 | |
| 16 #include <iostream> | 17 #include <iostream> |
| 17 #include <sstream> | 18 #include <sstream> |
| 18 #include <algorithm> | 19 #include <algorithm> |
| 19 | 20 |
| 21 #include "pugixml.hpp" | |
| 20 #include "anitomy/anitomy.h" | 22 #include "anitomy/anitomy.h" |
| 21 | 23 |
| 22 /* This file is very, very similar to the anime list page. | 24 /* This file is very, very similar to the anime list page. |
| 23 | 25 |
| 24 It differs from Taiga in that it uses tabs instead of | 26 It differs from Taiga in that it uses tabs instead of |
| 50 | 52 |
| 51 QByteArray TorrentsPageListModel::DownloadTorrentList() { | 53 QByteArray TorrentsPageListModel::DownloadTorrentList() { |
| 52 return HTTP::Get(session.config.torrents.feed_link); | 54 return HTTP::Get(session.config.torrents.feed_link); |
| 53 } | 55 } |
| 54 | 56 |
| 57 void TorrentsPageListModel::ParseFeedDescription(const std::string& description, Torrent& torrent) { | |
| 58 /* Parse description... */ | |
| 59 enum class Keys { SIZE, AUTHORIZED, SUBMITTER, COMMENT }; | |
| 60 | |
| 61 const std::unordered_map<std::string, Keys> KeyMap = { | |
| 62 {"Size", Keys::SIZE}, | |
| 63 {"Authorized", Keys::AUTHORIZED}, | |
| 64 {"Submitter", Keys::SUBMITTER}, | |
| 65 {"Comment", Keys::COMMENT} | |
| 66 }; | |
| 67 | |
| 68 /* Parse size from description */ | |
| 69 std::istringstream descstream(description); | |
| 70 | |
| 71 for (std::string line; std::getline(descstream, line);) { | |
| 72 const size_t pos = line.find_first_of(':', 0); | |
| 73 if (pos == std::string::npos) | |
| 74 continue; | |
| 75 | |
| 76 const std::string key = line.substr(0, pos); | |
| 77 const std::string value = line.substr(line.find_first_not_of(": ", pos)); | |
| 78 | |
| 79 switch (KeyMap.at(key)) { | |
| 80 case Keys::COMMENT: | |
| 81 torrent.SetDescription(value); | |
| 82 break; | |
| 83 case Keys::SIZE: | |
| 84 torrent.SetSize(Strings::HumanReadableSizeToBytes(value)); | |
| 85 break; | |
| 86 default: | |
| 87 break; | |
| 88 } | |
| 89 } | |
| 90 } | |
| 91 | |
| 55 void TorrentsPageListModel::ParseTorrentList(const QByteArray& ba) { | 92 void TorrentsPageListModel::ParseTorrentList(const QByteArray& ba) { |
| 56 std::istringstream stdstream(Strings::ToUtf8String(ba)); | 93 std::istringstream stdstream(Strings::ToUtf8String(ba)); |
| 57 | 94 |
| 58 pugi::xml_document doc; | 95 pugi::xml_document doc; |
| 59 if (!doc.load(stdstream)) | 96 if (!doc.load(stdstream)) |
| 82 torrent.SetTitle(Strings::ToUtf8String(elements.get(anitomy::kElementAnimeTitle))); | 119 torrent.SetTitle(Strings::ToUtf8String(elements.get(anitomy::kElementAnimeTitle))); |
| 83 torrent.SetEpisode(Strings::RemoveLeadingChars(Strings::ToUtf8String(elements.get(anitomy::kElementEpisodeNumber)), '0')); | 120 torrent.SetEpisode(Strings::RemoveLeadingChars(Strings::ToUtf8String(elements.get(anitomy::kElementEpisodeNumber)), '0')); |
| 84 torrent.SetGroup(Strings::ToUtf8String(elements.get(anitomy::kElementReleaseGroup))); | 121 torrent.SetGroup(Strings::ToUtf8String(elements.get(anitomy::kElementReleaseGroup))); |
| 85 torrent.SetResolution(Strings::ToUtf8String(elements.get(anitomy::kElementVideoResolution))); | 122 torrent.SetResolution(Strings::ToUtf8String(elements.get(anitomy::kElementVideoResolution))); |
| 86 } | 123 } |
| 87 torrent.SetDescription(Strings::TextifySynopsis(item.child_value("description"))); | 124 |
| 88 { | 125 ParseFeedDescription(Strings::TextifySynopsis(item.child_value("description")), torrent); |
| 89 /* Parse description... */ | 126 |
| 90 enum class Keys { SIZE, AUTHORIZED, SUBMITTER, COMMENT }; | |
| 91 | |
| 92 const std::unordered_map<std::string, Keys> KeyMap = { | |
| 93 {"Size", Keys::SIZE}, | |
| 94 {"Authorized", Keys::AUTHORIZED}, | |
| 95 {"Submitter", Keys::SUBMITTER}, | |
| 96 {"Comment", Keys::COMMENT} | |
| 97 }; | |
| 98 | |
| 99 const std::string description = Strings::TextifySynopsis(item.child_value("description")); | |
| 100 | |
| 101 /* Parse size from description */ | |
| 102 std::istringstream descstream(description); | |
| 103 | |
| 104 for (std::string line; std::getline(descstream, line);) { | |
| 105 const size_t pos = line.find_first_of(':', 0); | |
| 106 if (pos == std::string::npos) | |
| 107 continue; | |
| 108 | |
| 109 const std::string key = line.substr(0, pos); | |
| 110 const std::string value = line.substr(line.find_first_not_of(": ", pos)); | |
| 111 | |
| 112 switch (KeyMap.at(key)) { | |
| 113 case Keys::COMMENT: | |
| 114 torrent.SetDescription(value); | |
| 115 break; | |
| 116 case Keys::SIZE: | |
| 117 torrent.SetSize(Strings::HumanReadableSizeToBytes(value)); | |
| 118 break; | |
| 119 default: | |
| 120 break; | |
| 121 } | |
| 122 } | |
| 123 } | |
| 124 torrent.SetLink(item.child_value("link")); | 127 torrent.SetLink(item.child_value("link")); |
| 125 torrent.SetGuid(item.child_value("guid")); | 128 torrent.SetGuid(item.child_value("guid")); |
| 126 { | 129 { |
| 127 const QString date_str = Strings::ToQString(item.child_value("pubDate")); | 130 const QString date_str = Strings::ToQString(item.child_value("pubDate")); |
| 128 torrent.SetDate(QDateTime::fromString(date_str, "ddd, dd MMM yyyy HH:mm:ss t")); | 131 torrent.SetDate(QDateTime::fromString(date_str, "ddd, dd MMM yyyy HH:mm:ss t")); |
