Medias¶
Remember instance an object of FouryouseeAPI, according
to the basic set up
Getting the medias¶
- fouryousee.FouryouseeAPI.get_medias(self, **kwargs)¶
Get the medias of the 4YouSee account.
- Parameters
id (int, optional) – Id of the media to be edited.
name (str, optional) – Full or part name.
categoryId (Int or str, optional) – Id of an media category.
- Returns
List of dicts where every dict depicts a media.
- Return type
list
Usage
Once “my” object has been created. You can execute the next:
Getting all the medias. It will return all the contents of your account. It will be a list of dicts. If there is no content will return a empty list.
>>> my.get_medias()
Filtering by id. It will return a dict
>>> my.get_medias(id=60) { "id":60, "name":"Content_Deck_Vertical", "description":"Content_Deck_Vertical", "file":"i_60.mp4", "durationInSeconds":74, "categories":[ { "id":2, "name":"Sample name via API" } ], "schedule":{ "startDate":"None", "endDate":"None", "times":[ ] } }
Filtering by name. It will return a list of dicts, where every one is a match, a media.
>>> my.get_medias(name='play') [ { "id":1, "name":"4YouSee Play", "description":"4YouSee Play", "file":"i_1.mp4", "durationInSeconds":10, "categories":[ { "id":1, "name":"DEMO" }, { "id":3, "name":"Imagenes" }, { "id":11, "name":"Cliente 1" }, { "id":15, "name":"Semanas" }, { "id":16, "name":"Semana 1" } ], "schedule":{ "startDate":"2021-06-25", "endDate":"2021-06-30", "times":[ { "startTime":"06:00", "endTime":"23:00", "weekDays":[ 0, 2, 3, 5 ] }, { "startTime":"09:00", "endTime":"23:00", "weekDays":[ 1, 4, 6 ] } ] } }, { "id":125, "name":"player instalado", "description":"player instalado", "file":"i_125.gif", "durationInSeconds":0, "categories":[ { "id":1, "name":"DEMO" } ], "schedule":{ "startDate":"None", "endDate":"None", "times":[ ] } } ]
Filtering by categoryId. It will return a list of dicts, where every one is a match, a media. In case one of the categories id doesn’t exists, it will be ignored.
>>> my.get_medias(categoryId=10) # If the category doesn't have medias [] >>> my.get_medias(categoryId=15) [ { "id":1, "name":"Play", "description":"4YouSee Play", "file":"i_1.mp4", "durationInSeconds":10, "categories":[ { "id":1, "name":"DEMO" }, { "id":3, "name":"Imagenes" }, { "id":11, "name":"Cliente 1" }, { "id":15, "name":"Semanas" }, { "id":16, "name":"Semana 1" } ], "schedule":{ "startDate":"2021-06-25", "endDate":"2021-06-30", "times":[ { "startTime":"06:00", "endTime":"23:00", "weekDays":[ 0, 2, 3, 5 ] }, { "startTime":"09:00", "endTime":"23:00", "weekDays":[ 1, 4, 6 ] } ] } } ] >>> my.get_medias(categoryId='1,2,4')) [ { "id":1, "name":"Play", "description":"4YouSee Play", "file":"i_1.mp4", "durationInSeconds":10, "categories":[ { "id":1, "name":"DEMO" }, { "id":3, "name":"Imagenes" }, { "id":11, "name":"Cliente 1" }, { "id":15, "name":"Semanas" }, { "id":16, "name":"Semana 1" } ], "schedule":{ "startDate":"2021-06-25", "endDate":"2021-06-30", "times":[ { "startTime":"06:00", "endTime":"23:00", "weekDays":[ 0, 2, 3, 5 ] }, { "startTime":"09:00", "endTime":"23:00", "weekDays":[ 1, 4, 6 ] } ] } } ]
Mixing filters: It will return a list of dicts, where every one is a match, a media that is part of categoryId=1 and has the word 4yousee inside it.
>>> my.get_medias(name='4yousee', categoryId=1)
Advanced usage
Printing all the medias that has an schedule established.
>>> my.get_medias() >>> import json >>> for media in my.medias: >>> if media['schedule']['startDate'] and media['schedule']['endDate']: >>> print(json.dumps(media, indent=2))
Warning
The previous example consider the entire library of contents
Adding medias¶
- fouryousee.FouryouseeAPI.add_media(self, **kwargs) dict¶
Create a new media in the 4yousee account library. Obs.: Is not allowed post a html files through the API.
- Parameters
name (str, optional) – Name of the media in the account, default value will be the name of the file.
file (str, required) – Path of the file(s) locally.
duration (int, required only for images or zip files) – Duration of media.
categories (list of ints, required) – List of id of categories where this media will belong.
schedule (dict, optional) – scheduling information.
- Returns
Dict that depicts the added media.
- Return type
dict
Usage
Once “my” object has been created. You can execute the next:
Passing only the required params
>>> my.add_media(file='/home/username/Desktop/sample-mp4-file.mp4', ... categories=[31]) { "id":422, "name":"sample-mp4-file", "file":"https://4usee.com/*******/*****/common/videos/i_422.mp4", "duration":126, "schedule":{ "times":[ ] }, "categories":[ 31 ] }
Adding a zip file with schedule information
>>> my.add_media(file='/home/username/Desktop/sample-mp4-file.zip', ... duration=10, categories=[1], ... schedule={ ... "startDate": "2022-06-29", ... "endDate": "2022-07-31", ... "times": [ ... { ... "startTime": "08:00", ... "endTime": "11:00", ... "weekDays": [ 0, 2, 4, 5 ] ... } ... ] ... }) { "id":423, "name":"sample-zip-file", "file":"https://4usee.com/.../.../videos/i_423.zip", "duration":10, "schedule":{ "startDate":"2022-06-29", "endDate":"2022-07-31", "times":[ { "startTime":"08:00", "endTime":"11:00", "weekDays":[ 0, 2, 4, 5 ] } ] }, "categories":[ 1 ] }
Editing medias¶
- fouryousee.FouryouseeAPI.edit_media(self, **kwargs)¶
Update an existing media.
- Parameters
id (int, required) – Id of a media.
name (str, optional) – name for the media.
file (dict, optional) – Used only to replace the file media. To update the source file of the you need to create a upload a file first.
duration (int, optional) – duration of Media, used only by zip or images files.
categories (list of int, optional) – list of categories which this Media is gonna be associated.
schedule (dict) – Scheduling information.
- Returns
Dict that depicts the media edited.
- Return type
dict
Usage
Once “my” object has been created. You can execute the next:
Replacing the file media of the content with the 55 id. Only will change the param that you send.
>>> my.edit_media(id=55, ... file={ ... "id": "dce17a1a5949768a82dd8bedd2ee525d", ... "filename": "video.mp4" ... }) { "id":55, "name":"SEFESO_", "file":"https://4usee.com/****-*****/****/common/videos/i_55.mp4", "duration":20, "schedule":{ "startDate":"None", "endDate":"None", "times":[ ] }, "categories":[ 27 ] }
Changing the name of a media, categories and part of the schedule information
>>> my.get_media(id=99) { "id":99, "name":"Noticia museo del carnaval", "description":"Noticia museo del carnaval", "file":"i_99.mp4", "durationInSeconds":15, "categories":[ { "id":2, "name":"Sample name via API" } ], "schedule":{ "startDate":"None", "endDate":"None", "times": [ ] } } >>> my.edit_media(id=99, name='New name', ... categories=[11, 12, 13], ... schedule={'startDate': '2022-05-01', 'endDate': '2022-05-31'}) { "id":99, "name":"New name", "file":"https://4usee.com/****-*****/****/common/videos/i_99.mp4", "duration":15, "schedule":{ "startDate":"2022-05-01", "endDate":"2022-05-31", "times":[ ] }, "categories":[ 11, 12, 13 ] } >>> my.get_medias(id=99) { "id":99, "name":"New name", "description":"New name", "file":"i_99.mp4", "durationInSeconds":15, "categories":[ { "id":11, "name":"Cliente 1" }, { "id":12, "name":"Cliente 2" }, { "id":13, "name":"Cliente 3" } ], "schedule":{ "startDate":"2022-05-01", "endDate":"2022-05-31", "times":[ ] } }
Advanced Usage
Edit the duration of all the zip files of the account
>>> my.get_medias() >>> for media in c.medias: ... if media['file'].endswith('zip'): ... my.edit_media(id=media['id'], duration=15)
Deleting medias¶
- fouryousee.FouryouseeAPI.delete_media(self, spec_id: int)¶
Delete one media of the 4YouSee account.
- Parameters
spec_id (int, required) – Id of a single media.
- Returns
True in case the media was deleted successfully or False in case the media was not deleted.
- Return type
bool
Usage
Once “my” object has been created. You can execute the next:
>>> my.delete_media(15) True >>> my.delete_media(123_456) # If doesn't exists False
Advanced Usage
Deleting all the zip files of the account
>>> my.get_medias() >>> for media in c.medias: ... if media['file'].endswith('zip'): ... my.delete_media(media['id'])