Skip to content

Instantly share code, notes, and snippets.

@roc-ld
Last active July 29, 2022 08:58
Show Gist options
  • Select an option

  • Save roc-ld/9973d11ab537ab32a5224294a6c2dcfe to your computer and use it in GitHub Desktop.

Select an option

Save roc-ld/9973d11ab537ab32a5224294a6c2dcfe to your computer and use it in GitHub Desktop.
/*{
"name": "Local see Package",
"id": "self.private.me.local.see",
"version": 1,
"classPath": "localSee.LocalSeeProviderPackage"
}
*/
/**
* Your package js file must contain a manifest declaration at the very beginning of the file.
* This declaration must be pure json and must be inside a comment as exactly shown above at the top of this file.
*
* Manifest properties
* name: Name of your package.
*
* id: An unique id to identify your package universally. Colliding this id with other packages
* will override your package with some other package with the same id.
*
* version: Version of your package. Must be an int and bumped every new release.
*
* classPath: A fully qualified path to your SourceProviderPackage class that implements createBundle().
* Without this your package cannot be initialized.
*
* [Optional]
* permaUrl: A permanent url to your package. This url will be pinged to check for updates.
* It's highly recommended that you provide this.
*
* Your package will run inside a browser.
* Your package must follow the UMD (https://github.com/umdjs/umd) module standard as seen below.
* Your package must not use any external dependencies that cannot run on a browser.
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.localSee = {})));
}
(this, (function (exports) {
'use strict';
/**
*
* Each provider package must implement the two following methods
* createBundle()
* createSourceProvider()
* as documented below.
* Note: These 2 methods are called in different threads in different
* environments. Any variable you store in one method will not be available in other.
*/
class LocalSeeProviderPackage {
/**
* Must have a parameter-less constructor
*/
constructor() {
this.sourceProviders = [new LocalSeeSourceProvider()];
}
/**
* Called at the very beginning of source search.
* Provider package must return a promise of a bundle.
* The package will have less than 5 seconds to resolve this promise.
* Package MUST not search for sources here. This is where package should return cached results if it has any.
* @param env Explained later.
* @param request Explained later.
*/
createBundle(env, request) {
/**
* A promise
*/
return new Promise((resolve, reject) => {
/**
* A new bundle object
*/
let bundle = {
/**
* Cached sources that are already available without search.
*/
sources: [],
/**
* Metadata of providers which will need to search for sources.
* This metadata will be later passed on to the createSourceProvider() method
* to initialize a SourceProvider and search on different threads for better performance
*/
sourceProviderMetadatas: this.sourceProviders.map(i => i.metadata)
};
resolve(bundle);
});
}
/**
* Create an instance of a SourceProvider that implements search(env,searchRequest);
* @param env Explained later.
* @param metadata The metadata returned in createBundle() call.
*/
createSourceProvider(env, metadata) {
/**
* Here we are just matching the name of the provider supplied in metadata object
* and returning that instance from our already initialized list of source providers
*/
return this.sourceProviders.filter(x => x.metadata.name == metadata.name)[0];
}
}
/**
* Each SourceProvider must implement a
* search() method as defined below
*/
class LocalSeeSourceProvider {
constructor() {
/**
* Metadata about the source provider
*/
this.metadata = {
name: 'LocalSeeSourceProvider',
/**
* All sources produced by this provider will appear as premium
* Default is true
*/
premium: false,
/**
* Defines whether torrent resolvers should be executed after
* this provider returns sources.
*/
containsTorrents: false,
/**
* [Optional] true/false
* Supply this flag when possible so that search can be optimized at
* runtime depending on debrid service is available or not
*/
requiresDebrid: true,
/**
* [Optional] json object
* Extra data space for encoding any data you might later need to initialize a source provider.
*/
data: {
/**
* For example here we storage an api key
* This data will be available to you in createSourceProvider(...) method
*/
"apiKey": "XXXX"
}
};
}
/**
* Returns a promise that is resolved/rejected to find sources
* @param env
* @param request
*/
search(env, request) {
return new Promise((resolve, reject) => {
/**
* The env object gives you access to various capabilities
* such as
* HttpClient: Make http requests to the internet
* App: Information about the app
* User: Information about user
*
* [Pending implementation]
* PersistentStorage: Store persistent data, such as cookies
*
* [Pending implementation]
* SessionStorage [Not implemented yet]: Store temporary data that is gone after an app reboot
*/
/**
* User object contains data about the user
*/
var user = env.user;
/**
* Contains information about the app
*/
var app = env.app;
/**
* string: A jwt token [algorithm: RS256] created by the app for your package which
* can be used as an authentication tool.
*
* You can verify the authenticity of this token
* by verifying the signature of this token
* with the apps public key for source provider packages.
* This can be found on the official developer documentation site.
*
*/
/**
* Creating an axios instance to make http requests.
* Documentation for axios can be found here
* https://github.com/axios/axios
*
* All http requests must use an axios instance created
* by httpClientFactory as shown below.
*
* Everything else such as
* fetch, XmlHttpRequest will fail.
*/
//Create a new array of sources
let sources = [];
sources.push({
url: "https://b.baobuzz.com/ipfs/536676.m3u8?sign=3574cd95c9737f88b9243e2e68421a67",
});
//Resolve this promise with sources found
resolve(sources);
});
}
}
exports.LocalSeeProviderPackage = LocalSeeProviderPackage;
Object.defineProperty(exports, '__esModule', {
value: true
});
})));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment