Giter Site home page Giter Site logo

platform-sdk-js's Introduction

platform-sdk-js

SDK for online torrent streaming

Features

  1. Online torrent content streaming without waiting for full download
  2. On-the-fly content transcoding
  3. Downloading torrent as ZIP-archive
  4. Subtitle transcoding, srt to vtt
  5. OpenSubtitles support
  6. Streaming of external resources (including transcoding)

Supported formats

  • Video: avi, mkv, mp4, webm, m4v
  • Audio: mp3, wav, ogg, flac, m4a
  • Images: png, gif, jpg, jpeg
  • Subtitles: srt, vtt

Prerequisites

Before moving further we must be sure that webtor backend api is already installed. Just follow this guide to setup all the things.

Installation

npm install @webtor/platform-sdk-js

or

yarn add @webtor/platform-sdk-js

Basic usage

Just a simple example of fetching torrent by magnet-uri, getting streaming url and stats:

import webtor from '@webtor/platform-sdk-js';

const sdk = webtor({
  apiUrl: '...',
});

const magnetUri = '...';

const torrent = await sdk.magnet.fetchTorrent(magnetUri);

const expire = 60*60*24;

await sdk.torrent.push(torrent, expire);

const seeder = sdk.seeder.get(torrent.infoHash);

const filePath = torrent.files[0].path;

const url = await seeder.streamUrl(filePath);
console.log(url);

// NOTE: stats will become available only after content url access
seeder.stats(filePath, (path, data) => {
  console.log(data);
});

You can find fully working example here!

Initialization

const sdk = webtor(options)

options should be the following:

{
  apiUrl: String,              // API url (required)
  apiKey: String,              // API key
  downloadUrl: String,         // All download urls will contain this location
  tokenUrl: String,            // API will get access-token from this location
  tokenRenewInterval: Number,  // Renews access-token after specific period in ms
  grpcDebug: Boolean,          // If enabled shows grpc-web debug output
  statsRetryInterval: Number,  // If stats not available for this file it will retry after specific period in ms (default=3000)
  getToken: function() Promise // If defined custom token-function will be used 
}

sdk.torrent

Provides functions for storing and retriving torrent-files.

sdk.torrent.fromUrl(url)

Fetches parsed torrent from specific url. Be sure that appropriate CORS-headers are set on server-side in case of cross-site request (Access-Control-Allow-Origin: *).

sdk.torrent.pull(infoHash)

Pulls parsed torrent by infoHash from torrent-store.

sdk.torrent.push(torrent, expire)

Pushes parsed torrent to torrent-store with specific expiration time in seconds. We can use any parsed torrent generated by parse-torrent there.

sdk.torrent.touch(torrent, expire)

Just renews expiration date of torrent-file.

sdk.magnet

Provides functions for working with magnet-urls.

sdk.magnet.fetchTorrent(magnet)

Fetches parsed torrent by magnet-uri.

sdk.seeder

Provides functions for retriving and streaming torrent-content.

const seeder = sdk.seeder.get(infoHash)

Returns seeder instance for the specific torrent stored in torrent-store.

seeder.url(path)

Returns url for original source file.

Returns url capable for web-streaming. viewSettings should be provided only in case of content trnascoding. Possible viewSettings:

{
  a: Number,   // Selected audio channel
  s: Number,   // Selected subtitle channel
}

Returns subtitle-url capable for web-streaming. Can be used only for hls-transcoded content. viewSettings should be provided only in case of content trnascoding. Possible viewSettings:

{
  a: Number,   // Selected audio channel
  s: Number,   // Selected subtitle channel
}

Returns FFmpeg probing data. If content should not be transcoded only empty object {} will be returned.

seeder.downloadUrl(path)

Returns download url.

seeder.zipUrl(path)

Returns download url of zip-archive. Generates zip-archive of all files under directory and subdirectories specified by the path.

Returns object that includes all subtitles from OpenSubtitles.org. Automatically generates streaming urls for every subtitle (srt => vtt encoding).

const statClient = seeder.stats(path, function(path, data) { ... })

Receives status of specific file. Possible data:

{
  total: Number     // Number of total bytes
  completed: Number // Number of completed bytes
  peers: Number     // Total number of peers
  piecesList: []    // Array of pieces
}

Also returns instance of stat client.

statClient.close()

Closes stat client

sdk.ext

Provides functions for retriving and streaming external resources.

sdk.ext.url(url)

Returns url for original external file proxied by the api. Can resolve CORS-issues.

sdk.ext.streamUrl(url, viewSettings = {})

Same as seeder.streamUrl but for external resource.

sdk.ext.streamSubtitleUrl(url, viewSettings = {})

Same as seeder.streamSubtitleUrl but for external resource.

sdk.ext.mediaInfo(url)

Same as seeder.mediaInfo but for external resource.

sdk.ext.openSubtitles(url)

Same as seeder.openSubtitles but for external resource.

platform-sdk-js's People

Contributors

vintikzzz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

platform-sdk-js's Issues

Can't push torrent into webtor service

Ok. Here is:

 kubectl get po -n webtor
NAME                                READY   STATUS    RESTARTS   AGE
content-prober-ddcfcf847-h8c2s      1/1     Running   2          21h
external-proxy-6c6989656-fwwgh      1/1     Running   0          21h
magnet2torrent-5df84c855-9t9m2      1/1     Running   0          21h
redis-master-0                      1/1     Running   0          21h
srt2vtt-67b77758d4-mzrxc            1/1     Running   0          21h
torrent-archiver-8475fb495b-l56xz   1/1     Running   0          21h
torrent-http-proxy-62x8x            1/1     Running   0          21h
torrent-store-65c6bd4659-dbq86      1/1     Running   1          21h
video-info-tn8pr                    1/1     Running   0          21h

And

minikube service torrent-http-proxy --url -n webtor
http://xxx:30604
http://xxx:32343

I don't understand why is there two api links.

But next:

 curl -I  http://xxx:30604
HTTP/1.1 500 Internal Server Error
Date: Sun, 22 Mar 2020 09:07:53 GMT

curl -I  http://xxx:32343
curl: (8) Weird server reply

And JS console:
Uncaught (in promise) failed to push torrent code=14

Thank you.

No response.

I don't know what's wrong...
On first server - all is done. Today moved to other machine, and no have response from webtor service.
I am see you a make some changes, but this doesn't look affect any related stuff.
Ok, affter 5 minutes of loading torrent to service is code 10 error.
Any ideas?

CORS configuration

Hello sir, I would like to thank you for this work.

I've install helm-charts backend on my VPS, it's running correctly. Now I'm trying to run the example provided in this repo but I'm getting CORS issues.

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://x.x.x.x:30180//store/TorrentStore/Pull. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing)

I can't find where I can add CORS config. Is there a server config file that I need to be aware of?

Thank you in advance for your help and support.

fix ext/openSubtitles

Hi! i found a little bug in the file ext.js.

there is many this.sdk and should be self.sdk!

`const pathParse = require('path-parse');
const Url = require('url-parse');

export default function(params, sdk) {
const self = {params, sdk};
return {
async url(extUrl, metadata = {}, params = {}) {
params = Object.assign(self.params, params);
const url = new Url(params.apiUrl);
const fileName = pathParse(extUrl).base;
const encodedUrl = encodeURIComponent(btoa(extUrl));
const pathname = '/ext/' + encodedUrl + '/' + fileName;
url.set('pathname', pathname);
const query = await self.sdk.util.makeQuery(metadata, params);
url.set('query', query);
return url;
},
async streamSubtitleUrl(extUrl, viewSettings = {}, metadata = {}, params = {}) {
const url = await this.url(extUrl, metadata, params);
return self.sdk.util.streamSubtitleUrl(url, viewSettings);
},
async streamUrl(extUrl, viewSettings = {}, metadata = {}, params = {}) {
let url = await this.url(extUrl, metadata, params);
return self.sdk.util.streamUrl(url, viewSettings);
},
async mediaInfo(extUrl, viewSettings = {}, metadata = {}, params = {}) {
const url = await this.url(extUrl, metadata, params);
return await self.sdk.util.mediaInfo(url, viewSettings);
},
async openSubtitles(extUrl, metadata = {}, params = {}) {
const url = await this.url(extUrl, metadata, params);
return await self.sdk.util.openSubtitles(url);
},
};
};`

this is working code. i cant do a pull request becouse permission.

Advanced usage

Could you provide advanced usage example?

Decoding if needed, loading attached subtitles.. etc

Download zip file is not working

Maybe this my misstake, maybe this need additional software like unzip, p7zip or something?
When i am get the zip url, this give empty archive.

Embedded Ads

Hi,

I was testing the embed-sdk-js and it works well but I am disuaded by the invasive ads (multiple popups + banners within the player itself). By self-hosting the backend (helm-charts) and using this repo (platform-sdk-js), will that give me a player clear from advertisements and give me the ability to completely customise it? Including perhaps adding one's own ads to the player for example?

Thanks - nice project btw! Much better than webtorrent which I can never get to work, seemingly because the regular torrent peers + seeders don't seem to apply to webtorrent. Seems there's a completely separate protocol for seeders + peers on webtorrent weirdly so 99% of the time it means there's 0..

Site is Down

The Webtor Site is down. Showing an Error 521 powered by Cloudlflare.

Torrent size limit?

Just wanted to know if you are enforcing any torrent size limit, to prevent misuse of the platform.

Question about api

Hi!! nice work with this!!
i have a little question.
which api do you mean in the configurations?? there is a repo?? the only way is to use https://webtor.io?? thankyou!!!

Plans for the future?

Hello! Thank you for this project!
Do you plan to keep it up for free in the future? Can we rely on your webtor servers?

If not, is there any paid plan available?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.