shit attempt at better torrent search, fixes

This commit is contained in:
ThaUnknown 2020-08-28 07:14:44 +02:00
parent 01c4b2e5ce
commit b9c6a129e6
3 changed files with 62 additions and 42 deletions

View file

@ -65,6 +65,7 @@ function alRequest(a) {
medium medium
} }
bannerImage bannerImage
synonyms
} }
} }
} }
@ -104,6 +105,7 @@ function alRequest(a) {
extraLarge extraLarge
} }
bannerImage bannerImage
synonyms
} }
} }
} }
@ -186,7 +188,8 @@ let detailsfrag = document.createDocumentFragment(),
status: "Status", status: "Status",
english: "English", english: "English",
romaji: "Romaji", romaji: "Romaji",
native: "Native" native: "Native",
synonyms: "Synonyms"
} }
function viewAnime(media) { function viewAnime(media) {
@ -197,6 +200,7 @@ function viewAnime(media) {
document.querySelector(".view .title").textContent = !!media.title.english ? media.title.english : media.title.romaji document.querySelector(".view .title").textContent = !!media.title.english ? media.title.english : media.title.romaji
document.querySelector(".view .desc").innerHTML = !!media.description ? media.description : "" document.querySelector(".view .desc").innerHTML = !!media.description ? media.description : ""
document.querySelector(".view .details").innerHTML = "" document.querySelector(".view .details").innerHTML = ""
document.querySelector(".view #play").onclick = function () { nyaaSearch(media.title, document.querySelector(".view #ep").value, 0); halfmoon.toggleModal("view")}
detailsCreator(media) detailsCreator(media)
document.querySelector(".view .details").appendChild(detailsfrag) document.querySelector(".view .details").appendChild(detailsfrag)
} }
@ -206,7 +210,7 @@ function detailsCreator(entry) {
let template = document.createElement("p") let template = document.createElement("p")
if (typeof value[1] == 'object') { if (typeof value[1] == 'object') {
if (Array.isArray(value[1])) { if (Array.isArray(value[1])) {
if (details[value[0]]) { if (details[value[0]] && value[1].length > 0) {
template.innerHTML = `<span class="font-weight-bold">${details[value[0]]}</span><br><span class="text-muted">${value[1].map(key => (key)).join(', ')}</span>` template.innerHTML = `<span class="font-weight-bold">${details[value[0]]}</span><br><span class="text-muted">${value[1].map(key => (key)).join(', ')}</span>`
detailsfrag.appendChild(template) detailsfrag.appendChild(template)
} }
@ -226,46 +230,56 @@ const DOMPARSER = new DOMParser().parseFromString.bind(new DOMParser()),
searchTitle = document.querySelector("#title"), searchTitle = document.querySelector("#title"),
searchEpisode = document.querySelector("#ep") searchEpisode = document.querySelector("#ep")
// remake this shit
function tsearch(title, episode) { function nyaaSearch(titles, episode, index) {
let table = document.querySelector("tbody.tsearch") if (episode.length < 2) {
searchTitle.value = title
searchEpisode.value = episode
if (episode < 10) {
episode = `0${episode}` episode = `0${episode}`
} }
let url = new URL(`https://nyaa.si/?page=rss&c=1_2&f=2&s=seeders&o=desc&q=${title}" ${episode} "`)
let frag = document.createDocumentFragment(), let frag = document.createDocumentFragment(),
hasBegun = true table = document.querySelector("tbody.tsearch"),
title = Object.values(titles)[index],
url = new URL(`https://nyaa.si/?page=rss&c=1_2&f=2&s=seeders&o=desc&q=${title}" ${episode} "`)
table.textContent = "";
console.log(`https://nyaa.si/?page=rss&c=1_2&f=2&s=seeders&o=desc&q=${title}" ${episode} "`)
fetch(url).then((res) => { fetch(url).then((res) => {
res.text().then((xmlTxt) => { res.text().then((xmlTxt) => {
try { try {
let doc = DOMPARSER(xmlTxt, "text/xml") let doc = DOMPARSER(xmlTxt, "text/xml")
doc.querySelectorAll("item").forEach((item, index) => { if (doc.querySelectorAll("item").length != 0) {
let i = item.querySelector.bind(item), doc.querySelectorAll("item").forEach((item, index) => {
template = document.createElement("tr") let i = item.querySelector.bind(item),
template.innerHTML = ` template = document.createElement("tr")
<th>${(index + 1)}</th> template.innerHTML = `
<td>${i("title").textContent}</td> <th>${(index + 1)}</th>
<td>${i("size").textContent}</td> <td>${i("title").textContent}</td>
<td>${i("seeders").textContent}</td> <td>${i("size").textContent}</td>
<td>${i("leechers").textContent}</td> <td>${i("seeders").textContent}</td>
<td>${i("downloads").textContent}</td> <td>${i("leechers").textContent}</td>
<td onclick="addTorrent('${i('infoHash').textContent}')" class="pointer">Play</td> <td>${i("downloads").textContent}</td>
` <td onclick="addTorrent('${i('infoHash').textContent}')" class="pointer">Play</td>
frag.appendChild(template) `
}) frag.appendChild(template)
})
halfmoon.toggleModal("tsearch")
} else {
if (index < 2) {
nyaaSearch(titles, episode, index + 1)
} else {
halfmoon.initStickyAlert({
content: `Couldn't find torrent for ${!!titles.english ? titles.english : titles.romaji}! Try using a direct magnet link.`,
title: "Search Failed",
alertType: "alert-danger",
fillType: ""
});
}
}
} catch (e) { } catch (e) {
console.error(e) console.error(e)
} }
if (hasBegun) {
table.textContent = "";
hasBegun = false;
}
table.appendChild(frag) table.appendChild(frag)
}) })
}).catch(() => console.error("Error in fetching the RSS feed")) }).catch(() => console.error("Error in fetching the RSS feed"))
} }
function tsearchform() { function tsearchform() {
tsearch(searchTitle.value, searchEpisode.value) tsearch(searchTitle.value, searchEpisode.value)

View file

@ -23,14 +23,6 @@
<button class="close pointer" data-dismiss="modal" type="button" aria-label="Close"> <button class="close pointer" data-dismiss="modal" type="button" aria-label="Close">
<span>&times;</span> <span>&times;</span>
</button> </button>
<div class="input-group mb-20">
<input type="text" id="title" class="form-control"
placeholder="Anime Name, Magnet Link, Torrent File or Hash">
<input type="number" id="ep" class="form-control flex-reset w-50" placeholder="#" min="1">
<div class="input-group-append">
<button class="btn btn-primary" type="button" onclick="tsearchform()">Search</button>
</div>
</div>
<table class="table"> <table class="table">
<thead> <thead>
<tr> <tr>
@ -52,16 +44,23 @@
<div class="modal modal-full ie-scroll-fix" id="view" tabindex="-1" role="dialog"> <div class="modal modal-full ie-scroll-fix" id="view" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document"> <div class="modal-dialog" role="document">
<div class="view modal-content m-0 p-0"> <div class="view modal-content m-0 p-0">
<button class="close bg-dark-light pointer" data-dismiss="modal" type="button" aria-label="Close">
<span>&times;</span>
</button>
<div class="banner"> <div class="banner">
<img class="cover-img w-full h-full"> <img class="cover-img w-full h-full">
<button class="close bg-dark-light pointer" data-dismiss="modal" type="button" aria-label="Close">
<span>&times;</span>
</button>
</div> </div>
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div class="col-md-3 mt-nc pb-20"> <div class="col-md-3 mt-nc pb-20 d-flex flex-column justify-content-between">
<img class="contain-img rounded w-full"> <img class="contain-img rounded w-full">
<div class="input-group">
<div class="input-group-prepend">
<button class="btn bg-primary pr-5 pl-10" type="button" id="play">Play Episode</button>
</div>
<input type="number" id="ep" class="form-control flex-reset w-28 bg-primary noarrow px-5 text-center" placeholder="#" value="1" min="1">
</div>
</div> </div>
<div class="col-9 p-20"> <div class="col-9 p-20">
<h4 class="title font-weight-bold"> <h4 class="title font-weight-bold">
@ -195,7 +194,9 @@
<div class="input-group-prepend"> <div class="input-group-prepend">
<button class="btn btn-primary material-icons px-10" type="submit">search</button> <button class="btn btn-primary material-icons px-10" type="submit">search</button>
</div> </div>
<input type="text" class="form-control search" placeholder="Anime Name, Image Link or Direct Magnet Link, Torrent File, Hash" id="search"> <input type="text" class="form-control search"
placeholder="Anime Name, Image Link or Direct Magnet Link, Torrent File, Hash"
id="search">
</form> </form>
</div> </div>
</div> </div>

View file

@ -26,7 +26,12 @@
left: var(--nav-size); left: var(--nav-size);
width: calc(100% - var(--nav-size)); width: calc(100% - var(--nav-size));
} }
.w-28{
width: 2.8rem;
}
.noarrow::-webkit-inner-spin-button {
-webkit-appearance: none;
}
/*PLAYER*/ /*PLAYER*/
#player:target { #player:target {