feat: torrent player
This commit is contained in:
1 parent
b379bc229d
commit
f6cb8df39b
17 files changed
+1705
-3689
No files matched your search
+2
-2
@@ -1,7 +1,7 @@
|
||||
class Http {
|
||||
base = 'https://api.themoviedb.org/3';
|
||||
|
||||
get<T>(url: string, { params }: { params?: Record<string, unknown> } = {}): Promise<T> {
|
||||
get<T>(url: string, { params }: { params?: Record<string, unknown> } = {}, base?: string): Promise<T> {
|
||||
const serializedParams = Object.entries(params || {}).reduce((params, [key, value]) => {
|
||||
if (!['', undefined, null].includes(value as string)) {
|
||||
params.set(key, value as string);
|
||||
@@ -10,7 +10,7 @@ class Http {
|
||||
return params;
|
||||
}, new URLSearchParams());
|
||||
|
||||
return fetch(`${this.base}${url}?${serializedParams}`, {
|
||||
return fetch(`${base || this.base}${url}?${serializedParams}`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${process.env.MOVIE_DB_TOKEN}`
|
||||
},
|
||||
|
||||
@@ -174,6 +174,22 @@ export const trailers = async ({
|
||||
.then((data) => data.results);
|
||||
};
|
||||
|
||||
export const torrentFiles = (magnet: string): Promise<Video[]> => {
|
||||
return http
|
||||
.get<{ name: string; subtitles: Subtitles[] }[]>('/files', { params: { magnet } }, process.env.TRACKER_PROXY_BASE)
|
||||
.then((files) =>
|
||||
files.map((file) => {
|
||||
const base = `${process.env.TRACKER_PROXY_BASE}/stream?magnet=${encodeURIComponent(magnet)}}`;
|
||||
|
||||
return {
|
||||
name: file.name,
|
||||
src: `${base}&filename=${encodeURIComponent(file.name)}`,
|
||||
subtitles: file.subtitles
|
||||
};
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
export const YTSTorrents = async ({
|
||||
query,
|
||||
sort,
|
||||
|
||||
@@ -53,6 +53,7 @@ export class YTS {
|
||||
title: `${movie.title_english} ${torrent.quality ? `[${torrent.quality}]` : ''}`,
|
||||
seeders: torrent.seeds,
|
||||
size: torrent.size,
|
||||
type: torrent.type,
|
||||
magnet: `magnet:?xt=urn:btih:${torrent.hash}&dn=${encodeURIComponent(query)}&tr=${trackers.join('&tr=')}`
|
||||
};
|
||||
}) || []
|
||||
|
||||
Reference in new issue
Block a user