![PyPI - Python Version](https://img.shields.io/pypi/pyversions/mediaserver-api-client.svg)
![PyPI](https://img.shields.io/pypi/v/mediaserver-api-client.svg)
# mediaserver-client
A python3 reference implementation of an UbiCast Nudgis API client.
Nudgis was called MediaServer in the past but the internal name of Nudgis is still MediaServer.
## Requirements
git
python >= 3.9 (download the latest stable release from https://www.python.org/downloads/)
Optional:
* python3-venv
## Installation
### Linux & OSX
For development, the package can be installed in editable mode to allow changes on it :
```sh
git clone https://github.com/UbiCastTeam/mediaserver-client.git
cd mediaserver-client/
python3 -m venv .env
source .env/bin/activate # remember to run this every time you enter the folder and need to restore the environment
python3 -m pip install --editable .
```
If you want to install it system-wide as dependency, the releases are available on pypi:
```sh
pip install mediaserver-api-client
```
### Windows
* Open cmd.exe and check python is available with `py --version` which should display the Python version
```
>py --version
Python 3.11.1
```
* From this project root path, run:
```
> py -m venv .env
> ".env/Scripts/activate.bat"
> pip install .
```
* Check it works with:
```
>py -m examples.ping_server
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "C:\Users\User\src\mediaserver-client\examples\ping_server.py", line 17, in <module>
print(msc.api('/'))
^^^^^^^^^^^^
File "C:\Users\User\src\mediaserver-client\ms_client\client.py", line 221, in api
result = self.request(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\User\src\mediaserver-client\ms_client\client.py", line 98, in request
self.check_conf()
File "C:\Users\User\src\mediaserver-client\ms_client\client.py", line 71, in check_conf
configuration_lib.check_conf(self.conf)
File "C:\Users\User\src\mediaserver-client\ms_client\lib\configuration.py", line 87, in check_conf
raise ConfigurationError('The value of "SERVER_URL" is not set. Please configure it.')
ms_client.lib.configuration.ConfigurationError: The value of "SERVER_URL" is not set. Please configure it.
```
Despite the error above, it shows that the installation is complete.
## Configuration
Copy the provided `config.json.example` file into e.g. `myconfig.json`, edit it with a text editor and fill the URL and API KEY.
* Check it works with:
Linux:
```
$ python3 ./examples/ping.py myconfig.json
{'success': True, 'mediaserver': '11.1.1'}
```
Windows:
```
$ py ./examples/ping.py myconfig.json
{'success': True, 'mediaserver': '11.1.1'}
```
## Client class instantiation
The client class (`ms_client`.`client`.`MediaServerClient`) takes two arguments:
* `local_conf`: This argument can be either a dict, a path (`str` object) or a unix user (`unix:msuser` for example) -- only aplicable from running scripts from within the server running mediaserver (Nudgis). The default value is `None`, which means no configuration.
* `setup_logging`: This argument must be a boolean. If set to `True`, the logging to console will be configured. The default value is `True`.
## Configuration
You can see available parameters in the default configuration file :
[Default configuration](/ms_client/conf.py)
The local configuration must be a json file.
## Examples
### Start/Stop a live
``` python
from ms_client.client import MediaServerClient
msc = MediaServerClient(local_conf='your-conf.json')
response = msc.api('/lives/prepare', method='post')
if response['success']:
oid = response['oid']
rtmp_uri = response['publish_uri']
print(oid, rtmp_uri)
print(msc.api('/lives/start', method='post', data={'oid': oid}))
print(msc.api('/lives/stop', method='post', data={'oid': oid}))
```
### Remove all users function
``` python
from ms_client.client import MediaServerClient
msc = MediaServerClient(local_conf='your-conf.json')
def remove_all_users():
print('Remove all users')
users = msc.api('/users')['users']
for user in users:
msc.api('/users/delete', method='get', params={'id': user['id']})
```
### Add media with a video, make it published at once
``` python
from ms_client.client import MediaServerClient
msc = MediaServerClient(local_conf='your-conf.json')
print(msc.add_media('Test multichunk upload mp4', file_path='test.mp4', validated='yes', speaker_email='user@domain.com'))
```
### Create user personal channel and upload into it
``` python
from ms_client.client import MediaServerClient
msc = MediaServerClient(local_conf='your-conf.json')
personal_channel_oid = msc.api('/channels/personal/', method='get', params={'email': 'test@test.com'}).get('oid')
respone_like = {
'slug': 'testtestcom_05881',
'oid': 'c125855df7d36iudslp3',
'dbid': 113,
'title': 'test@test.com',
'success': True
}
if personal_channel_oid:
print('Uploading to personal channel %s' % personal_channel_oid)
print(msc.add_media('Test multichunk upload mp4', file_path='test.mp4', validated='yes', speaker_email='user@domain.com', channel=personal_channel_oid))
```
### Add media with a zip
``` python
from ms_client.client import MediaServerClient
msc = MediaServerClient(local_conf='your-conf.json')
print(msc.add_media('Test multichunk upload zip', file_path='/tmp/test.zip'))
print(msc.add_media(file_path='test.mp4'))
```
### Add a user
``` python
from ms_client.client import MediaServerClient
msc = MediaServerClient(local_conf='your-conf.json')
print(msc.api('users/add/', method='post', data={'email': 'test@test.com'}))
```
### Add users with csv file; example file (header should be included):
users.csv :
``` csv
Firstname;Lastname;Email;Company
Albert;Einstein;albert.einstein@test.com;Humanity
```
``` python
from ms_client.client import MediaServerClient
msc = MediaServerClient(local_conf='your-conf.json')
msc.import_users_csv('users.csv')
```
### Add an annotation
``` python
from ms_client.client import MediaServerClient
msc = MediaServerClient(local_conf='your-conf.json')
print(msc.api('annotations/post', params={'oid': 'v125849d470d7v92kvtc', 'time': 1000}))
```
### Get Chapters
``` python
from ms_client.client import MediaServerClient
msc = MediaServerClient(local_conf='your-conf.json')
print(msc.api('annotations/chapters/list', params={'oid': 'v125849d470d7v92kvtc'}))
```
### Get annotations types list and print chapters id
``` python
from ms_client.client import MediaServerClient
msc = MediaServerClient(local_conf='your-conf.json')
response = msc.api('annotations/types/list', params={'oid': 'v125849d470d7v92kvtc'})
for a in response['types']:
if a['slug'] == 'chapter':
print(a['id'])
```
Raw data
{
"_id": null,
"home_page": "https://www.ubicast.eu/en/solutions/delivery/",
"name": "mediaserver-api-client",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "api, client, mediaserver, nudgis, ubicast",
"author": "UbiCast",
"author_email": "dev@ubicast.eu",
"download_url": "https://files.pythonhosted.org/packages/47/4e/646e718e6c5f0c6c157011224910373eba26d0dac38cb96f9016516f56c3/mediaserver_api_client-4.4.tar.gz",
"platform": null,
"description": "![PyPI - Python Version](https://img.shields.io/pypi/pyversions/mediaserver-api-client.svg)\n![PyPI](https://img.shields.io/pypi/v/mediaserver-api-client.svg)\n\n# mediaserver-client\n\nA python3 reference implementation of an UbiCast Nudgis API client.\nNudgis was called MediaServer in the past but the internal name of Nudgis is still MediaServer.\n\n## Requirements\n\ngit\npython >= 3.9 (download the latest stable release from https://www.python.org/downloads/)\n\nOptional:\n* python3-venv\n\n## Installation\n\n### Linux & OSX\n\nFor development, the package can be installed in editable mode to allow changes on it :\n\n```sh\ngit clone https://github.com/UbiCastTeam/mediaserver-client.git\ncd mediaserver-client/\npython3 -m venv .env\nsource .env/bin/activate # remember to run this every time you enter the folder and need to restore the environment\npython3 -m pip install --editable .\n```\n\nIf you want to install it system-wide as dependency, the releases are available on pypi:\n```sh\npip install mediaserver-api-client\n```\n\n### Windows\n\n* Open cmd.exe and check python is available with `py --version` which should display the Python version\n\n```\n>py --version\nPython 3.11.1\n```\n\n* From this project root path, run:\n\n```\n> py -m venv .env\n> \".env/Scripts/activate.bat\"\n> pip install .\n``` \n \n* Check it works with:\n\n```\n>py -m examples.ping_server\nTraceback (most recent call last):\n File \"<frozen runpy>\", line 198, in _run_module_as_main\n File \"<frozen runpy>\", line 88, in _run_code\n File \"C:\\Users\\User\\src\\mediaserver-client\\examples\\ping_server.py\", line 17, in <module>\n print(msc.api('/'))\n ^^^^^^^^^^^^\n File \"C:\\Users\\User\\src\\mediaserver-client\\ms_client\\client.py\", line 221, in api\n result = self.request(*args, **kwargs)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"C:\\Users\\User\\src\\mediaserver-client\\ms_client\\client.py\", line 98, in request\n self.check_conf()\n File \"C:\\Users\\User\\src\\mediaserver-client\\ms_client\\client.py\", line 71, in check_conf\n configuration_lib.check_conf(self.conf)\n File \"C:\\Users\\User\\src\\mediaserver-client\\ms_client\\lib\\configuration.py\", line 87, in check_conf\n raise ConfigurationError('The value of \"SERVER_URL\" is not set. Please configure it.')\nms_client.lib.configuration.ConfigurationError: The value of \"SERVER_URL\" is not set. Please configure it.\n```\n\nDespite the error above, it shows that the installation is complete.\n\n## Configuration\n\nCopy the provided `config.json.example` file into e.g. `myconfig.json`, edit it with a text editor and fill the URL and API KEY.\n\n* Check it works with:\n\nLinux:\n```\n$ python3 ./examples/ping.py myconfig.json\n{'success': True, 'mediaserver': '11.1.1'}\n```\nWindows:\n```\n$ py ./examples/ping.py myconfig.json\n{'success': True, 'mediaserver': '11.1.1'}\n```\n\n## Client class instantiation\n\nThe client class (`ms_client`.`client`.`MediaServerClient`) takes two arguments:\n* `local_conf`: This argument can be either a dict, a path (`str` object) or a unix user (`unix:msuser` for example) -- only aplicable from running scripts from within the server running mediaserver (Nudgis). The default value is `None`, which means no configuration.\n* `setup_logging`: This argument must be a boolean. If set to `True`, the logging to console will be configured. The default value is `True`.\n\n## Configuration\n\nYou can see available parameters in the default configuration file :\n[Default configuration](/ms_client/conf.py)\n\nThe local configuration must be a json file.\n\n## Examples\n\n### Start/Stop a live\n\n``` python\nfrom ms_client.client import MediaServerClient\nmsc = MediaServerClient(local_conf='your-conf.json')\n\nresponse = msc.api('/lives/prepare', method='post')\nif response['success']:\n oid = response['oid']\n rtmp_uri = response['publish_uri']\n\n print(oid, rtmp_uri)\n\n print(msc.api('/lives/start', method='post', data={'oid': oid}))\n\n print(msc.api('/lives/stop', method='post', data={'oid': oid}))\n```\n\n### Remove all users function\n\n``` python\nfrom ms_client.client import MediaServerClient\nmsc = MediaServerClient(local_conf='your-conf.json')\n\n\ndef remove_all_users():\n print('Remove all users')\n users = msc.api('/users')['users']\n\n for user in users:\n msc.api('/users/delete', method='get', params={'id': user['id']})\n```\n\n### Add media with a video, make it published at once\n\n``` python\nfrom ms_client.client import MediaServerClient\nmsc = MediaServerClient(local_conf='your-conf.json')\n\nprint(msc.add_media('Test multichunk upload mp4', file_path='test.mp4', validated='yes', speaker_email='user@domain.com'))\n```\n\n### Create user personal channel and upload into it\n\n``` python\nfrom ms_client.client import MediaServerClient\nmsc = MediaServerClient(local_conf='your-conf.json')\n\npersonal_channel_oid = msc.api('/channels/personal/', method='get', params={'email': 'test@test.com'}).get('oid')\n\nrespone_like = {\n 'slug': 'testtestcom_05881',\n 'oid': 'c125855df7d36iudslp3',\n 'dbid': 113,\n 'title': 'test@test.com',\n 'success': True\n}\nif personal_channel_oid:\n print('Uploading to personal channel %s' % personal_channel_oid)\n\n print(msc.add_media('Test multichunk upload mp4', file_path='test.mp4', validated='yes', speaker_email='user@domain.com', channel=personal_channel_oid))\n```\n\n### Add media with a zip\n\n``` python\nfrom ms_client.client import MediaServerClient\nmsc = MediaServerClient(local_conf='your-conf.json')\n\nprint(msc.add_media('Test multichunk upload zip', file_path='/tmp/test.zip'))\nprint(msc.add_media(file_path='test.mp4'))\n```\n\n### Add a user\n\n``` python\nfrom ms_client.client import MediaServerClient\nmsc = MediaServerClient(local_conf='your-conf.json')\n\nprint(msc.api('users/add/', method='post', data={'email': 'test@test.com'}))\n```\n\n### Add users with csv file; example file (header should be included):\n\nusers.csv :\n\n``` csv\nFirstname;Lastname;Email;Company\nAlbert;Einstein;albert.einstein@test.com;Humanity\n```\n\n``` python\nfrom ms_client.client import MediaServerClient\nmsc = MediaServerClient(local_conf='your-conf.json')\n\nmsc.import_users_csv('users.csv')\n```\n\n### Add an annotation\n\n``` python\nfrom ms_client.client import MediaServerClient\nmsc = MediaServerClient(local_conf='your-conf.json')\n\nprint(msc.api('annotations/post', params={'oid': 'v125849d470d7v92kvtc', 'time': 1000}))\n```\n\n### Get Chapters\n\n``` python\nfrom ms_client.client import MediaServerClient\nmsc = MediaServerClient(local_conf='your-conf.json')\n\nprint(msc.api('annotations/chapters/list', params={'oid': 'v125849d470d7v92kvtc'}))\n```\n\n### Get annotations types list and print chapters id\n\n``` python\nfrom ms_client.client import MediaServerClient\nmsc = MediaServerClient(local_conf='your-conf.json')\n\nresponse = msc.api('annotations/types/list', params={'oid': 'v125849d470d7v92kvtc'})\nfor a in response['types']:\n if a['slug'] == 'chapter':\n print(a['id'])\n```\n",
"bugtrack_url": null,
"license": "LGPLv3",
"summary": "A python3 reference implementation of an UbiCast MediaServer API client",
"version": "4.4",
"project_urls": {
"Download": "https://github.com/UbiCastTeam/mediaserver-client",
"Homepage": "https://www.ubicast.eu/en/solutions/delivery/"
},
"split_keywords": [
"api",
" client",
" mediaserver",
" nudgis",
" ubicast"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "d9e813ee098f7365b4f977888f4109551dacade562e8806e542b195730f3abe0",
"md5": "063d8a5aaf00ed9112de96fe71eaadb1",
"sha256": "e6cdddaffec2f988188752e570332d5034aab37e8a47f3809ae02bd799cfb36d"
},
"downloads": -1,
"filename": "mediaserver_api_client-4.4-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "063d8a5aaf00ed9112de96fe71eaadb1",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": null,
"size": 18365,
"upload_time": "2024-05-06T07:21:38",
"upload_time_iso_8601": "2024-05-06T07:21:38.391953Z",
"url": "https://files.pythonhosted.org/packages/d9/e8/13ee098f7365b4f977888f4109551dacade562e8806e542b195730f3abe0/mediaserver_api_client-4.4-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "474e646e718e6c5f0c6c157011224910373eba26d0dac38cb96f9016516f56c3",
"md5": "798fa62ff489c5b73fc9ac9f142dd8ce",
"sha256": "2fe844b357d617c1009e8ca7db0d5ebffbec132f90a5a5d120d375f64d158080"
},
"downloads": -1,
"filename": "mediaserver_api_client-4.4.tar.gz",
"has_sig": false,
"md5_digest": "798fa62ff489c5b73fc9ac9f142dd8ce",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 17111,
"upload_time": "2024-05-06T07:21:40",
"upload_time_iso_8601": "2024-05-06T07:21:40.588804Z",
"url": "https://files.pythonhosted.org/packages/47/4e/646e718e6c5f0c6c157011224910373eba26d0dac38cb96f9016516f56c3/mediaserver_api_client-4.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-06 07:21:40",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "UbiCastTeam",
"github_project": "mediaserver-client",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "mediaserver-api-client"
}