Playlists

Remember instance an object of FouryouseeAPI, according to the basic set up

Getting the playlists

fouryousee.FouryouseeAPI.get_playlists(self, **kwargs)

Get the playlists of the 4YouSee account.

Parameters

id (int, optional) – Id of the playlist.

Returns

List of dicts, where every dict, depicts a playlist.

Return type

list

Usage

Once “my” object has been created. You can execute the next:

Getting all playlists. It will return all the playlists of your account. It will be a list of dicts. If there is no playlist will return a empty list.

>>> my.get_playlists()
[
   {
      "id":38,
      "name":"Player DEMO",
      "durationInSeconds":112,
      "isSubPlaylist":false,
      "category":"None",
      "items":[
         { "type":"news", "durationInSeconds":10 },
         {
            "type":"media",
            "id":55,
            "name":"samsung_A80",
            "file":"i_55.mp4",
            "durationInSeconds":10
         },
         {
            "type":"media",
            "id":31,
            "name":"Gopro",
            "file":"i_31.mp4",
            "durationInSeconds":30
         },
         {
            "type":"media",
            "id":56,
            "name":"audifonos_samsung",
            "file":"i_56.mp4",
            "durationInSeconds":10
         },
         {
            "type":"media",
            "id":51,
            "name":"pelicula__sello_cinepolis",
            "file":"i_51.mp4",
            "durationInSeconds":12
         },
         {
            "type":"media",
            "id":53,
            "name":"ubereats",
            "file":"i_53.mp4",
            "durationInSeconds":10
         }
      ],
      "sequence":[ 0, 0, 1, 2, 3, 4, 0, 5 ]
   },
   {
      "id":39,
      "name":"Liva PC",
      "durationInSeconds":112,
      "isSubPlaylist":false,
      "category":"None",
      "items":[
         { "type":"news", "durationInSeconds":10 },
         {
            "type":"media",
            "id":55,
            "name":"samsung_A80",
            "file":"i_55.mp4",
            "durationInSeconds":10
         },
         {
            "type":"media",
            "id":31,
            "name":"Gopro",
            "file":"i_31.mp4",
            "durationInSeconds":30
         },
         {
            "type":"media",
            "id":56,
            "name":"audifonos_samsung",
            "file":"i_56.mp4",
            "durationInSeconds":10
         },
         {
            "type":"media",
            "id":51,
            "name":"pelicula__sello_cinepolis",
            "file":"i_51.mp4",
            "durationInSeconds":12
         },
         {
            "type":"media",
            "id":53,
            "name":"ubereats",
            "file":"i_53.mp4",
            "durationInSeconds":10
         }
      ],
      "sequence":[ 0, 0, 1, 2, 3, 4, 0, 5 ]
   }
]

If you know the playlist id

>>> my.get_playlists(id=39)
{
   "id":38,
   "name":"Player DEMO",
   "durationInSeconds":112,
   "isSubPlaylist":false,
   "category":"None",
   "items":[
      { "type":"news", "durationInSeconds":10 },
      {
         "type":"media",
         "id":55,
         "name":"samsung_A80",
         "file":"i_55.mp4",
         "durationInSeconds":10
      },
      {
         "type":"media",
         "id":31,
         "name":"Gopro",
         "file":"i_31.mp4",
         "durationInSeconds":30
      },
      {
         "type":"media",
         "id":56,
         "name":"audifonos_samsung",
         "file":"i_56.mp4",
         "durationInSeconds":10
      },
      {
         "type":"media",
         "id":51,
         "name":"pelicula__sello_cinepolis",
         "file":"i_51.mp4",
         "durationInSeconds":12
      },
      {
         "type":"media",
         "id":53,
         "name":"ubereats",
         "file":"i_53.mp4",
         "durationInSeconds":10
      }
   ],
   "sequence":[ 0, 0, 1, 2, 3, 4, 0, 5 ]
}

If the id doesn’t exists.

>>> my.get_playlists(id=123_456)
Exception: {"message":"Playlist with ID 123456 was not found"}

Advanced Usage

  • Gettin all the contents of the active playlists

Let’s suppose, we have an iterable with the playlists id, called active_playlists

>>> active_playlists, active_medias = [1, 67, 3, 4, 5, 8], []
>>> my.get_playlists()
>>> def active_contents(plist: dict) -> list:
...     temp_act_list = []
...     for item in plist['items']:
...         match item['type']:
...             case 'media':
...                 temp_act_list += [item['id']]
...             case 'carousel':
...                 if item['items']:
...                     temp_act_list += list(map(lambda x: x['id'], item['items'))
...                 else:
...                     pass
...             case 'videoWall':
...                     for rows in item['grid']:
...                         temp_act_list += list(map(lambda x: x['id'], rows))
...             case 'subPlaylist':
...                 temp_act_list += active_contents(item)
...     return temp_act_list
>>> for plist in list(filter(lambda x: x['id'] in active_playlists, my.playlists)):
...     active_medias += active_contents(plist)
>>> print(sorted(list(set(active_medias)))
[1, 3, 4, 8, 19, 20, 28, 30, 32, 33, 38, 39, 40, 45, 48, 49,
50, 53, 54, 55, 56, 57, 66, 69, 80, 99, 100, 101]

Adding playlists

fouryousee.FouryouseeAPI.add_playlist(self, **kwargs) dict

Create a new playlist in the 4yousee account.

Parameters
  • name (str, required) – Playlist display name.

  • isSubPlaylist (bool, optional) – Default value is False.

  • category (int, optional) – Id of category of playlists.

  • items (list of dicts, required) – Items that the playlist will content

  • sequence (list, required) – Sequence of execution of the items.

Returns

dict that depicts the playlist created.

Return type

dict

Usage

Once “my” object has been created. You can execute the next:

Passing all the required params

>>> my.add_playlist(name='New Playlist Example',
...                 isSubplaylist=False,
...                 category=1,
...                 items=[
...                            { "type": "layout", "id": 1 },
...                            {
...                               "type": "videowall",
...                                "abortIfError": False,
...                                "ignoreLayout": False,
...                                "grid": [
...                                            [
...                                                { "type": "media", "id": 4 },
...                                               { "type": "media", "id": 1 }
...                                            ],
...                                            [
...                                                { "type": "media", "id": 2 },
...                                                { "type": "media", "id": 4 }
...                                            ]
...                                        ]
...                            },
...                            { "type": "media", "id": 5 },
...                            { "type": "news" }
...                        ],
...                 sequence=[ 0, 1, 2, 3])
{
  "id": 89,
  "name": "New Playlist Example",
  "durationInSeconds": 30,
  "isSubPlaylist": false,
  "category": { "id": 1, "name": "Main Category" },
  "items": [
            {
              "type": "layout",
              "id": 1,
              "name": "Grid 1920x1080 com 1 área",
              "width": 1920,
              "height": 1080
            },
            {
              "type": "videoWall",
              "abortIfError": false,
              "ignoreLayout": false,
              "grid": [
                [
                  {
                    "id": 4,
                    "name": "4YouSee Analyse",
                    "file": "i_4.mp4",
                    "durationInSeconds": 10,
                    "categories": [
                      { "id": 1, "name": "DEMO" }
                    ]
                  },
                  {
                    "id": 1,
                    "name": "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" }
                    ],
                    "contentSchedule": {
                      "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": 2,
                    "name": "4YouSee Manage",
                    "file": "i_2.mp4",
                    "durationInSeconds": 10,
                    "categories": [
                      { "id": 1, "name": "DEMO" }
                    ]
                  },
                  {
                    "id": 4,
                    "name": "4YouSee Analyse",
                    "file": "i_4.mp4",
                    "durationInSeconds": 10,
                    "categories": [
                      { "id": 1, "name": "DEMO" }
                    ]
                  }
                ]
              ]
            },
            {
              "type": "media",
              "id": 1,
              "name": "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" }
              ],
              "contentSchedule": {
                "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 ]
                  }
                ]
              }
            },
            {
              "type": "news",
              "durationInSeconds": 10
            }
          ],
  "sequence": [ 0, 1, 2, 3 ]
}

Note

The previous playlist has 4 elements inside it.

Editing playlists

fouryousee.FouryouseeAPI.edit_playlist(self, **kwargs)

Update a Playlist by id.

Parameters
  • name (str, required) – Playlist display name.

  • isSubPlaylist (bool, optional) – Default value is False.

  • category (int, optional) – Id of category of playlists.

  • items (list of dicts, required) – Items that the playlist will content

  • sequence (list, required) – Sequence of execution of the items.

Returns

Dict that depicts the playlist modified.

Return type

dict

Usage

Once “my” object has been created. You can execute the next:

Changing the name.

>>> my.edit_playlist(id=75, name='Changing playlist name')
{
  "id": 75,
  "name": "Changing playlist name",
  "durationInSeconds": 20,
  "isSubPlaylist": false,
  "category": null,
  "items": [
    {
      "type": "media",
      "id": 117,
      "name": "Cielo_Nuevo_",
      "file": "i_117.mp4",
      "durationInSeconds": 20,
      "categories": [
        { "id": 27, "name": "random_" }
      ]
    }
  ],
  "sequence": [ 0 ]
}

Adding a item to the playlist

>>> my.edit_playlist(id=75, items=[
...                                 { 'type': 'media', 'id': 117 },
...                                 { 'type': 'media', 'id': 228 },
...                               ],
...                  sequence=[0,1])
{
  "id": 75,
  "name": "Changing playlist name",
  "durationInSeconds": 146,
  "isSubPlaylist": false,
  "category": null,
  "items": [
            {
              "type": "media",
              "id": 117,
              "name": "Cielo_Nuevo_",
              "file": "i_117.mp4",
              "durationInSeconds": 20,
              "categories": [
                { "id": 27, "name": "random_" }
              ]
            },
            {
              "type": "media",
              "id": 228,
              "name": "sample-mp4-file",
              "file": "i_228.mp4",
              "durationInSeconds": 126,
              "categories": [
                { "id": 1, "name": "DEMO" }
              ]
            }
          ],
  "sequence": [ 0, 1 ]
}

Deleting a media of the playlist and adding two carousels

>>> my.edit_playlist(id=75, items=[
...                                 { 'type': 'media', 'id': 117 },
...                                 { 'type': 'carousel', 'id': 8 },
...                                 { 'type': 'carousel', 'id': 9 },
...                               ]
...                  sequence=[0,1])
{
  "id": 75,
  "name": "Changing playlist name",
  "durationInSeconds": 20,
  "isSubPlaylist": false,
  "category": null,
  "items": [
    {
      "type": "media",
      "id": 117,
      "name": "Cielo_Nuevo_",
      "file": "i_117.mp4",
      "durationInSeconds": 20,
      "categories": [
        { "id": 27, "name": "random_" }
      ]
    },
    {
      "type": "carousel",
      "id": 25,
      "name": "Jornada Madrugada 12am-8am",
      "items": [],
      "sequence": []
    },
    {
      "type": "carousel",
      "id": 14,
      "name": "Cliente 4",
      "items": [],
      "sequence": []
    }
  ],
  "sequence": [ 0, 1, 2 ]
}

Advanced Usage

  • Duplicating a playlist

>>> existent_plist = my.get_playlists(id=75)
>>> new_items = [{'type': item['type'], 'id': item['id']} for item in existent_plist['items']]
>>> my.add_playlist(name=existent_plist['name'], items=new_items, sequence=existent_plist['sequence'])
{
  "id": 90,
  "name": "Changing playlist name",
  "durationInSeconds": 20,
  "isSubPlaylist": false,
  "category": null,
  "items": [
    {
      "type": "media",
      "id": 117,
      "name": "Cielo_Nuevo_",
      "file": "i_117.mp4",
      "durationInSeconds": 20,
      "categories": [
        { "id": 27, "name": "random_" }
      ]
    },
    {
      "type": "carousel",
      "id": 25,
      "name": "Jornada Madrugada 12am-8am",
      "items": [],
      "sequence": []
    },
    {
      "type": "carousel",
      "id": 14,
      "name": "Cliente 4",
      "items": [],
      "sequence": []
    }
  ],
  "sequence": [ 0, 1, 2 ]
}
  • Removing empty carousels from a playlist

>>> plist = my.get_playlists(id=75)
>>> empty_car = False
>>> print(f"Analisando playlist "{plist['id']} - {plist['name']}"")
>>> idx = 0
>>> while idx <= len(plist['items']):
        try:
            if plist['items'][idx]['type'] == 'carousel' and not plist['items'][idx]['sequence']:
                empty_car = True
                print(" Carousel excluido : "{} - {}"".                                                  format(plist['items'][idx]['id'],
                                                 plist['items'][idx]['name']))
                del plist['items'][idx]
                plist['sequence'] = list(filter(lambda s: s != idx, plist['sequence']))
                plist['sequence'] = list(map(lambda seq: seq - 1 if seq > idx else seq, plist['sequence']))
            else:
                idx += 1
        except IndexError:
            break
 >>> if empty_car:
        try:
            new_items = []
            for item in plist['items']:
                if item['type'] in ['videoWall', 'news']:
                    new_items.append(item)
                else:
                    new_items.append({'type': item['type'], 'id': item['id']})
            my.edit_playlist(id=plist['id'],
                             items=new_items,
                             sequence=plist['sequence'])
            print(f"    Playlist "{plist['id']} - {plist['name']}" atualizada!")
        except Exception as e:
            print(f"    Não foi possível atualizar playlist "{plist['id']} - {plist['name']}"
Error : {e}")
    else:
        print(f"        Playlist "{plist['id']} - {plist['name']}" não tem carroseis vazíos")

Warning

The previous piece of code doesn’t consider a playlist with videowalls.

Deleting playlists

fouryousee.FouryouseeAPI.delete_playlist(self, spec_id: int)

Delete one playlist of the 4YouSee account.

Parameters

spec_id (int, required) – Id of a single playlist.

Returns

True in case the playlist was deleted successfully or False in case the playlist was not deleted.

Return type

bool

Usage

Once “my” object has been created. You can execute the next:

>>> my.delete_playlist(15)
True
>>> my.delete_playlist(123_456) # If doesn't exists
False

Advanced Usage

>>> my.get_medias(categoryId=10)