import json
import requests
from api_auth import APICredentials, APIParams
  
class Create_VLP:
    def __init__(self):
        self.host = "https://services.uplynk.com"
  
    def run(self):
        self._create_virtual_linear_playlist()
 
    def _create_virtual_linear_playlist(self):
        url = "{}{}".format(self.host, "/api/v4/linear-playlist")
 
        description = 'Sample Playlist' # Brief description of the playlist.
        repeat = -1 # Repeats the playlist indefinitely.
        beam_break_duration = 30 # Sets 30 second ad breaks.
        playlist = [{
                'beam':{
                    'id':'abc123456defghi789jklmno012345pq'  # Asset ID
                }
            }, {
                'beam':{
                    'id':'1df8d13992cd4222a7343b8fafd89cd7' # Asset ID
                },
                'ad':{
                    'dur': 20 # Sets 20 second ad breaks between assets.
                }
            }
        ]

        payload = {
            'desc': description,
            'repeat': repeat,
            'beam_break_duration': beam_break_duration,
            'playlist': playlist
        }
 
        headers = {'Content-Type': 'application/json'}
 
        response = requests.post(
            url, params=APIParams(APICredentials()).get_params({}), data=json.dumps(payload), headers=headers
        )
 
        print(response.json())
  
Create_VLP().run()