mirror of
https://github.com/ThaUnknown/miru.git
synced 2026-03-28 17:18:42 +00:00
shit attempt at better torrent search, fixes
This commit is contained in:
parent
01c4b2e5ce
commit
b9c6a129e6
3 changed files with 62 additions and 42 deletions
|
|
@ -65,6 +65,7 @@ function alRequest(a) {
|
|||
medium
|
||||
}
|
||||
bannerImage
|
||||
synonyms
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -104,6 +105,7 @@ function alRequest(a) {
|
|||
extraLarge
|
||||
}
|
||||
bannerImage
|
||||
synonyms
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -186,7 +188,8 @@ let detailsfrag = document.createDocumentFragment(),
|
|||
status: "Status",
|
||||
english: "English",
|
||||
romaji: "Romaji",
|
||||
native: "Native"
|
||||
native: "Native",
|
||||
synonyms: "Synonyms"
|
||||
}
|
||||
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 .desc").innerHTML = !!media.description ? media.description : ""
|
||||
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)
|
||||
document.querySelector(".view .details").appendChild(detailsfrag)
|
||||
}
|
||||
|
|
@ -206,7 +210,7 @@ function detailsCreator(entry) {
|
|||
let template = document.createElement("p")
|
||||
if (typeof value[1] == 'object') {
|
||||
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>`
|
||||
detailsfrag.appendChild(template)
|
||||
}
|
||||
|
|
@ -226,46 +230,56 @@ const DOMPARSER = new DOMParser().parseFromString.bind(new DOMParser()),
|
|||
searchTitle = document.querySelector("#title"),
|
||||
searchEpisode = document.querySelector("#ep")
|
||||
|
||||
// remake this shit
|
||||
|
||||
function tsearch(title, episode) {
|
||||
let table = document.querySelector("tbody.tsearch")
|
||||
searchTitle.value = title
|
||||
searchEpisode.value = episode
|
||||
if (episode < 10) {
|
||||
function nyaaSearch(titles, episode, index) {
|
||||
if (episode.length < 2) {
|
||||
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(),
|
||||
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) => {
|
||||
res.text().then((xmlTxt) => {
|
||||
try {
|
||||
let doc = DOMPARSER(xmlTxt, "text/xml")
|
||||
doc.querySelectorAll("item").forEach((item, index) => {
|
||||
let i = item.querySelector.bind(item),
|
||||
template = document.createElement("tr")
|
||||
template.innerHTML = `
|
||||
<th>${(index + 1)}</th>
|
||||
<td>${i("title").textContent}</td>
|
||||
<td>${i("size").textContent}</td>
|
||||
<td>${i("seeders").textContent}</td>
|
||||
<td>${i("leechers").textContent}</td>
|
||||
<td>${i("downloads").textContent}</td>
|
||||
<td onclick="addTorrent('${i('infoHash').textContent}')" class="pointer">Play</td>
|
||||
`
|
||||
frag.appendChild(template)
|
||||
})
|
||||
if (doc.querySelectorAll("item").length != 0) {
|
||||
doc.querySelectorAll("item").forEach((item, index) => {
|
||||
let i = item.querySelector.bind(item),
|
||||
template = document.createElement("tr")
|
||||
template.innerHTML = `
|
||||
<th>${(index + 1)}</th>
|
||||
<td>${i("title").textContent}</td>
|
||||
<td>${i("size").textContent}</td>
|
||||
<td>${i("seeders").textContent}</td>
|
||||
<td>${i("leechers").textContent}</td>
|
||||
<td>${i("downloads").textContent}</td>
|
||||
<td onclick="addTorrent('${i('infoHash').textContent}')" class="pointer">Play</td>
|
||||
`
|
||||
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) {
|
||||
console.error(e)
|
||||
}
|
||||
if (hasBegun) {
|
||||
table.textContent = "";
|
||||
hasBegun = false;
|
||||
}
|
||||
table.appendChild(frag)
|
||||
})
|
||||
}).catch(() => console.error("Error in fetching the RSS feed"))
|
||||
|
||||
}
|
||||
function tsearchform() {
|
||||
tsearch(searchTitle.value, searchEpisode.value)
|
||||
|
|
|
|||
27
app/app.html
27
app/app.html
|
|
@ -23,14 +23,6 @@
|
|||
<button class="close pointer" data-dismiss="modal" type="button" aria-label="Close">
|
||||
<span>×</span>
|
||||
</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">
|
||||
<thead>
|
||||
<tr>
|
||||
|
|
@ -52,16 +44,23 @@
|
|||
<div class="modal modal-full ie-scroll-fix" id="view" tabindex="-1" role="dialog">
|
||||
<div class="modal-dialog" role="document">
|
||||
<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>×</span>
|
||||
</button>
|
||||
<div class="banner">
|
||||
<img class="cover-img w-full h-full">
|
||||
<button class="close bg-dark-light pointer" data-dismiss="modal" type="button" aria-label="Close">
|
||||
<span>×</span>
|
||||
</button>
|
||||
|
||||
</div>
|
||||
<div class="container">
|
||||
<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">
|
||||
<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 class="col-9 p-20">
|
||||
<h4 class="title font-weight-bold">
|
||||
|
|
@ -195,7 +194,9 @@
|
|||
<div class="input-group-prepend">
|
||||
<button class="btn btn-primary material-icons px-10" type="submit">search</button>
|
||||
</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>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -26,7 +26,12 @@
|
|||
left: var(--nav-size);
|
||||
width: calc(100% - var(--nav-size));
|
||||
}
|
||||
|
||||
.w-28{
|
||||
width: 2.8rem;
|
||||
}
|
||||
.noarrow::-webkit-inner-spin-button {
|
||||
-webkit-appearance: none;
|
||||
}
|
||||
/*PLAYER*/
|
||||
|
||||
#player:target {
|
||||
|
|
|
|||
Loading…
Reference in a new issue