Giter Club home page Giter Club logo

jwplatform-node's Introduction

JW Platform API

Node client for interfacing with the JW Platform management API.

Note that this is not developed for client side use, as it requires your API Key and Secret. For your own security, please restrict usage to server side applications.

Install

Install the package with:

yarn add jwplatform

Example Usage

const JWPlatformAPI = require('jwplatform');

const jwApi = new JWPlatformAPI({ apiKey: 'INSERT API KEY', apiSecret: 'INSERT API SECRET'});

jwApi.videos.show({ video_key: 'INSERT VIDEO KEY' }).then((response) => { 
    // handle response data 
});

Upload

The JWPlatform library contains a single method for using the single upload method.

const JWPlatformAPI = require('jwplatform');

const jwApi = new JWPlatformAPI({ apiKey: 'INSERT API KEY', apiSecret: 'INSERT API SECRET'});

jwApi.upload({ videoOptions }, '/path/to/file')

Demo

To run a demo of this client, run the following command:

API_KEY='INSERT API KEY' \
API_SECRET='INSERT API SECRET' \
// Different routes will need different ID's. Refer to documentation for required fields.
VIDEO_KEY='INSERT VIDEO ID' \
// i.e. videos/list or videos/conversions/list
DEMO = '{RESOURCE}/{ACTION}'
make demo

Note that only LIST and SHOW actions are available.

Supported Operations

All API methods documentated on the API are available in this client. Please refer here.

Testing

The JW Platform client is tested using chai and mocha. To run the test suite, run the command yarn test.

Coverage reports are available through Istanbul.js, and can be accessed by running yarn coverage.

Linting

This repository is lintned using ESLint and Prettier. Two commands are available for linting:

  • yarn lint: lints projects, without fixing any issues
  • yarn lint --fix: runs and fixes lint issues

License

This code is provided under the Apache 2.0 License.

jwplatform-node's People

Contributors

dependabot[bot] avatar ksindi 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

jwplatform-node's Issues

I can't upload video with large .m4

it will successful when i'm uploaded the small size of video .mp4.
but it found problem when i upload video with 1.4gb.

Version
"jwplatform": "0.0.5",

Error log

{ RequestError: Error: write EPIPE
    at new RequestError (/Users/woraponprathuangthip/backend-baan-doctor/node_modules/request-promise-core/lib/errors.js:14:15)
    at Request.plumbing.callback (/Users/woraponprathuangthip/backend-baan-doctor/node_modules/request-promise-core/lib/plumbing.js:87:29)
    at Request.RP$callback [as _callback] (/Users/woraponprathuangthip/backend-baan-doctor/node_modules/request-promise-core/lib/plumbing.js:46:31)
    at self.callback (/Users/woraponprathuangthip/backend-baan-doctor/node_modules/request/request.js:185:22)
    at Request.emit (events.js:203:15)
    at Request.EventEmitter.emit (domain.js:448:20)
    at Request.onRequestError (/Users/woraponprathuangthip/backend-baan-doctor/node_modules/request/request.js:877:8)
    at ClientRequest.emit (events.js:198:13)
    at ClientRequest.EventEmitter.emit (domain.js:448:20)
    at Socket.socketErrorListener (_http_client.js:401:9)
    at Socket.emit (events.js:198:13)
    at Socket.EventEmitter.emit (domain.js:448:20)
    at errorOrDestroy (internal/streams/destroy.js:107:12)
    at onwriteError (_stream_writable.js:436:5)
    at onwrite (_stream_writable.js:461:5)
    at _destroy (internal/streams/destroy.js:49:7)
    at Socket._destroy (net.js:614:3)
    at Socket.destroy (internal/streams/destroy.js:37:8)
    at WriteWrap.afterWrite (net.js:791:10)
  name: 'RequestError',
  message: 'Error: write EPIPE',
  cause:
   { Error: write EPIPE
       at WriteWrap.afterWrite (net.js:789:14) errno: 'EPIPE', code: 'EPIPE', syscall: 'write' },
  error:
   { Error: write EPIPE
       at WriteWrap.afterWrite (net.js:789:14) errno: 'EPIPE', code: 'EPIPE', syscall: 'write' },
  options:
   { method: 'POST',
     uri: 'http://upload.jwplatform.com/v1/videos/upload',
     json: true,
     formData: { file: [ReadStream] },
     qs:
      { key: 'b1vJ7OXR',
        token: '84d0721dc16653e0ba4b318541c549f2786f371ec40',
        api_format: 'json' },
     callback: [Function: RP$callback],
     transform: undefined,
     simple: true,
     resolveWithFullResponse: false,
     transform2xxOnly: false },
  response: undefined }

packages

"dependencies": {
        "aws-sdk": "^2.736.0",
        "bcryptjs": "^2.4.3",
        "body-parser": "^1.19.0",
        "compression": "^1.7.4",
        "connect-timeout": "^1.9.0",
        "cors": "^2.8.5",
        "dotenv": "^8.2.0",
        "express": "^4.17.1",
        "fs": "0.0.1-security",
        "jwplatform": "0.0.5",
        "jwt-simple": "^0.5.6",
        "lodash.countby": "^4.6.0",
        "mjml": "^4.7.0",
        "mkdirp": "^1.0.4",
        "multer": "^1.4.2",
        "multer-s3": "^2.9.0",
        "nodemailer": "^6.4.11",
        "passport": "^0.4.1",
        "passport-jwt": "^4.0.0",
        "path": "^0.12.7",
        "pg": "^8.3.0",
        "sequelize": "^6.3.4"
    },
    "devDependencies": {
        "@babel/cli": "^7.10.4",
        "@babel/core": "^7.10.4",
        "@babel/node": "^7.10.4",
        "@babel/plugin-transform-runtime": "^7.10.4",
        "@babel/preset-env": "^7.10.4",
        "babel-eslint": "^10.1.0",
        "eslint": "^7.4.0",
        "nodemon": "^2.0.4"
    }

How i fix it? set time out or set some option?
it will fail when upload until 4 minute.

image

replacing existing video

When using

const response = await path == null ? jwApi.videos.update(data) : jwApi.videos.update(data, path)

the first case i.e. updating the title and description of a specific video works fine.
But replacing the video doesn't actually replace it even though everything else gets updated as expected.
Am I calling the update function incorrectly?

TypeError: fs.createReadStream is not a function

I used Jwplatform to upload a single video. But I am getting this warning and video is not uploading to JW player. I am trying to upload a video from the local machine.

async onUpload() {
const filePath = '/Downloads/test.mp4';

await jwApi
.upload(
{
title: 'My new video!',
},
filePath
)
.then(resp => {
console.log(resp);
})
.catch(e => console.warn(e));

}

Screen Shot 2020-08-27 at 1 28 13 PM

create a video through the api with a download_url property

I'm trying to use this library to publish some video's through a script. Basicly my code is as follows:

const jwApi = new JWPlatformAPI({ apiKey: JWPLAYER_API_KEY, apiSecret: JWPLAYER_SECRET });

const video = "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"

const jwResponse = await jwApi.videos.create({ title: 'my video', download_url: video });

As a response i get

{ jwResponse:
   { status: 'ok',
     media: { type: 'video', key: 'GTlEutz5' },
     link:
      { path: '/v1/videos/upload',
        query: [Object],
        protocol: 'http',
        address: 'upload.jwplatform.com' },
     rate_limit: { reset: 1573036920, limit: 60, remaining: 59 } } }

where I did not expect to receive an upload url, I did expect that the supplied video url was used to create a jw-hosted video (cfr. https://developer.jwplayer.com/jw-platform/docs/developer-guide/management-api/uploading-videos/)

Am I using this library in a wrong way to accomplish this ?

API_KEY ERROR

Please i need help.
I have created an accound and added a credential on V2 section, where i am given an API KEY and Secrete , I then used the basic fuction tion intiate the platform.
const JWPlatformAPI = require('jwplatform');
const jwApiInstance = new JWPlatformAPI({
apiKey:'tivcast-player',
apiSecret: 'XXXXXXXXXXXXXXXX',
});

I tried to check my players
jwApiInstance.players.list().then(response => console.log(response));

I got this error:
Unhandled rejection StatusCodeError: 400 - {"status":"error","code":"ParameterInvalid","title":"Invalid Parameter","message":"api_key: API key tivcast-player is invalid"}

Direct S3 upload from browser has CORS error

I can create a s3 upload link using this:

  const res = await jwApi.videos.create({
    upload_method: 's3',
  });

This returns me a url:

https://jwplatform-upload.s3-accelerate.amazonaws.com/secretlink...

But I cannot use this to directly upload from the browser as there's a CORS error:

Access to XMLHttpRequest at 'https://jwplatform-upload.s3-accelerate.amazonaws.com/secretlink' from origin 'https://mywebsite.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Is there any way I can do direct browser uploading to the s3 url? Or do I have to upload the file somewhere else first?

Resumable Upload - Failing because missing parameter X-Session-ID

I'm trying to implement resumable upload but when I start POSTing file data over to the url:

https://upload.jwplatform.com/v1/videos/upload/resumable?api_format=json&key=secretkey&redirect_address=myaddress&redirect_query.uploaded=1&resumableChunkNumber=2&resumableChunkSize=1048576&resumableCurrentChunkSize=1048576&resumableTotalSize=10546620&resumableType=video%2Fmp4&resumableIdentifier=10546620-BBBmp4&resumableFilename=BBB.mp4&resumableRelativePath=BBB.mp4&resumableTotalChunks=10

I get a 400 error:

{"status": "error", "code": "ParameterMissing", "title": "Missing Parameter", "message": "X-Session-ID header is missing"}

What is this x-session-id that I need to pass?

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.