Code Monkey home page Code Monkey logo

dailymotion-sdk-python's Introduction

Dailymotion API SDK for Python

Build Status Coverage Status

Installation

$ pip install dailymotion

Or

$ git clone [email protected]:dailymotion/dailymotion-sdk-python.git
$ cd dailymotion-sdk-python
$ python setup.py install

Examples

Public API call:

d = dailymotion.Dailymotion()
d.get('/videos')

Authenticated call:

d = dailymotion.Dailymotion()
d.set_grant_type('password', api_key=API_KEY, api_secret=API_SECRET,
    scope=['userinfo'], info={'username': USERNAME, 'password': PASSWORD})
d.get('/me', {'fields': 'id,fullname'})

Video upload:

d = dailymotion.Dailymotion()
d.set_grant_type('password', api_key=API_KEY, api_secret=API_SECRET,
    scope=['manage_videos'], info={'username': USERNAME, 'password': PASSWORD})
url = d.upload('./video.mp4')
d.post('/me/videos',
    {'url': url, 'title': 'MyTitle', 'published': 'true', 'channel': 'news'})

Authentication:

The Dailymotion API requires OAuth 2.0 authentication in order to access protected resources.

Contrary to most SDKs, the Dailymotion Python SDK implements lazy authentication, which means that no authentication request is sent as long as no data is requested from the API. At which point, two requests are sent back-to-back during the first request for information, one to authenticate and one to fetch the data.

Please note that the Dailymotion Python SDK also takes care of abstracting the entire OAuth flow, from retrieving, storing and using access tokens, to using refresh tokens to gather new access tokens automatically. You shouldn't have to deal with access tokens manually.

The session storage is enabled by default, you can disabled it by passing session_store_enabled=false to the constructor.

Access tokens are stored in memory by default, storing them in you OS files is recommanded :

import dailymotion

# The ./data directory
file_session = dailymotion.FileSessionStore('./data')
d = dailymotion.Dailymotion(session_storage=file_session)
....

Tests

  1. Install dependencies:

    $ pip install -r requirements.txt
    
  2. Update the file named config.py or set environment variables with the following content:

    CLIENT_ID = '[YOUR API KEY]'
    CLIENT_SECRET = '[YOUR API SECRET]'
    USERNAME = '[YOUR USERNAME]'
    PASSWORD = '[YOUR PASSWORD]'
    REDIRECT_URI = '[YOUR REDIRECT URI]'
    BASE_URL = 'https://api.dailymotion.com'
    OAUTH_AUTHORIZE_URL = 'https://www.dailymotion.com/oauth/authorize'
    OAUTH_TOKEN_URL = 'https://api.dailymotion.com/oauth/token'
  3. Run tests:

    $ py.test TestDailymotion.py
    

dailymotion-sdk-python's People

Contributors

amzani avatar lukasklein avatar pyke369 avatar rochacon avatar vlad-mh avatar

Watchers

 avatar  avatar  avatar

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.