Added type definitions for torrent-search-api

This commit is contained in:
Nicolas GIRARDIN
2018-10-26 20:43:35 +02:00
parent 0e0e730ec8
commit 302bb8a483
4 changed files with 214 additions and 0 deletions

90
types/torrent-search-api/index.d.ts vendored Normal file
View File

@@ -0,0 +1,90 @@
// Type definitions for torrent-search-api 2.0
// Project: https://github.com/JimmyLaurent/torrent-search-api#readme
// Definitions by: Nicolas Girardin <https://github.com/ngirardin>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export interface Torrent {
title: string;
time: string;
size: string;
magnet: string;
desc: string;
provider: string;
}
export interface TorrentProvider {
name: string;
baseUrl: string;
requireAuthentification: boolean;
supportTokenAuthentification: boolean;
supportCookiesAuthentification: boolean;
supportCredentialsAuthentification: boolean;
loginUrl: string;
loginQueryString: string;
searchUrl: string;
categories: any; // FIXME {key: [string]}
defaultCategory: string;
resultsPerPageCount: number;
itemsSelector: string;
itemSelectors: any; // FIXME {key: [string]}
paginateSelector: string;
torrentDetailsSelector: string;
enableCloudFareBypass: boolean;
headers: any; // FIXME {key:[string]}
magnetSelector: string;
autoFixUnstableUrl: boolean;
}
export function lodProvider(providerParam: string): void;
export function loadProvider(providerParam: string | TorrentProvider): void;
export function addProvider(provider: string): void;
export function loadProviders(...args: string[]): void;
export function loadProviders(...args: TorrentProvider[]): void;
export function removeProvider(providerName: string): void;
export function enableProvider(providerName: string, args?: string[]): void;
export function enableProvider(providerName: string, ...args: string[]): void;
export function enablePublicProviders(): void;
export function disableProvider(providerName: string): void;
export function disableAllProviders(): void;
export function getProviders(): TorrentProvider[];
export function getActiveProviders(): TorrentProvider[];
export function isProviderActive(name: string): boolean;
export function search(
query: string,
category: string,
limit: number
): Promise<Torrent[]>;
export function search(
providers: string[],
query: string,
category: string,
limit: number
): Promise<Torrent[]>;
export function getTorrentDetails(torrent: Torrent): Promise<string>;
export function downloadTorrent(
torrent: Torrent,
filenamePath?: string
): Promise<string>;
export function overrideConfig(
providerName: string,
newConfig: TorrentProvider
): Promise<string>;
export function getMagnet(torrent: Torrent): Promise<string>;
export function getProvider(name: string, throwOnError: boolean): string;

View File

@@ -0,0 +1,107 @@
import TorrentSearchApi = require("torrent-search-api");
// $ExpectType void
TorrentSearchApi.enableProvider("Torrent9");
// $ExpectType Promise<Torrent[]>
TorrentSearchApi.search("1080", "Movies", 20);
// $ExpectType TorrentProvider[]
TorrentSearchApi.getProviders();
// $ExpectType TorrentProvider[]
TorrentSearchApi.getActiveProviders();
// $ExpectType void
TorrentSearchApi.enablePublicProviders();
// $ExpectType void
TorrentSearchApi.enableProvider("Torrent9");
// $ExpectType void
TorrentSearchApi.enableProvider("IpTorrents", ["uid=XXX;", "pass=XXX;"]);
// $ExpectType void
TorrentSearchApi.enableProvider("IpTorrents", "USERNAME", "PASSWORD");
// $ExpectType void
TorrentSearchApi.enableProvider("xxx", "TOKEN");
// $ExpectType void
TorrentSearchApi.disableProvider("TorrentLeech");
// $ExpectType void
TorrentSearchApi.disableAllProviders();
// $ExpectType boolean
TorrentSearchApi.isProviderActive("1337x");
// $ExpectType Promise<Torrent[]>
TorrentSearchApi.search("1080", "Movies", 20);
// $ExpectType Promise<Torrent[]>
TorrentSearchApi.search(["IpTorrents", "Torrent9"], "1080", "Movies", 20);
const torrent = {
title: "tile",
time: "time",
size: "size",
magnet: "magnet",
desc: "desc",
provider: "provider"
};
// $ExpectType Promise<string>
TorrentSearchApi.getTorrentDetails(torrent);
// $ExpectType Promise<string>
TorrentSearchApi.getMagnet(torrent);
// $ExpectType Promise<string>
TorrentSearchApi.downloadTorrent(torrent);
// $ExpectType Promise<string>
TorrentSearchApi.downloadTorrent(torrent, "file.mp4");
const provider = {
name: "name",
baseUrl: "baseUrl",
requireAuthentification: true,
supportTokenAuthentification: true,
supportCookiesAuthentification: true,
supportCredentialsAuthentification: true,
loginUrl: "loginUrl",
loginQueryString: "loginQueryString",
searchUrl: "searchUrl",
categories: {
All: "all",
Movies: "movies"
},
defaultCategory: "all",
resultsPerPageCount: 50,
itemsSelector: ".selector",
itemSelectors: {
title: ".title",
seeds: ".seeds",
peers: ".peers",
size: ".size",
desc: ".desc"
},
paginateSelector: ".page",
torrentDetailsSelector: ".detail",
enableCloudFareBypass: true,
headers: {
UserAgent: "ua"
},
magnetSelector: ".magnet",
autoFixUnstableUrl: true
};
// $ExpectType void
TorrentSearchApi.loadProvider(provider);
// $ExpectType void
TorrentSearchApi.loadProviders("/path/to/provider");
// $ExpectType void
TorrentSearchApi.removeProvider("MyCustomProvider");

View File

@@ -0,0 +1,16 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es6"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": ["../"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": ["index.d.ts", "torrent-search-api-tests.ts"]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }