diff src/gui/pages/torrents.cc @ 183:01d259b9c89f

pages/torrents.cc: parse feed descriptions separately services/anilist.cc: use constexpr STL string_view for HTTP queries
author Paper <mrpapersonic@gmail.com>
date Mon, 04 Dec 2023 13:40:42 -0500
parents bc8d2ccff09c
children 53211cb1e7f5
line wrap: on
line diff
--- a/src/gui/pages/torrents.cc	Mon Dec 04 13:19:54 2023 -0500
+++ b/src/gui/pages/torrents.cc	Mon Dec 04 13:40:42 2023 -0500
@@ -54,6 +54,41 @@
 	return HTTP::Get(session.config.torrents.feed_link);
 }
 
+void TorrentsPageListModel::ParseFeedDescription(const std::string& description, Torrent& torrent) {
+	/* Parse description... */
+	enum class Keys { SIZE, AUTHORIZED, SUBMITTER, COMMENT };
+
+	const std::unordered_map<std::string, Keys> KeyMap = {
+		{"Size", Keys::SIZE},
+		{"Authorized", Keys::AUTHORIZED},
+		{"Submitter", Keys::SUBMITTER},
+		{"Comment", Keys::COMMENT}
+	};
+
+	/* Parse size from description */
+	std::istringstream descstream(description);
+
+	for (std::string line; std::getline(descstream, line);) {
+		const size_t pos = line.find_first_of(':', 0);
+		if (pos == std::string::npos)
+			continue;
+
+		const std::string key = line.substr(0, pos);
+		const std::string value = line.substr(line.find_first_not_of(": ", pos));
+
+		switch (KeyMap.at(key)) {
+			case Keys::COMMENT:
+				torrent.SetDescription(value);
+				break;
+			case Keys::SIZE:
+				torrent.SetSize(Strings::HumanReadableSizeToBytes(value));
+				break;
+			default:
+				break;
+		}
+	}
+}
+
 void TorrentsPageListModel::ParseTorrentList(const QByteArray& ba) {
 	std::istringstream stdstream(Strings::ToUtf8String(ba));
 
@@ -86,43 +121,9 @@
 			torrent.SetGroup(Strings::ToUtf8String(elements.get(anitomy::kElementReleaseGroup)));
 			torrent.SetResolution(Strings::ToUtf8String(elements.get(anitomy::kElementVideoResolution)));
 		}
-		torrent.SetDescription(Strings::TextifySynopsis(item.child_value("description")));
-		{
-			/* Parse description... */
-			enum class Keys { SIZE, AUTHORIZED, SUBMITTER, COMMENT };
-
-			const std::unordered_map<std::string, Keys> KeyMap = {
-				{"Size", Keys::SIZE},
-				{"Authorized", Keys::AUTHORIZED},
-				{"Submitter", Keys::SUBMITTER},
-				{"Comment", Keys::COMMENT}
-			};
-
-			const std::string description = Strings::TextifySynopsis(item.child_value("description"));
-
-			/* Parse size from description */
-			std::istringstream descstream(description);
 
-			for (std::string line; std::getline(descstream, line);) {
-				const size_t pos = line.find_first_of(':', 0);
-				if (pos == std::string::npos)
-					continue;
-
-				const std::string key = line.substr(0, pos);
-				const std::string value = line.substr(line.find_first_not_of(": ", pos));
+		ParseFeedDescription(Strings::TextifySynopsis(item.child_value("description")), torrent);
 
-				switch (KeyMap.at(key)) {
-					case Keys::COMMENT:
-						torrent.SetDescription(value);
-						break;
-					case Keys::SIZE:
-						torrent.SetSize(Strings::HumanReadableSizeToBytes(value));
-						break;
-					default:
-						break;
-				}
-			}
-		}
 		torrent.SetLink(item.child_value("link"));
 		torrent.SetGuid(item.child_value("guid"));
 		{