-
-
Save anisse/ed92d218fd05dd6e1c03 to your computer and use it in GitHub Desktop.
Test API AirMedia Freebox OS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# for python3.3 run like this: | |
# pyvenv env && source env/bin/activate && curl http://python-distribute.org/distribute_setup.py | python && easy_install pip && pip install requests && python airmedia.py | |
# for python2, like this: | |
# virtualenv env && source env/bin/activate && pip install requests && python airmedia.py | |
# or just install requests from your distro | |
import sys | |
if sys.version_info >= (3, 0): b = lambda s : bytes(s, encoding='utf8') | |
else: b = lambda s : s | |
import requests | |
import json | |
import hmac | |
import hashlib | |
import time | |
# CONFIGURATION | |
app_token = '' | |
app_id = '' | |
urlbase = 'http://mafreebox.freebox.fr/api/v1/' | |
############### | |
def open_session(): | |
r = requests.get(urlbase + 'login') | |
challenge = json.loads(r.text)['result']['challenge'] | |
password = hmac.new(b(app_token), b(challenge), hashlib.sha1).hexdigest() | |
req = json.dumps({'app_id': app_id, 'password': password}) | |
r = requests.post(urlbase + 'login/session', req) | |
return json.loads(r.text)['result']['session_token'] | |
def sendairmedia(session, action, url): | |
req = json.dumps({'action': action, 'media_type': 'video', 'media': url}) | |
r = requests.post(urlbase + 'airmedia/receivers/Freebox Player/', req, headers={'X-Fbx-App-Auth': session}) | |
session = open_session() | |
sendairmedia(session, 'stop', '') | |
sendairmedia(session, 'start', 'http://download.blender.org/peach/bigbuckbunny_movies/big_buck_bunny_480p_surround-fix.avi') | |
time.sleep(10) | |
sendairmedia(session, 'stop', '') | |
sendairmedia(session, 'start', 'http://mirrorblender.top-ix.org/movies/sintel-1024-surround.mp4') | |
time.sleep(10) | |
sendairmedia(session, 'stop', '') | |
sendairmedia(session, 'start', 'http://arcagenis.org/mirror/mango/ToS/tears_of_steel_720p.mkv') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment