Fix torrent parsing

This commit is contained in:
FooIbar committed 2024-03-07 23:06:22 +08:00
1 parent 5d0c2e3f05
commit acb2c720af
2 files changed
+18 -15

No files matched your search

@@ -601,18 +601,23 @@ fun GalleryDetailScreen(args: GalleryDetailScreenArgs, navigator: DestinationsNa
}
}
}
val items = mTorrentList!!.map { it.format() }
val selected = showSelectItem(items, R.string.torrents, false)
val url = mTorrentList!![selected].url
val name = "${mTorrentList!![selected].name}.torrent"
val r = DownloadManager.Request(Uri.parse(url))
r.setDestinationInExternalPublicDir(
Environment.DIRECTORY_DOWNLOADS,
AppConfig.APP_DIRNAME + "/" + FileUtils.sanitizeFilename(name),
)
r.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
r.addRequestHeader("Cookie", EhCookieStore.getCookieHeader(url))
downloadManager.enqueue(r)
if (mTorrentList!!.isEmpty()) {
showSnackbar(noTorrents)
} else {
val items = mTorrentList!!.map { it.format() }
val selected = showSelectItem(items, R.string.torrents, false)
val url = mTorrentList!![selected].url
val name = "${mTorrentList!![selected].name}.torrent"
val r = DownloadManager.Request(Uri.parse(url))
r.setDestinationInExternalPublicDir(
Environment.DIRECTORY_DOWNLOADS,
AppConfig.APP_DIRNAME + "/" + FileUtils.sanitizeFilename(name),
)
r.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
r.addRequestHeader("Cookie", EhCookieStore.getCookieHeader(url))
downloadManager.enqueue(r)
showSnackbar(downloadTorrentStarted)
}
}
EhIconButton(
icon = Icons.Default.SwapVerticalCircle,
@@ -624,8 +629,6 @@ fun GalleryDetailScreen(args: GalleryDetailScreenArgs, navigator: DestinationsNa
if (granted) {
runSuspendCatching {
showTorrentDialog()
}.onSuccess {
showSnackbar(downloadTorrentStarted)
}.onFailure {
logcat(it)
showSnackbar(downloadTorrentFailed)
+1 -1
View File
@@ -25,7 +25,7 @@ fn parse_torrent_list(dom: &VDom, parser: &Parser) -> Result<Vec<Torrent>> {
if html.contains("Expunged") {
None
} else {
let grp = regex!("</span> ([0-9-]+) [0-9:]+</td>[\\s\\S]+</span> ([0-9.]+ [KMGT]iB)</td>[\\s\\S]+</span> ([0-9]+)</td>[\\s\\S]+</span> ([0-9]+)</td>[\\s\\S]+</span> ([0-9]+)</td>[\\s\\S]+</span>([^<]+)</td>[\\s\\S]+onclick=\"document.location='([^\"]+)'[^<]+>([^<]+)</a>").captures(&html)?;
let grp = regex!("<span>([0-9-]+) [0-9:]+</span>[\\s\\S]+</span> ([0-9.]+ [KMGT]iB)</td>[\\s\\S]+</span> ([0-9]+)</td>[\\s\\S]+</span> ([0-9]+)</td>[\\s\\S]+</span> ([0-9]+)</td>[\\s\\S]+</span> ([^<]+)</td>[\\s\\S]+onclick=\"document.location='([^\"]+)'[^<]+>([^<]+)</a>").captures(&html)?;
let name = unescape(&grp[8]).ok()?;
Some(Torrent {
posted: grp[1].to_string(),