Giter Site home page Giter Site logo

jwplatform-py's Introduction

JW Platform API Client

A Python client library for accessing JW Platform API. Visit JW Player Developer site for more information about JW Platform API.

Installation

JW Platform API library can be installed using pip:

pip install jwplatform

Library has Requests package as dependency. It will be installed automatically when installing using pip.

Usage

Import jwplatform library:

from jwplatform.client import JWPlatformClient

Initialize jwplatform client instance. API keys can be created in the JW Platform dashboard on the API Credentials page. Copy the secret value to use here.

jwplatform_client = JWPlatformClient('API_SECRET')

Make an API request:

response = jwplatform_client.Media.get(site_id='SITE_ID', media_id='MEDIA_ID')

If API request is successful, response variable will contain dictionary with information related to the response and the actual video data in response.json_body:

>>> response.json_body
{"id": "Ny05CEfj",
 "type": "media",
 "created": "2019-09-25T15:29:11.042095+00:00",
 "last_modified": "2019-09-25T15:29:11.042095+00:00",
 "metadata": {
   "title": "Example video",
   "tags": ["new", "video"]
 }}

JW Platform API library will raise exception inherited from jwplatform.errors.APIError if anything goes wrong. For example, if there is no media with the specified media_id requesting it will raise jwplatform.errors.NotFoundError:

try:
    jwplatform_client.Media.get(site_id='SITE_ID', media_id='BAD_MEDIA_ID')
except jwplatform.errors.NotFoundError as err:
    print(err)

For the complete list of available exception see jwplatform/errors.py file.

List calls allow for (optional) querying and filtering. This can be done by passing the query parameters as a dict to the query_params keyword argument on list calls:

response = jwplatform_client.Media.list(
  site_id="SITE_ID",
  query_params={
      "page": 1,
      "page_length": 10,
      "sort": "title:asc",
      "q": "external_id: abcdefgh",
  },
)

All query parameters are optional. page, page_length, and sort parameters default to 1, 10, and "created:dsc", respectively. The q parameter allows for filtering on different attributes and may allow for AND/OR querying depending on the resource. For full documentation on the query syntax and endpoint specific details please refer to developer.jwplayer.com.

Source Code

Source code for the JW Platform API library provided on GitHub.

V1 Client

The V1 Client remains available for use, but is deprecated. We strongly recommend using the V2 Client when possible.

To use the V1 Client, import the Client from the v1 namespace.

import jwplatform.v1

api_client = jwplatform.v1.Client('SITE_ID', 'V1_API_SECRET')

License

JW Platform API library is distributed under the MIT license.

jwplatform-py's People

Contributors

chris97425 avatar dannyjgibson avatar dashtodd avatar dylancaponi avatar emptyflash avatar erdos4d avatar eric-weaver avatar gtwohig avatar jdgumz avatar justiniso avatar ksindi avatar onebrownsound avatar polishmatt avatar rjw57 avatar saurabhc123 avatar sergeylashin avatar shwetamurthy20 avatar sol1000 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

Watchers

 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

jwplatform-py's Issues

Cannot update source_url via client.Media or PUT request

Updating a source_url media object doesn't seem to work correctly.

Here's below a snippet to reproduce

from jwplatform.client import JWPlatformClient

API_V2_SECRET = YOUR_API_SECRET
MEDIA_ID = YOUR_MEDIA_ID
SRC_URL = "https://example_new_source_url.m3u8"


new_media = {
        'upload': {
            'method': 'external',
            'mime_type': 'application/vnd.apple.mpegurl',
            'source_url': SRC_URL,
        },
        'metadata': {
            'title': 'Test',
            'description': '',
            'duration': 0,
            'author': '',
            'permalink': "",
            'category': 'Movies',
            'tags': [],
            'custom_params': {},
        }
    }

client = JWPlatformClient(API_V2_SECRET)

First way with client.Media.update method

media = client.Media.update(
        site_id=SITE_ID,
        media_id=MEDIA_ID,
        body=new_media
    ).json_body

Second way with simple PUT request

media = client.request(
        'PUT',
        path=f"/v2/sites/{SITE_ID}/media/{MEDIA_ID}/reupload/",
        body=new_media['upload']
    ).json_body

In both cases, the request succed with a 200 response but the media object still returns the former source_url as if it was not correctly updated.

Cannot recreate a movie after deleting it

Hello.

For our specific need, we need to create a movie with an external_id, delete this movie and after a while recreate it with the same external_id. However the second create operation raise a duplicate error :

2021-11-08T23:11:05.936+01:00 | jwplatform.errors.BadRequestError: JWPlatform API Error:
2021-11-08T23:11:05.936+01:00 | duplicate_external_id: Failed to create media jjnt7IjV: external_id "6671" already exists for this site

More particularly this happens when I execute the second create :

new_media = {
        'upload': {
            'method': 'external',
            'mime_type': 'application/vnd.apple.mpegurl',
            'source_url': SRC_URL,
        },
        'metadata': {
            'external_id': '6671',
            'title': 'Test',
            'description': '',
            'duration': 0,
            'author': '',
            'permalink': "",
            'category': 'Movies',
            'tags': [],
            'custom_params': {},
        }
    }

media = client.Media.create(
        site_id=SITE_ID,
        body=new_media
    ).json_body

Could you please provide some insight on this ?

Client with null kwargs does not use default parameters

Currently jwplatform.Client instantiation only uses default parameters if a kwarg doesn't exist. If the kwarg is None this value is still used. It would be expected that None values for a kwarg use the default value.

Current

>>> import jwplatform
>>> client = jwplatform.Client('key', 'secret', host=None)
>>> client._host == 'api.jwplatform.com'
False

Expected

>>> import jwplatform
>>> client = jwplatform.Client('key', 'secret', host=None)
>>> client._host == 'api.jwplatform.com'
True

Fix Thumbnail Inheritance

Thumbnail class functionality does not work as intended.

I used the "try it" feature in the docs and successfully made a thumbnails/list call: https://developer.jwplayer.com/jwplayer/reference/get_v2-sites-site-id-thumbnails

When I tried this using jwplatform-py:

response = api.Thumbnail.list(
    site_id=jw.site_id,
    query_params={
        "q": "media_id:redacted",
        "page_length": 10,
        "page": 1
})

it returned an error:

  File "...venv/lib/python3.9/site-packages/jwplatform/client.py", line 85, in raw_request
    raise APIError.from_response(response)
jwplatform.errors.NotFoundError: JWPlatform API Error:

not_found: The requested resource could not be found.

I fixed this by changing client.py from:

class _ThumbnailClient(_ResourceClient):

to

class _ThumbnailClient(_SiteResourceClient):

Auth issues with v2 client

Python version: 3.9.7
Library version: 2.1.3

Using the JWPlatformClient produces 401s when trying to list media. Example:

    jwplatform_client = JWPlatformClient(MY_API_SECRET)
    response = jwplatform_client.Media.list(site_id=MY_SITE_ID)

Whenever I execute the above code, a request is sent with the following headers:

User-Agent: jwplatform_client-python/2.1.3
Authorization: Bearer MY_API_SECRET
Content-Type: application/json

and I get a 401 response. I noticed in the documentation that Bearer is emitted from the Authorization header. While debugging, If I remove that part and only send the secret in the Authorization header it works as expected.

Download videos using api...possible?

I do not see any references to downloading the videos using the api. I am working on a migration project and would appreciate any help in the right direction.

Thank you.

Unclosed requests.Session() cause ResourceWarning

I got below warning while running unit test

ResourceWarning: unclosed <ssl.SSLSocket fd=7, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=0, laddr=('192.168.30.101', 50234), raddr=('34.236.206.55', 443)>
  return self.run(*args, **kwds)
ResourceWarning: Enable tracemalloc to get the object allocation traceback

Make a new gh/pip release

There have been several updates and bug fixes including this one that would be nice to have in the official release.

Currently, pip install downloads a version from 2021.

Can someone on the JW team please publish a new release here and on pypi?

Thank you!

Please change this thing

From this ->
class _UploadClient(_ScopedClient):
_collection_path = "/v1/uploads/{resource_id}"

To This ->
class _UploadClient(_ScopedClient):
_collection_path = "/v2/uploads/{resource_id}"

Captions upload

Do you have any example on uploading captions? I can't get it to work.

Thumbnails

Hi,

Problem solved, thanks.

Hi,

I would like to know with the resource jw_client.videos.thumbnails.show(video_key = '') works, when I try to use I receive the error:

<Response 219 bytes [302 FOUND]> is not JSON serializable

Thanks

v1 EOL? Migration Guide?

How long will v1 continue being available?

All I found was:
"JW Player will gradually release v2 capabilities during the second half of 2020 into 2021. During this period, JW Player will maintain full support for both JW Platform Management API v1 and JW Player Platform Management API v2."

Everything is working perfectly for us and we're happy with v1 features so we'd like to avoid upgrading indefinitely if possible.

If v1 will start failing mid-2021 is there a migration guide available?

video_list_to_csv example is incorrect

I used your example https://github.com/jwplayer/jwplatform-py/blob/master/examples/video_list_to_csv.py to query the video list and create a CSV file. It seems however, there are two bugs in this example:

  1. https://github.com/jwplayer/jwplatform-py/blob/master/examples/video_list_to_csv.py#L38 There's a typo, the name should be 'result_offset', but is 'result_offest'. Because of that the list is not properly generated as it always takes the first part of the batch
  2. Second problem is that the field total in this line https://github.com/jwplayer/jwplatform-py/blob/master/examples/video_list_to_csv.py#L58 is used as if it contained the number of entries returned in this response, however my empirical experimentation shows, that it returns the total number of existing videos, so the offset is not properly calculated.

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.