Skip to content

Commit

Permalink
Initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
dasevilla committed May 15, 2013
0 parents commit 0ce89c5
Show file tree
Hide file tree
Showing 10 changed files with 474 additions and 0 deletions.
39 changes: 39 additions & 0 deletions .gitignore
@@ -0,0 +1,39 @@
*.py[cod]

# C extensions
*.so

# Packages
*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg
lib
lib64
__pycache__

# Installer logs
pip-log.txt

# Unit test / coverage reports
.coverage
.tox
nosetests.xml

# Translations
*.mo

# Mr Developer
.mr.developer.cfg
.project
.pydevproject

# SublimeText project files
*.sublime-workspace
21 changes: 21 additions & 0 deletions LICENSE.txt
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2013 Devin Sevilla

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
1 change: 1 addition & 0 deletions MANIFEST.in
@@ -0,0 +1 @@
include README.rst LICENSE.txt
5 changes: 5 additions & 0 deletions README.rst
@@ -0,0 +1,5 @@
===================
Rovi Python Client
===================

A simple Python client library for the `Rovi API <http://developer.rovicorp.com/>`
Empty file added roviclient/__init__.py
Empty file.
69 changes: 69 additions & 0 deletions roviclient/base.py
@@ -0,0 +1,69 @@
import hashlib
import time

import requests
from requests.auth import AuthBase


class MasheryAuth(AuthBase):
"""
Adds ``apikey`` and ``sig`` query parameters to the request
"""

def __init__(self, key, secret):
self.key = key
self.secret = secret

def __call__(self, r):
params = {
'apikey': self.key,
'sig': self._sig(),
}
r.prepare_url(r.url, params)

return r

def _sig(self):
timestamp = int(time.time())

m = hashlib.md5()
m.update(self.key)
m.update(self.secret)
m.update(str(timestamp))

return m.hexdigest()


class RoviApi(object):

ROVI_API_BASE = 'http://api.rovicorp.com'

def __init__(self, service, version, key, secret):
self.service = service
self.version = version

session = requests.Session()
session.auth = MasheryAuth(key, secret)
self.session = session

def request_url(self, resource):
return '/'.join([self.ROVI_API_BASE, self.service, self.version, resource])

def make_request(self, resource, params=None):
if params is None:
params = {}

url = self.request_url(resource)
params['format'] = 'json'

r = self.session.get(url=url, params=params)

r.raise_for_status()

return r


class RoviDataApi(RoviApi):

def __init__(self, key, secret):
super(RoviDataApi, self).__init__('data', 'v1', key, secret)
85 changes: 85 additions & 0 deletions roviclient/search.py
@@ -0,0 +1,85 @@
from base import RoviApi


class SearchApi(RoviApi):
"""
Searches titles or names in Rovi Cloud Services and returns results in
order of popularity and similarity to the search query.
http://prod-doc.rovicorp.com/mashery/index.php/Search-api/v2.1/search
"""

def __init__(self, key, secret):
super(SearchApi, self).__init__('search', 'v2.1', key, secret)

def make_request(self, endpoint, entitiy_type, query, params=None):
if params is None:
params = {}

params['entitytype'] = entitiy_type
params['query'] = query
params['country'] = 'US'
params['language'] = 'en'

return super(SearchApi, self).make_request('%s/search' % endpoint,
params)

def music_search(self, entitiy_type, query, **kwargs):
"""
Search the music database
Where ``entitiy_type`` is a comma separated list of:
``song``
songs
``album``
albums
``composition``
compositions
``artist``
people working in music
"""
return self.make_request('music', entitiy_type, query, kwargs)

def amg_video_search(self, entitiy_type, query, **kwargs):
"""
Search the Movies and TV database
Where ``entitiy_type`` is a comma separated list of:
``movie``
Movies
``tvseries``
TV series
``credit``
people working in TV or movies
"""
return self.make_request('amgvideo', entitiy_type, query, kwargs)

def video_search(self, entitiy_type, query, **kwargs):
"""
Search the TV schedule database
Where ``entitiy_type`` is a comma separated list of:
``movies``
Movie
``tvseries``
TV series
``episode``
Episode titles
``onetimeonly``
TV programs
``credit``
People working in TV or movies
"""
return self.make_request('video', entitiy_type, query, kwargs)

0 comments on commit 0ce89c5

Please sign in to comment.