Created
September 21, 2023 14:37
-
-
Save jimdur8n/6319bfddcff137fecb51556c59d2b0af to your computer and use it in GitHub Desktop.
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
import requests | |
import json | |
trint_api_key = "your key here" | |
#Set paramaters for video | |
#these will be dynamically populated in the future | |
filename = "U:\\mpeg4\\2023\\09\\NBC\\20230919NBC.mp4" | |
month = '09' | |
year = '2023' | |
network = 'NBC' | |
def findTrintFolderID(year,month,network): | |
#This function uses the Trint API to find | |
#the id of the Network folder for the year and month | |
#List Folders | |
url = "https://api.trint.com/folders?workspace-id=I0HSHeilQU2yT9Nv8Z6Zcg" | |
headers = {"accept": "application/json", | |
"api-key": trint_api_key, | |
} | |
response = requests.get(url, headers=headers) | |
#Turn the response into a JSON object | |
try: | |
json_data = json.loads(response.text) | |
except json.JSONDecodeError as e: | |
print(f"Error parsing JSON: {e}") | |
#find the folder ID that matches the year | |
year_id = None | |
for item in json_data: | |
if item["name"] == year: | |
year_id = item["_id"] | |
break | |
if year_id is not None: | |
print(f"The Year ID for {year} is {year_id}") | |
else: | |
print(f"Could not find an ID for {year}") | |
#Find the month | |
month_id = None | |
for item in json_data: | |
if item["name"] == month and item["parent"] == year_id: | |
month_id = item["_id"] | |
break | |
if month_id is not None: | |
print(f"The Month ID for {month} is {month_id}") | |
else: | |
print(f"Could not find an ID for {month}") | |
#Find the Network | |
network_id = None | |
for item in json_data: | |
if item["name"] == network and item["parent"] == month_id: | |
network_id = item["_id"] | |
break | |
if network_id is not None: | |
print(f"The Network ID for {network} is {network_id}") | |
else: | |
print(f"Could not find an ID for {network}") | |
return network_id | |
def uploadVidtwoTrint(filename,network_id): | |
url = f"https://upload.trint.com/?filename={filename}&detect-speaker-change=false&folder-id={network_id}&workspace-id=I0HSHeilQU2yT9Nv8Z6Zcg" | |
headers = { | |
"accept": "application/json", | |
"api-key": trint_api_key, | |
"content-type": "mp4" | |
} | |
response = requests.post(url, headers=headers) | |
return response.text | |
netkey = findTrintFolderID(year,month,network) | |
print(uploadVidtwoTrint(filename,netkey)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment