-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathaddon.js
105 lines (85 loc) · 3.9 KB
/
addon.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
const { addonBuilder } = require("stremio-addon-sdk");
const magnet = require("magnet-uri");
const manifest = {
"id": "org.stremio.helloworld",
"version": "1.0.0",
"name": "Hello World Addon",
"description": "Sample addon providing a few public domain movies",
// set what type of resources we will return
"resources": [
"catalog",
"stream"
],
"types": ["movie", "series"], // your add-on will be preferred for those content types
// set catalogs, we'll be making 2 catalogs in this case, 1 for movies and 1 for series
"catalogs": [
{
type: 'movie',
id: 'helloworldmovies'
},
{
type: 'series',
id: 'helloworldseries'
}
],
// prefix of item IDs (ie: "tt0032138")
"idPrefixes": [ "tt" ]
};
const dataset = {
// fileIdx is the index of the file within the torrent ; if not passed, the largest file will be selected
"tt0032138": { name: "The Wizard of Oz", type: "movie", infoHash: "24c8802e2624e17d46cd555f364debd949f2c81e", fileIdx: 0 },
"tt0017136": { name: "Metropolis", type: "movie", infoHash: "dca926c0328bb54d209d82dc8a2f391617b47d7a", fileIdx: 1 },
// night of the living dead, example from magnet
"tt0063350": fromMagnet("Night of the Living Dead", "movie", "magnet:?xt=urn:btih:A7CFBB7840A8B67FD735AC73A373302D14A7CDC9&dn=night+of+the+living+dead+1968+remastered+bdrip+1080p+ita+eng+x265+nahom&tr=udp%3A%2F%2Ftracker.publicbt.com%2Fannounce&tr=udp%3A%2F%2Fglotorrents.pw%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.openbittorrent.com%3A80%2Fannounce"),
"tt0051744": { name: "House on Haunted Hill", type: "movie", infoHash: "9f86563ce2ed86bbfedd5d3e9f4e55aedd660960" },
"tt1254207": { name: "Big Buck Bunny", type: "movie", url: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4" }, // HTTP stream
"tt0031051": { name: "The Arizona Kid", type: "movie", ytId: "m3BKVSpP80s" }, // YouTube stream
"tt0137523": { name: "Fight Club", type: "movie", externalUrl: "https://www.netflix.com/watch/26004747" }, // redirects to Netflix
"tt1748166:1:1": { name: "Pioneer One", type: "series", infoHash: "07a9de9750158471c3302e4e95edb1107f980fa6" }, // torrent for season 1, episode 1
};
// utility function to add from magnet
function fromMagnet(name, type, uri) {
const parsed = magnet.decode(uri);
const infoHash = parsed.infoHash.toLowerCase();
const tags = [];
if (uri.match(/720p/i)) tags.push("720p");
if (uri.match(/1080p/i)) tags.push("1080p");
return {
name: name,
type: type,
infoHash: infoHash,
sources: (parsed.announce || []).map(function(x) { return "tracker:"+x }).concat(["dht:"+infoHash]),
tag: tags,
title: tags[0], // show quality in the UI
}
}
const builder = new addonBuilder(manifest);
// Streams handler
builder.defineStreamHandler(function(args) {
if (dataset[args.id]) {
return Promise.resolve({ streams: [dataset[args.id]] });
} else {
return Promise.resolve({ streams: [] });
}
})
const METAHUB_URL = "https://images.metahub.space"
const generateMetaPreview = function(value, key) {
// To provide basic meta for our movies for the catalog
// we'll fetch the poster from Stremio's MetaHub
// see https://github.com/Stremio/stremio-addon-sdk/blob/master/docs/api/responses/meta.md#meta-preview-object
const imdbId = key.split(":")[0]
return {
id: imdbId,
type: value.type,
name: value.name,
poster: METAHUB_URL+"/poster/medium/"+imdbId+"/img",
}
}
builder.defineCatalogHandler(function(args, cb) {
// filter the dataset object and only take the requested type
const metas = Object.entries(dataset)
.filter(([_, value]) => value.type === args.type)
.map(([key, value]) => generateMetaPreview(value, key))
return Promise.resolve({ metas: metas })
})
module.exports = builder.getInterface()