Compare commits
7 Commits
b5de8af9d1
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 1509f03681 | |||
| 5fda73a258 | |||
| b92a1216f0 | |||
| 7aa0e8fd30 | |||
| bedb50d524 | |||
| e293f68c4a | |||
| 67a9887058 |
5
Justfile
5
Justfile
@@ -3,4 +3,7 @@ dev:
|
|||||||
go run .
|
go run .
|
||||||
|
|
||||||
build:
|
build:
|
||||||
docker build -t tvqueue .
|
docker build -t git.tsivinsky.com/tsivinsky/tvqueue:latest .
|
||||||
|
|
||||||
|
push:
|
||||||
|
docker push git.tsivinsky.com/tsivinsky/tvqueue:latest
|
||||||
|
|||||||
1
go.mod
1
go.mod
@@ -7,7 +7,6 @@ require (
|
|||||||
github.com/autobrr/go-qbittorrent v1.14.0
|
github.com/autobrr/go-qbittorrent v1.14.0
|
||||||
github.com/jmoiron/sqlx v1.4.0
|
github.com/jmoiron/sqlx v1.4.0
|
||||||
github.com/joho/godotenv v1.5.1
|
github.com/joho/godotenv v1.5.1
|
||||||
github.com/kylesanderson/go-jackett v0.0.0-20251103073025-88ab5d10a082
|
|
||||||
github.com/mattn/go-sqlite3 v1.14.33
|
github.com/mattn/go-sqlite3 v1.14.33
|
||||||
github.com/zeebo/bencode v1.0.0
|
github.com/zeebo/bencode v1.0.0
|
||||||
)
|
)
|
||||||
|
|||||||
2
go.sum
2
go.sum
@@ -19,8 +19,6 @@ github.com/jmoiron/sqlx v1.4.0 h1:1PLqN7S1UYp5t4SrVVnt4nUVNemrDAtxlulVe+Qgm3o=
|
|||||||
github.com/jmoiron/sqlx v1.4.0/go.mod h1:ZrZ7UsYB/weZdl2Bxg6jCRO9c3YHl8r3ahlKmRT4JLY=
|
github.com/jmoiron/sqlx v1.4.0/go.mod h1:ZrZ7UsYB/weZdl2Bxg6jCRO9c3YHl8r3ahlKmRT4JLY=
|
||||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||||
github.com/kylesanderson/go-jackett v0.0.0-20251103073025-88ab5d10a082 h1:4dvzW0EB2DDyw/Qa6ga6Ny4xDfubmbHc5JOVO0G7hFg=
|
|
||||||
github.com/kylesanderson/go-jackett v0.0.0-20251103073025-88ab5d10a082/go.mod h1:o805kiTZcYvSoF1ImxwxvU+VOmK/kvRVRLI49VHXORs=
|
|
||||||
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
|
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
|
||||||
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||||
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
||||||
|
|||||||
20
jackett/client.go
Normal file
20
jackett/client.go
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package jackett
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
Host string
|
||||||
|
APIKey string
|
||||||
|
}
|
||||||
|
|
||||||
|
type Client struct {
|
||||||
|
conf Config
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewClient(conf Config) *Client {
|
||||||
|
return &Client{
|
||||||
|
conf: conf,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) buildUrl(path string) string {
|
||||||
|
return c.conf.Host + path
|
||||||
|
}
|
||||||
91
jackett/search.go
Normal file
91
jackett/search.go
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
package jackett
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Response struct {
|
||||||
|
Results []Result `json:"results"`
|
||||||
|
Indexers []Indexer `json:"indexers"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Result struct {
|
||||||
|
FirstSeen string `json:"FirstSeen"`
|
||||||
|
Tracker string `json:"Tracker"`
|
||||||
|
TrackerID string `json:"TrackerId"`
|
||||||
|
TrackerType string `json:"TrackerType"`
|
||||||
|
CategoryDesc string `json:"CategoryDesc"`
|
||||||
|
BlackholeLink string `json:"BlackholeLink"`
|
||||||
|
Title string `json:"Title"`
|
||||||
|
GUID string `json:"Guid"`
|
||||||
|
Link string `json:"Link"`
|
||||||
|
Details string `json:"Details"`
|
||||||
|
PublishDate string `json:"PublishDate"`
|
||||||
|
Category []int `json:"Category"`
|
||||||
|
Size int64 `json:"Size"`
|
||||||
|
Files any `json:"Files"`
|
||||||
|
Grabs int `json:"Grabs"`
|
||||||
|
Description string `json:"Description"`
|
||||||
|
RageID any `json:"RageID"`
|
||||||
|
TVDBID any `json:"TVDBId"`
|
||||||
|
Imdb any `json:"Imdb"`
|
||||||
|
TMDb any `json:"TMDb"`
|
||||||
|
DoubanID any `json:"DoubanId"`
|
||||||
|
Author string `json:"Author"`
|
||||||
|
BookTitle string `json:"BookTitle"`
|
||||||
|
Seeders int `json:"Seeders"`
|
||||||
|
Peers int `json:"Peers"`
|
||||||
|
Poster any `json:"Poster"`
|
||||||
|
InfoHash any `json:"InfoHash"`
|
||||||
|
MagnetURI any `json:"MagnetUri"`
|
||||||
|
MinimumRatio any `json:"MinimumRatio"`
|
||||||
|
MinimumSeedTime any `json:"MinimumSeedTime"`
|
||||||
|
DownloadVolumeFactor float64 `json:"DownloadVolumeFactor"`
|
||||||
|
UploadVolumeFactor float64 `json:"UploadVolumeFactor"`
|
||||||
|
Gain float64 `json:"Gain"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Indexer struct {
|
||||||
|
ID string `json:"ID"`
|
||||||
|
Name string `json:"Name"`
|
||||||
|
Status int `json:"Status"`
|
||||||
|
Results int `json:"Results"`
|
||||||
|
Error string `json:"Error"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) Search(q string, categories ...int) ([]Result, error) {
|
||||||
|
req, err := http.NewRequest("GET", c.buildUrl("/api/v2.0/indexers/all/results"), nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to create request: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
query := url.Values{}
|
||||||
|
query.Add("apikey", c.conf.APIKey)
|
||||||
|
query.Add("Query", q)
|
||||||
|
|
||||||
|
categoryList := []string{}
|
||||||
|
for _, c := range categories {
|
||||||
|
categoryList = append(categoryList, strconv.Itoa(c))
|
||||||
|
}
|
||||||
|
query.Add("Category[]", strings.Join(categoryList, ","))
|
||||||
|
|
||||||
|
req.URL.RawQuery = query.Encode()
|
||||||
|
|
||||||
|
resp, err := http.DefaultClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to send request: %v", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
response := new(Response)
|
||||||
|
if err := json.NewDecoder(resp.Body).Decode(response); err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to decode response: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.Results, nil
|
||||||
|
}
|
||||||
49
main.go
49
main.go
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"api/jackett"
|
||||||
"api/model"
|
"api/model"
|
||||||
"embed"
|
"embed"
|
||||||
_ "embed"
|
_ "embed"
|
||||||
@@ -18,7 +19,6 @@ import (
|
|||||||
"github.com/autobrr/go-qbittorrent"
|
"github.com/autobrr/go-qbittorrent"
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
"github.com/kylesanderson/go-jackett"
|
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -44,30 +44,13 @@ type JackettTorrent struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func checkForNewTorrents(jackettClient *jackett.Client, db *sqlx.DB, m *model.Model, item *model.Item) error {
|
func checkForNewTorrents(jackettClient *jackett.Client, db *sqlx.DB, m *model.Model, item *model.Item) error {
|
||||||
results, err := jackettClient.TVSearch(jackett.TVSearchOptions{
|
results, err := jackettClient.Search(item.Query, item.Category)
|
||||||
Query: item.Query,
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("couldn't get to jackett api: %v\n", err)
|
return fmt.Errorf("couldn't get to jackett api: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, torrent := range results.Channel.Item {
|
for _, torrent := range results {
|
||||||
size := toIntOr(torrent.Size, 0)
|
guidTorrent, _ := m.GetTorrentByGuidAndItemId(torrent.GUID, item.ID)
|
||||||
category := toIntOr(torrent.Category[0], 5000)
|
|
||||||
pubDate, _ := time.Parse(time.RFC1123Z, torrent.PubDate)
|
|
||||||
|
|
||||||
seeders := 0
|
|
||||||
peers := 0
|
|
||||||
for _, attr := range torrent.Attr {
|
|
||||||
if attr.Name == "seeders" {
|
|
||||||
seeders = toIntOr(attr.Value, 0)
|
|
||||||
}
|
|
||||||
if attr.Name == "peers" {
|
|
||||||
peers = toIntOr(attr.Value, 0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
guidTorrent, _ := m.GetTorrentByGuidAndItemId(torrent.Guid, item.ID)
|
|
||||||
if guidTorrent != nil {
|
if guidTorrent != nil {
|
||||||
// already have this exact one, for this item. ABORT!
|
// already have this exact one, for this item. ABORT!
|
||||||
continue
|
continue
|
||||||
@@ -76,14 +59,14 @@ func checkForNewTorrents(jackettClient *jackett.Client, db *sqlx.DB, m *model.Mo
|
|||||||
// this shit will duplicate. idk if it's ok or not, but fuck it. we ball
|
// this shit will duplicate. idk if it's ok or not, but fuck it. we ball
|
||||||
_, err = db.NamedExec("INSERT INTO torrents (title, guid, indexer, pubdate, size, download_url, seeders, peers, category, item_id) VALUES (:title, :guid, :indexer, :pubdate, :size, :download_url, :seeders, :peers, :category, :item_id)", map[string]any{
|
_, err = db.NamedExec("INSERT INTO torrents (title, guid, indexer, pubdate, size, download_url, seeders, peers, category, item_id) VALUES (:title, :guid, :indexer, :pubdate, :size, :download_url, :seeders, :peers, :category, :item_id)", map[string]any{
|
||||||
"title": torrent.Title,
|
"title": torrent.Title,
|
||||||
"guid": torrent.Guid,
|
"guid": torrent.GUID,
|
||||||
"indexer": torrent.Jackettindexer.ID,
|
"indexer": torrent.TrackerID,
|
||||||
"pubdate": pubDate,
|
"pubdate": torrent.PublishDate,
|
||||||
"size": size,
|
"size": torrent.Size,
|
||||||
"download_url": torrent.Link,
|
"download_url": torrent.Link,
|
||||||
"seeders": seeders,
|
"seeders": torrent.Seeders,
|
||||||
"peers": peers,
|
"peers": torrent.Peers,
|
||||||
"category": category,
|
"category": torrent.Category[0],
|
||||||
"item_id": item.ID,
|
"item_id": item.ID,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -390,7 +373,15 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := torrentClient.AddTorrentFromMemory(data, map[string]string{}); err != nil {
|
opts := make(map[string]string)
|
||||||
|
if category, ok := os.LookupEnv("QBITTORRENT_CATEGORY"); ok {
|
||||||
|
opts["category"] = category
|
||||||
|
}
|
||||||
|
if savePath, ok := os.LookupEnv("QBITTORRENT_SAVEPATH"); ok {
|
||||||
|
opts["savepath"] = savePath
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := torrentClient.AddTorrentFromMemory(data, opts); err != nil {
|
||||||
http.Error(w, err.Error(), 500)
|
http.Error(w, err.Error(), 500)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +1,19 @@
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useMemo, useState } from "react";
|
||||||
import type { ItemDetails } from "../api/useItemsQuery";
|
import type { ItemDetails } from "../api/useItemsQuery";
|
||||||
import { useItemTorrentsQuery } from "../api/useItemTorrentsQuery";
|
import { useItemTorrentsQuery } from "../api/useItemTorrentsQuery";
|
||||||
import {
|
import {
|
||||||
ArrowsClockwiseIcon,
|
ArrowsClockwiseIcon,
|
||||||
CaretDownIcon,
|
CaretDownIcon,
|
||||||
CaretUpIcon,
|
CaretUpIcon,
|
||||||
CheckCircleIcon,
|
|
||||||
DownloadSimpleIcon,
|
|
||||||
TrashIcon,
|
TrashIcon,
|
||||||
} from "@phosphor-icons/react";
|
} from "@phosphor-icons/react";
|
||||||
import { useDownloadTorrentMutation } from "../api/useDownloadTorrentMutation";
|
|
||||||
import { useDeleteItemMutation } from "../api/useDeleteItemMutation";
|
import { useDeleteItemMutation } from "../api/useDeleteItemMutation";
|
||||||
import { useQueryClient } from "@tanstack/react-query";
|
import { useQueryClient } from "@tanstack/react-query";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import relativeTime from "dayjs/plugin/relativeTime";
|
import relativeTime from "dayjs/plugin/relativeTime";
|
||||||
import { humanFileSize } from "../utils/humanFileSize";
|
|
||||||
import { useDeleteTorrentMutation } from "../api/useDeleteTorrentMutation";
|
|
||||||
import { useRefreshItemMutation } from "../api/useRefreshItemMutation";
|
import { useRefreshItemMutation } from "../api/useRefreshItemMutation";
|
||||||
import { Loader } from "./Loader";
|
import { Loader } from "./Loader";
|
||||||
|
import { Torrent } from "./Torrent";
|
||||||
|
|
||||||
dayjs.extend(relativeTime);
|
dayjs.extend(relativeTime);
|
||||||
|
|
||||||
@@ -33,12 +29,21 @@ export const Item = ({ item }: ItemProps) => {
|
|||||||
const { data: torrents } = useItemTorrentsQuery(item.id, open);
|
const { data: torrents } = useItemTorrentsQuery(item.id, open);
|
||||||
|
|
||||||
const deleteMutation = useDeleteItemMutation();
|
const deleteMutation = useDeleteItemMutation();
|
||||||
const downloadMutation = useDownloadTorrentMutation();
|
|
||||||
const refreshMutation = useRefreshItemMutation();
|
const refreshMutation = useRefreshItemMutation();
|
||||||
const deleteTorrentMutation = useDeleteTorrentMutation();
|
|
||||||
|
|
||||||
const Icon = open ? CaretUpIcon : CaretDownIcon;
|
const Icon = open ? CaretUpIcon : CaretDownIcon;
|
||||||
|
|
||||||
|
const [search, setSearch] = useState("");
|
||||||
|
|
||||||
|
const filteredTorrents = useMemo(() => {
|
||||||
|
if (!search) return torrents;
|
||||||
|
return torrents?.filter((torrent) => {
|
||||||
|
const terms = search.split(" ");
|
||||||
|
const foundTerms = terms.filter((term) => torrent.title.includes(term));
|
||||||
|
return foundTerms.length === terms.length;
|
||||||
|
});
|
||||||
|
}, [search, torrents]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const params = new URLSearchParams(location.search);
|
const params = new URLSearchParams(location.search);
|
||||||
const itemId = params.get("item");
|
const itemId = params.get("item");
|
||||||
@@ -49,10 +54,6 @@ export const Item = ({ item }: ItemProps) => {
|
|||||||
}
|
}
|
||||||
}, [item]);
|
}, [item]);
|
||||||
|
|
||||||
const handleDownloadTorrent = (torrentId: number) => {
|
|
||||||
downloadMutation.mutate({ torrentId });
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleDelete = () => {
|
const handleDelete = () => {
|
||||||
if (!confirm("Do you want to delete this item?")) return;
|
if (!confirm("Do you want to delete this item?")) return;
|
||||||
|
|
||||||
@@ -83,22 +84,6 @@ export const Item = ({ item }: ItemProps) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDeleteTorrent = (torrentId: number) => {
|
|
||||||
deleteTorrentMutation.mutate(
|
|
||||||
{
|
|
||||||
id: torrentId,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
onSuccess() {
|
|
||||||
queryClient.invalidateQueries({ queryKey: ["items"] });
|
|
||||||
queryClient.invalidateQueries({
|
|
||||||
queryKey: ["items", item.id, "torrents"],
|
|
||||||
});
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="border-t border-b border-neutral-900">
|
<div className="border-t border-b border-neutral-900">
|
||||||
<div
|
<div
|
||||||
@@ -112,6 +97,15 @@ export const Item = ({ item }: ItemProps) => {
|
|||||||
</div>
|
</div>
|
||||||
{open && (
|
{open && (
|
||||||
<div>
|
<div>
|
||||||
|
<div className="my-2">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
placeholder="Search torrents..."
|
||||||
|
className="w-full outline-none py-1 px-2 rounded border-2 border-transparent focus:border-neutral-900"
|
||||||
|
value={search}
|
||||||
|
onChange={(e) => setSearch(e.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
<div className="flex items-center gap-2 mb-2">
|
<div className="flex items-center gap-2 mb-2">
|
||||||
<div>
|
<div>
|
||||||
Last Refresh:{" "}
|
Last Refresh:{" "}
|
||||||
@@ -140,51 +134,9 @@ export const Item = ({ item }: ItemProps) => {
|
|||||||
<TrashIcon size={20} /> Delete item
|
<TrashIcon size={20} /> Delete item
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
{torrents && torrents.length > 0 ? (
|
{filteredTorrents && filteredTorrents.length > 0 ? (
|
||||||
torrents?.map((torrent) => (
|
filteredTorrents.map((torrent) => (
|
||||||
<div
|
<Torrent key={torrent.id} itemId={item.id} torrent={torrent} />
|
||||||
key={torrent.id}
|
|
||||||
className="flex justify-between items-center hover:bg-neutral-200 group"
|
|
||||||
>
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<span>
|
|
||||||
<a
|
|
||||||
href={torrent.guid}
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
>
|
|
||||||
{torrent.title}
|
|
||||||
</a>{" "}
|
|
||||||
[{formatCategory(torrent.category)}] [{torrent.indexer}]
|
|
||||||
</span>
|
|
||||||
{torrent.downloaded && (
|
|
||||||
<span title="Torrent files downloaded">
|
|
||||||
<CheckCircleIcon size={20} color="green" />
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
<button
|
|
||||||
className="hidden group-hover:inline text-[#b00420] cursor-pointer"
|
|
||||||
onClick={() => handleDeleteTorrent(torrent.id)}
|
|
||||||
>
|
|
||||||
<TrashIcon size={16} />
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div className="flex items-center gap-1">
|
|
||||||
<span>Seeds: {torrent.seeders}</span>
|
|
||||||
<span>Peers: {torrent.peers}</span>
|
|
||||||
<span>
|
|
||||||
PubDate: {dayjs(torrent.pubdate).format("DD.MM.YYYY")} at{" "}
|
|
||||||
{dayjs(torrent.pubdate).format("HH:mm")}
|
|
||||||
</span>
|
|
||||||
<button
|
|
||||||
className="cursor-pointer"
|
|
||||||
onClick={() => handleDownloadTorrent(torrent.id)}
|
|
||||||
>
|
|
||||||
<DownloadSimpleIcon size={24} />
|
|
||||||
</button>
|
|
||||||
<span>{humanFileSize(torrent.size)}</span>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
))
|
))
|
||||||
) : (
|
) : (
|
||||||
<span>No torrents yet</span>
|
<span>No torrents yet</span>
|
||||||
@@ -194,26 +146,3 @@ export const Item = ({ item }: ItemProps) => {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const formatCategory = (category: number): string => {
|
|
||||||
switch (category) {
|
|
||||||
case 1000:
|
|
||||||
return "Console";
|
|
||||||
case 2000:
|
|
||||||
return "Movies";
|
|
||||||
case 3000:
|
|
||||||
return "Audio";
|
|
||||||
case 4000:
|
|
||||||
return "PC";
|
|
||||||
case 5000:
|
|
||||||
return "TV";
|
|
||||||
case 6000:
|
|
||||||
return "XXX";
|
|
||||||
case 7000:
|
|
||||||
return "Books";
|
|
||||||
case 8000:
|
|
||||||
return "Other";
|
|
||||||
default:
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|||||||
116
web/src/components/Torrent.tsx
Normal file
116
web/src/components/Torrent.tsx
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
import { useState } from "react";
|
||||||
|
import type { ItemTorrent } from "../api/useItemTorrentsQuery";
|
||||||
|
import { categories } from "../lib/categories";
|
||||||
|
import {
|
||||||
|
ArrowSquareOutIcon,
|
||||||
|
CaretDownIcon,
|
||||||
|
CaretUpIcon,
|
||||||
|
CheckCircleIcon,
|
||||||
|
DownloadSimpleIcon,
|
||||||
|
TrashIcon,
|
||||||
|
} from "@phosphor-icons/react";
|
||||||
|
import dayjs from "dayjs";
|
||||||
|
import { humanFileSize } from "../utils/humanFileSize";
|
||||||
|
import { useDeleteTorrentMutation } from "../api/useDeleteTorrentMutation";
|
||||||
|
import { useDownloadTorrentMutation } from "../api/useDownloadTorrentMutation";
|
||||||
|
import { useQueryClient } from "@tanstack/react-query";
|
||||||
|
|
||||||
|
export type TorrentProps = {
|
||||||
|
itemId: number;
|
||||||
|
torrent: ItemTorrent;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const Torrent = ({ itemId, torrent }: TorrentProps) => {
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
const downloadMutation = useDownloadTorrentMutation();
|
||||||
|
const deleteMutation = useDeleteTorrentMutation();
|
||||||
|
|
||||||
|
const [open, setOpen] = useState(false);
|
||||||
|
|
||||||
|
const ChevronIcon = open ? CaretUpIcon : CaretDownIcon;
|
||||||
|
|
||||||
|
const handleDownload = () => {
|
||||||
|
downloadMutation.mutate({ torrentId: torrent.id });
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDelete = () => {
|
||||||
|
deleteMutation.mutate(
|
||||||
|
{
|
||||||
|
id: torrent.id,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
onSuccess() {
|
||||||
|
queryClient.invalidateQueries({ queryKey: ["items"] });
|
||||||
|
queryClient.invalidateQueries({
|
||||||
|
queryKey: ["items", itemId, "torrents"],
|
||||||
|
});
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col gap-1">
|
||||||
|
<div
|
||||||
|
className="flex items-center gap-2 hover:bg-neutral-200 cursor-pointer"
|
||||||
|
role="button"
|
||||||
|
tabIndex={0}
|
||||||
|
onClick={() => setOpen((prev) => !prev)}
|
||||||
|
>
|
||||||
|
<p>{torrent.title}</p>
|
||||||
|
{torrent.downloaded && (
|
||||||
|
<span title="Torrent files downloaded">
|
||||||
|
<CheckCircleIcon size={20} color="green" />
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
<div className="ml-auto flex items-center gap-1">
|
||||||
|
<span>[{formatCategory(torrent.category)}]</span>
|
||||||
|
<span>{humanFileSize(torrent.size)}</span>
|
||||||
|
<span>
|
||||||
|
<ChevronIcon size={20} />
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{open && (
|
||||||
|
<div className="p-2 bg-neutral-100 rounded-md text-[15px]">
|
||||||
|
<p>Indexer: {torrent.indexer}</p>
|
||||||
|
<p>Seeders: {torrent.seeders}</p>
|
||||||
|
<p>Peers: {torrent.peers}</p>
|
||||||
|
<p>
|
||||||
|
Published: {dayjs(torrent.pubdate).format("DD.MM.YYYY")} at{" "}
|
||||||
|
{dayjs(torrent.pubdate).format("HH:mm")}
|
||||||
|
</p>
|
||||||
|
<div className="flex items-center gap-2 mt-2">
|
||||||
|
<a
|
||||||
|
href={torrent.guid}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
className="flex items-center gap-1"
|
||||||
|
>
|
||||||
|
<ArrowSquareOutIcon size={18} /> Open
|
||||||
|
</a>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="cursor-pointer flex items-center gap-1"
|
||||||
|
onClick={handleDownload}
|
||||||
|
>
|
||||||
|
<DownloadSimpleIcon size={18} /> Download
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
className="text-[#b00420] cursor-pointer flex items-center gap-1"
|
||||||
|
onClick={handleDelete}
|
||||||
|
>
|
||||||
|
<TrashIcon size={18} /> Delete torrent
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const formatCategory = (category: number): string => {
|
||||||
|
return categories[category as keyof typeof categories] || "";
|
||||||
|
};
|
||||||
@@ -1,10 +1,61 @@
|
|||||||
export const categories = {
|
export const categories = {
|
||||||
1000: "Console",
|
1000: "Console",
|
||||||
|
1010: "Console/NDS",
|
||||||
|
1020: "Console/PSP",
|
||||||
|
1030: "Console/Wii",
|
||||||
|
1040: "Console/XBox",
|
||||||
|
1050: "Console/XBox 360",
|
||||||
|
1080: "Console/PS3",
|
||||||
|
1090: "Console/Other",
|
||||||
|
1110: "Console/3DS",
|
||||||
|
1120: "Console/PS Vita",
|
||||||
|
1180: "Console/PS4",
|
||||||
|
|
||||||
2000: "Movies",
|
2000: "Movies",
|
||||||
|
2010: "Movies/Foreign",
|
||||||
|
2020: "Movies/Other",
|
||||||
|
2030: "Movies/SD",
|
||||||
|
2040: "Movies/HD",
|
||||||
|
2045: "Movies/UHD",
|
||||||
|
2060: "Movies/3D",
|
||||||
|
2070: "Movies/DVD",
|
||||||
|
|
||||||
3000: "Audio",
|
3000: "Audio",
|
||||||
|
3010: "Audio/MP3",
|
||||||
|
3020: "Audio/Video",
|
||||||
|
3030: "Audio/Audiobook",
|
||||||
|
3040: "Audio/Lossless",
|
||||||
|
3050: "Audio/Other",
|
||||||
|
|
||||||
4000: "PC",
|
4000: "PC",
|
||||||
|
4010: "PC/0day",
|
||||||
|
4030: "PC/Mac",
|
||||||
|
4040: "PC/Mobile-Other",
|
||||||
|
4050: "PC/Games",
|
||||||
|
4060: "PC/Mobile-IOS",
|
||||||
|
4070: "PC/Mobile-Android",
|
||||||
|
|
||||||
5000: "TV",
|
5000: "TV",
|
||||||
|
5020: "TV/Foreign",
|
||||||
|
5030: "TV/SD",
|
||||||
|
5040: "TV/HD",
|
||||||
|
5045: "TV/UHD",
|
||||||
|
5050: "TV/Other",
|
||||||
|
5060: "TV/Sport",
|
||||||
|
5070: "TV/Anime",
|
||||||
|
5080: "TV/Documentary",
|
||||||
|
|
||||||
6000: "XXX",
|
6000: "XXX",
|
||||||
|
6010: "XXX/DVD",
|
||||||
|
6060: "XXX/ImageSet",
|
||||||
|
|
||||||
7000: "Books",
|
7000: "Books",
|
||||||
|
7010: "Books/Mags",
|
||||||
|
7020: "Books/EBook",
|
||||||
|
7030: "Books/Comics",
|
||||||
|
7040: "Books/Technical",
|
||||||
|
7050: "Books/Other",
|
||||||
|
|
||||||
8000: "Other",
|
8000: "Other",
|
||||||
|
8010: "Other/Misc",
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user