Dear friends, good evening. As I have written before, I use vscheduler to create a 24-hour stream. Since 237dominique has made the application's code available, I tried to find a way to improve/change some things I wanted. In this regard, since I have no idea about programming, I thought of trying ChatGPT. You can find program and code here
https://www.dropbox.com/...cheduler%202023.zip?dl=0With the help of ChatGPT, I made some changes to the program:
1. Now when adding an event, the fade is preset to 0. I did this because when it is at 500, sometimes it abruptly cuts off the previous video and looks bad.
2. I changed the code that shuffles the events we select from the list. With the previous code, if we have 5 events on the list and shuffle them, the 5th one always goes to the 4th place and not higher.
3. I tried very hard and experimented a lot to find a way to make the program recognize the videolists of vmix directly. No matter how I tried, I failed. So, as you will read below, I thought of a new (new to me at least) approach to make this possible.
4. I created an extra program, the xml editor, which makes bulk changes to the lists of xml files generated by the program. This is still in an early version, so I won't upload it for now. These are the basics I did. Now, regarding how the program can recognize and play videolists from vmix... Since I couldn't achieve it directly within the program, I got disappointed and gave up. Until one day I needed a simple program that would input the time, minutes, and seconds and calculate what the new time would be. I asked ChatGPT, and it suggested/made a python script. I was culturally shocked that it told me exactly how to install python, run the script, and generally how quickly it implemented it, without needing even half a line of code.
When I asked it to create some vb.net scripts for vmix, it struggled a lot because, as I understood, while it gave me correct commands that actually exist in vb.net, the implementation of them by vmix has some limitations that ChatGPT, of course, does not know. After it made the first python script for me, I thought to ask if python supports xml searching, timers, and http requests.
And that's how a new (for me, at least) wonderful world opened up in front of me. So, I started a few days ago and have been creating Python scripts for vmix, which I will share, in case they prove useful to some other forum member or to get ideas and improvements, etc. What I see is that when the python script runs, it has zero impact on the CPU/GPU (at least for the simple ones I tested), so we are doing well in that regard too. I will start with the scripts.
1. Vmixvideolists
This specific script works with the vmanager program to play videolists from vmix. The usage is as follows:
We have our list in vmix that we want to play. We change the List name to anything we want, for example, Hellolist. Now we need to set the time it will play. We go to vmanager and create a new list and save it. The script searches in c:\vmixlists\, and this is something that can be changed within the script. So, we give our list a name in vmanager and save it. Thus, an XML file with the name we provided will be created inside the c:\vmixlists\ folder.
Now we need to add the time and date our list will play from vmix. We go to Events -> Add Event -> Operator mode, and we change the operator mode name to the name we gave our list in vmix, set the duration, and the time/date we want it to play. Then we press push to send the event to vcontroller. Then we save the list in vmanager again so the XML file gets updated with the new time.
Next, we run our .py script, and it asks us to enter the name of our XML file. For example, Hello.xml. After that, it asks us to enter the name we want to search for. Here we write Hellolist and press enter. That's it. We let the script run, and when the specified time comes (which we set in vmanager when creating the list there), it will play the vmix list. Note that each time we change the times in vmanager, we save to update the time in the script. If we change the list name in vmanager (change the XML file, that is), we run the script from the beginning with the new name of the XML file. I should mention here that since I am in Greece, ChatGPT added the following line to my code for the XML file to work: start_time_str = start_time_str.replace("πμ", "AM").replace("μμ", "PM"), which is for Greek regional settings. For you, it might be necessary to remove it or add the appropriate line for your own country's regional settings.
Code:
import os
import xml.etree.ElementTree as ET
from datetime import datetime, timedelta
import time
import requests
xml_folder = "c:/vmixlists/"
xml_filename = input("Enter the XML filename: ")
# Read multiple event titles separated by commas
event_titles_input = input("Enter the Event Titles to search for (separated by commas): ")
event_titles = [title.strip() for title in event_titles_input.split(",")]
xml_file_path = os.path.join(xml_folder, xml_filename)
while True:
tree = ET.parse(xml_file_path)
root = tree.getroot()
for event_title in event_titles:
found_event = None
for event in root.iter("Event"):
if event.get("Title") == event_title:
start_time_str = event.get("Start")
start_time_str = start_time_str.replace("πμ", "AM").replace("μμ", "PM")
start_time = datetime.strptime(start_time_str, "%d/%m/%Y %I:%M:%S %p")
now = datetime.now()
# Execute the event only if the current time is within a 10-second range of the start time
if start_time <= now < start_time + timedelta(seconds=10):
found_event = event
break
if found_event is not None:
input_name = found_event.get("Title").replace(" ", "%20")
url = f"http://127.0.0.1:8088/api/?Function=CutDirect&Input={input_name}"
response = requests.get(url)
print(f"Event executed, response: {response.text}")
else:
print(f'No event with title "{event_title}" found in the XML file or not time yet.')
time.sleep(1) # Wait for 1 second before checking for events again.
2. Random video
The scripts from here onwards are based on posts I've seen in forums, combined with things I personally would like to be able to do. This script searches a folder for an mp4 file, and once found, it selects a file randomly and adds it to vMix. The default folder is C:\spots, but of course, this can be changed. It's worth mentioning that it can be enriched with additional commands as needed. I won't lie... I don't know how to make the changes myself, but I will ask AI to do it for me.
Code:
import os
import random
import requests
import xml.etree.ElementTree as ET
def get_random_mp4_file(folder_path):
mp4_files = [f for f in os.listdir(folder_path) if f.endswith('.mp4')]
for _ in range(len(mp4_files)):
random_file = random.choice(mp4_files)
if not is_title_in_api_response(random_file):
return random_file
return None
def is_title_in_api_response(title):
api_url = 'http://127.0.0.1:8088/API'
response = requests.get(api_url)
if response.status_code == 200:
root = ET.fromstring(response.content)
for elem in root.findall('.//*[@title]'):
if elem.get('title') == title:
return True
return False
def send_request(video_path):
url = f'http://127.0.0.1:8088/api/?Function=AddInput&Value=Video|{video_path}'
response = requests.get(url)
if response.status_code == 200:
print('Success!')
print(response.text)
else:
print('An error occurred. Status code:', response.status_code)
folder_path = 'c:\\spots'
random_video = get_random_mp4_file(folder_path)
if random_video:
video_path = os.path.join(folder_path, random_video)
print(f'Selected random video: {video_path}')
send_request(video_path)
else:
print('No suitable MP4 file found in the folder.')
3. Streaming
This script, when executed, checks the vMix API XML for the streaming status every 1 minute. If it sees that stream 1 or 2 is not running, it tries to restart it.
Code:
import requests
import time
import xml.etree.ElementTree as ET
API_URL = "http://127.0.0.1:8088/api/"
CHECK_INTERVAL = 60 # Check for status in intervals
def get_streaming_status():
response = requests.get(API_URL)
xml_data = response.content
root = ET.fromstring(xml_data)
streaming = root.find('streaming')
channel1 = streaming.get('channel1') == 'True'
channel2 = streaming.get('channel2') == 'True'
return channel1, channel2
def stop_streaming(value):
requests.get(API_URL, params={"Function": "StopStreaming", "Value": value})
def start_streaming(value):
requests.get(API_URL, params={"Function": "StartStreaming", "Value": value})
while True:
channel1_status, channel2_status = get_streaming_status()
if not channel1_status:
print("Stream1 stopped. Stream1 Restarted...")
stop_streaming(0)
time.sleep(2)
start_streaming(0)
if not channel2_status:
print("Stream2 stopped. Stream2 Restarted...")
stop_streaming(1)
time.sleep(2)
start_streaming(1)
time.sleep(CHECK_INTERVAL)
4. Overlay script on time
I asked AI to create this script for me with the purpose of being able to play a GT title at a specific time during the day, with a duration that I define and on the overlay channel I want it to play. When executed, it requests the relevant information to run. It can also work with regular inputs.
Code:
import time
import requests
from datetime import datetime, timedelta
def send_http_request(overlay, input_name, action):
url = f"http://127.0.0.1:8088/api/?Function=OverlayInput{overlay}{action}&Input={input_name}"
response = requests.get(url)
print(f"Event executed, response: {response.text}")
# Asks from user to enter details
gt_name = input("Enter name: ")
overlay_channel = input("Enter overlay channel number (1-4): ")
while int(overlay_channel) not in [1, 2, 3, 4]:
print("No valid overlay number. It has to be 1, 2, 3, ή 4.")
overlay_channel = input("Enter overlay channel (1-4): ")
event_time_str = input("Enter time for the event (HH:MM:SS): ")
event_time = datetime.strptime(event_time_str, "%H:%M:%S")
event_duration_str = input("Enter duration for event minutes:seconds (MM:SS): ")
event_duration = datetime.strptime(event_duration_str, "%M:%S")
event_duration_seconds = event_duration.minute * 60 + event_duration.second
while event_duration_seconds < 1 or event_duration_seconds > 18000:
print("No valid Duration.")
event_duration_str = input("Enter duration for the event minutes:seconds (MM:SS): ")
event_duration = datetime.strptime(event_duration_str, "%M:%S")
event_duration_seconds = event_duration.minute * 60 + event_duration.second
input_name = gt_name.replace(" ", "%20")
def send_http_request(overlay, input_name, action):
url = f"http://127.0.0.1:8088/api/?Function=OverlayInput{overlay}{action}&Input={input_name}"
response = requests.get(url)
print(f"Event executed ({action}), response: {response.text}")
# Executes the event when time comes
while True:
now = datetime.now().time()
if now >= event_time.time():
send_http_request(overlay_channel, input_name, "In")
time.sleep(event_duration_seconds)
next_event_time = datetime.now() + timedelta(seconds=event_duration_seconds)
print(f"Overlay channel is off {next_event_time.time()}")
send_http_request(overlay_channel, input_name, "Out")
break
else:
time.sleep(1) # wait for 1 second before check again
Guide to install python in your pc to be able to run python scripts
Please follow this guide to download and install Python on Windows so that you can execute .py scripts:
1. Go to the official Python website:
https://www.python.org/2. Hover over the "Downloads" tab at the top of the page and click on "Windows" in the dropdown menu.
3. On the Windows download page, click on the latest Python release (e.g., Python 3.10.x). This will take you to the release page.
4. Scroll down to the "Files" section and download the appropriate installer for your system. For most users, the "Windows Installer (64-bit)" will be suitable. If you are using a 32-bit version of Windows, choose the "Windows Installer (32-bit)".
5. Once the installer has been downloaded, locate the file in your Downloads folder and double-click on it to run the installer.
6. In the installer window, make sure to check the box next to "Add Python to PATH" at the bottom of the window. This will make it easier to run Python scripts from the command prompt.
7. Click on "Install Now" to start the installation process. The installer will copy the necessary files to your computer and set up Python.
8. Once the installation is complete, you can close the installer window.
9. To verify that Python was installed correctly, open the Command Prompt by pressing the Windows key, typing "cmd" and hitting Enter.
10. In the Command Prompt, type "python --version" and press Enter. You should see the Python version you just installed displayed in the output (e.g., Python 3.10.x).
Now you have successfully installed Python on your Windows computer and can execute .py scripts. To run a script, navigate to the folder containing the script using the Command Prompt (use the "cd" command followed by the folder path), then type "python script_name.py" and press Enter. Replace "script_name.py" with the name of the script you want to execute.
Or you can make directly double click on your *.py file and it will run.
For some of the scripts, you may need to install additional libraries, such as the Python requests library, using the command "pip install requests".
To install the requests library, follow these steps:
1. First, make sure you have Python and pip (the package installer for Python) installed on your computer. If you haven't installed Python yet, please refer to the previous guide on downloading and installing Python on Windows.
2. Open the Command Prompt by pressing the Windows key, typing "cmd" and hitting Enter.
3. In the Command Prompt, type the following command and press Enter:
```
pip install requests
```
This command will download and install the requests library.
4. Once the installation is complete, you should see a message indicating that the library was successfully installed.
Now you have the requests library installed, and you can use it in your Python scripts that require it. To import the library in your script, add the following line at the beginning of your script:
```python
import requests
```
This will make the requests library available for use in your script.
That's it for now.
I would like to thank all the people who selflessly help in the forum. I'd like to emphasize that I am not a programmer and everything I do is based on many trials and experimentation. Before using anything in a real video production, make sure everything works as you desire.Let me know your thoughts or anything else you want to share. Take care. Happy Easter and Good Resurrection to all of you, with health and love.