logo

Live Production Software Forums


Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
mitchstein443  
#1 Posted : Sunday, January 13, 2019 7:45:58 AM(UTC)
mitchstein443

Rank: Advanced Member

Groups: Registered
Joined: 4/11/2015(UTC)
Posts: 61
Man
United States
Location: Home

Thanks: 7 times
Was thanked: 3 time(s) in 3 post(s)
powershell script that update titles in real time for wht is currently playing, what will play next and what time the next title will play.

Please understand this script was originally written by someone else on these forums, i have been modifying it over the last three years to add the up next, the time or the up next and to update my website with what is up next... it is sloppy as hell because it is from mind to script nd not formtted at all. I have been using this script or about two years and it works 24/7 requiring a dedicated computer to vmix and this script of at least a core2 3.2 gig processor, nvidia graphics card and 2 gigs ram MINIMUM for running at 420p.

For the last 6 months I ran this at 720p on a lenova thinkpad i7 with 4 gigs ram and an nvidia geforce video built in.

both systems would saturate the ram in about 6.5 days, due to memory bleed in powershell and also in some versions of vmix, so i have it all startup automatically and schedualed an automatic reboot every 7 days.

I run the videos through a vmix input list that has been as long as 13 days of videos with no problems.

I inivite someone or people to modify ts script to use the api list function to pull the next playing data instead of requiring a text file list (aafixed.mu3)

aafixed.mu3 is simply an export of the list input.

I also have found that it is import to have the inputs in this order

input 1 = my channel logo(a gif file)
input 2 = newsHD5.xmal (now playing title)
input 3 = newsHD2.xmal (upnext title with built in clock)
input 4 = List - (The list you will play.)

here is the code...

#--[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')

$thread = [System.Threading.Thread]::CurrentThread
$thread.Priority = "Lowest"

#The input number for the Vmix Title to Change
$input_no = "NewsHD5.xaml"
#The name of the title field to modify, on NewsHD.xaml would either be Headline or Description
$title_name = "Description"
#The number of sleeps before transitioning out
$trans_no = 5
$lasttitle = ""
$xmlurl = "http://127.0.0.1:8088/API/"
$apicallurl1 = "http://127.0.0.1:8088/API/?Function=SetText&Input=$input_no&SelectedName=$title_name&Value="
$transinurl = "http://127.0.0.1:8088/API/?Function=OverlayInput1In&Input=$input_no"
$transouturl = "http://127.0.0.1:8088/API/?Function=OverlayInput1Out&Input=$input_no"
$transcount = 0
while ($true) {
[xml]$data = (New-Object System.Net.WebClient).DownloadString($xmlurl)
$node = $data.SelectNodes("/vmix/inputs/input[@state='Running']")
$title = ($node | Select-Object -ExpandProperty title | Out-String)
$dura = ($node | Select-Object -ExpandProperty duration | Out-String)
$position = ($node | Select-Object -ExpandProperty position | Out-String)
$list = ($node | Select-Object -ExpandProperty list | Out-String)
$timeremaining = $dura - $position
$timeremaining = $timeremaining / 1000
write-host "timeremaining $timeremaining"
write-host "duration $dura"
write-host "position $position"

$title = $title-replace ".mp4",""
$title = $title-replace "List - ",""
$title = $title-replace "USB 2861 Device",""
$title = $title-replace "NDI ",""
$title = $title-replace "MITCH-PC ",""
$title = $title-replace "(vTask - Output 1)",""
#$title=$title.Substring(2)
$title-replace "()"
if ($lasttitle -ne $title) {
write-host "Updating Vmix input $input_no - $title_name"
write-host "With:$title"
$apicallurl = $apicallurl1 + $title
write-host $apicallurl
(New-Object System.Net.WebClient).DownloadString("$apicallurl")
Start-Sleep -Seconds 2
write-host "Transitioning $input_no In"
(New-Object System.Net.WebClient).DownloadString("$transinurl")
$transcount = 1


#$currentfile = "c:\livetv\11-8-2017\" + $title + ".mp4"
$reader = [System.IO.File]::OpenText("c:\livetv\aafixed.m3u")
$a = 0
$title = $title.Trim()
while($null -ne ($line = $reader.ReadLine())) {
$a = $a + 1
#write-host "$a - testing line -- $line"
#$currentfilepath = "c:\livetv" + $line
$currentfilepath = $line
$line = $line.split('.')[0]
$line = $line.Trim("\"," ")
$line = $line.Split('\')[$($line.Split('\').Count-1)]
#$line = $line + ".mp4"
#$currentfile = $title.Substring(0,$title.Length-1)
#if ($line -ne "30 second station ad"){write-host "$a - title =$title -----line =$line"}
#$line = $line.tostring()
#$currentfile = $currentfile.tostring()
if ($title -eq $line) {$a = 100

write-host "*****************************************Match Found%%%%%%%%%%%%%%%%%%%"
$nexttitle = ($reader.ReadLine())

$nexttitle = ($reader.ReadLine())
$nexttitle = $nexttitle.split('.')[0]
$nexttitle = $nexttitle.Split('\')[$($nexttitle.Split('\').Count-1)]
if ($line -ne "30 second station ad"){
(New-Object System.Net.WebClient).DownloadString("http://127.0.0.1:8088/API/?Function=SetText&Input=3&SelectedName=Description&Value=$nexttitle")



write-host "updating up next with $nexttitle"
}


#----------------removed from here________________
$folder = $currentfilepath.Substring(0, $currentfilepath.lastIndexOf('\'))
#$folder = "c:\livetv" + $folder
#$folder = "\\mitch-pc\g\livetv$folder"
#write-host "folder path = $folder"
$File = $line + ".mp4"
#write-host "filename = $File"
$LengthColumn = 27
$objShell = New-Object -ComObject Shell.Application
$objFolder = $objShell.Namespace($Folder)
$objFile = $objFolder.ParseName($File)
$Length = $objFolder.GetDetailsOf($objFile, $LengthColumn)
write-host "length of file -- $Length ..... $Dura"


$ts = New-TimeSpan -seconds $timeremaining
$nexttime = [DateTime]::Now.AddSeconds($timeremaining)
$nexttime = $nexttime.ToString('hh:mm:ss tt')
#$pos = $nexttime.IndexOf(" ")
#$leftPart = $nexttime.Substring(0, $pos)
#$rightPart = $nexttime.Substring($pos+1)
#$nexttime = $rightpart

write-host "nexttime is -- $nexttime"


$nextheadlinetitle = "Up Next @ "
$nextheadlinetitle = $nextheadlinetitle + $nexttime
(New-Object System.Net.WebClient).DownloadString("http://127.0.0.1:8088/API/?Function=SetText&Input=3&SelectedName=Headline&Value=$nextheadlinetitle")
write-host "updateing the headline with $nextheadlinetitle"
(New-Object System.Net.WebClient).DownloadString("http://www.tvbydemand.com/live_tv_update.asp?nexttitle=$nexttitle&nextheadlinetitle=$nextheadlinetitle&currenttitle=$title")

(New-Object System.Net.WebClient).DownloadString("http://127.0.0.1:8088/api/?Function=StartStreaming")

}


}


}
if ($title -eq "30 second station Ad" ) {
(New-Object System.Net.WebClient).DownloadString("$transouturl")
}


write-host "------waiting-------"
Start-Sleep -Seconds 20
$lasttitle = $title
if ($transcount -eq $trans_no) {
write-host "Transitioning $input_no Out"
(New-Object System.Net.WebClient).DownloadString("$transinurl")
}
$transcount++
if ($Host.UI.RawUI.KeyAvailable -and ("q" -eq $Host.UI.RawUI.ReadKey("IncludeKeyUp,NoEcho").Character)) {
Write-Host "Exiting now..."
break;
}






}
thanks 1 user thanked mitchstein443 for this useful post.
mjgraves on 1/15/2019(UTC)
mitchstein443  
#2 Posted : Monday, May 6, 2019 6:48:39 PM(UTC)
mitchstein443

Rank: Advanced Member

Groups: Registered
Joined: 4/11/2015(UTC)
Posts: 61
Man
United States
Location: Home

Thanks: 7 times
Was thanked: 3 time(s) in 3 post(s)
I've fixed up the script a bit, cleaned it up and added a line toupdate a website with what is currently playing and what will play next.
I also added a function to shut the script down and start it back up due to powershell's crappy memory handling..

The next part of this script will be to create and maintain a "tv-guide" by passing the information to a website that will actually use the data to create a "tv-guide" page...

It'd be nice to also add fade in and out titles that shows up coming shows...

This script and VMIX has been moved from my old (well over 10 years old) core2 system to an I5 dell desktop. Also the 24/7 channel is now at 1080p 3.5mbs instead of 480p 1.5mbs it is now about 5 years of using vmix to run a 24/7 channel, still going strong!


Anyway here is the script:

#--[void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')

$thread = [System.Threading.Thread]::CurrentThread
$thread.Priority = "Lowest"

#The input number for the Vmix Title to Change
$input_no = "2"
#The name of the title field to modify, on NewsHD.xaml would either be Headline or Description
$title_name = "Description.Text"
#The number of sleeps before transitioning out
$trans_no = 5
$lasttitle = ""
$xmlurl = "http://127.0.0.1:8088/API/"
$apicallurl1 = "http://127.0.0.1:8088/API/?Function=SetText&Input=$input_no&SelectedName=$title_name&Value="
$transinurl = "http://127.0.0.1:8088/API/?Function=OverlayInput1In&Input=$input_no"
$transouturl = "http://127.0.0.1:8088/API/?Function=OverlayInput1Out&Input=$input_no"
$transcount = 0
$timera = 0 # setup for restarting the script
while ($true) {


#create a timer to shutdown this script and reopen it in another instance
$timera = $timera + 1
Write-Host $timera + " timera `r`n`r`n`r`n"
If ($timera -eq 1000) {
Invoke-Item (start powershell ((Split-Path $MyInvocation.InvocationName) + "\vtitle.ps1"))
exit}
#timer done

[xml]$data = (New-Object System.Net.WebClient).DownloadString($xmlurl)
$node = $data.SelectNodes("/vmix/inputs/input[@state='Running']")
$title = ($node | Select-Object -ExpandProperty title | Out-String)
$dura = ($node | Select-Object -ExpandProperty duration | Out-String)
$position = ($node | Select-Object -ExpandProperty position | Out-String)

write-host "$dura"
$dura = $dura.Split("`r`n")[2]; #split was added after last vmix upgrade because it returned alot of junk before the needed data
Write-Host "duration after split $dura :"
$dura =[INT]$dura
Write-Host "$dura"

Write-Host "position = $position"
$position = $position.Split("`r`n")[10]; #split was added after last vmix upgrade because it returned alot of junk before the needed data
Write-Host "position after split $position :"
$position =[INT]$position

$timeremaining = $dura - $position
$timeremaining = $timeremaining / 1000
write-host "timeremaining $timeremaining"
write-host "duration $dura"
write-host "position $position"

$title = $title-replace ".mp4",""
$title = $title-replace "List - ",""
$title = $title-replace "USB 2861 Device",""
$title = $title-replace "NDI ",""
$title = $title-replace "MITCH-PC ",""
$title = $title-replace "(vTask - Output 1)",""
$title = $title-replace "Title 13- Wipe Out Blue.gtzip",""
$title = $title-replace "`r`n",""


#$title=$title.Substring(2)
$title-replace "()"
if ($lasttitle -ne $title) {
write-host "Updating Vmix input $input_no - $title_name"
write-host "With:$title"
$apicallurl = $apicallurl1 + $title
write-host $apicallurl
(New-Object System.Net.WebClient).DownloadString("$apicallurl")
Start-Sleep -Seconds 2
write-host "Transitioning $input_no In"
(New-Object System.Net.WebClient).DownloadString("$transinurl")
$transcount = 1


#$currentfile = "d:\livetv\11-8-2017\" + $title + ".mp4"
$reader = [System.IO.File]::OpenText("d:\livetv\aafixed.m3u") #path to the exported list that is currently playing I want to make it pull this from the xml data eventually
$a = 0
$title = $title.Trim()
while($null -ne ($line = $reader.ReadLine())) {
$a = $a + 1
#write-host "$a - testing line -- $line"
#$currentfilepath = "d:\livetv" + $line
$currentfilepath = $line
$line = $line.split('.')[0]
$line = $line.Trim("\"," ")
$line = $line.Split('\')[$($line.Split('\').Count-1)]
#$line = $line + ".mp4"
#$currentfile = $title.Substring(0,$title.Length-1)
if ($line -ne "30 second station ad"){write-host "$a - title =$title -----line =$line"}
#$line = $line.tostring()
#$currentfile = $currentfile.tostring()
if ($title -eq $line) {$a = 100

write-host "*****************************************Match Found%%%%%%%%%%%%%%%%%%%"
$nexttitle = ($reader.ReadLine())

$nexttitle = ($reader.ReadLine())
$nexttitle = $nexttitle.split('.')[0]
$nexttitle = $nexttitle.Split('\')[$($nexttitle.Split('\').Count-1)]

if ($line -ne "30 second station ad"){
(New-Object System.Net.WebClient).DownloadString("http://127.0.0.1:8088/API/?Function=SetText&Input=3&SelectedName=Description&Value=$nexttitle")



write-host "updating up next with $nexttitle"

}


#----------------removed from here________________
$folder = $currentfilepath.Substring(0, $currentfilepath.lastIndexOf('\'))

$File = $line + ".mp4"
#write-host "filename = $File"
$LengthColumn = 27

write-host "length of file -- $Length ..... $Dura"


$ts = New-TimeSpan -seconds $timeremaining
$nexttime = [DateTime]::Now.AddSeconds($timeremaining)
$nexttime = $nexttime.ToString('hh:mm:ss tt')

write-host "nexttime is -- $nexttime"


$nextheadlinetitle = "Up Next @ "
$nextheadlinetitle = $nextheadlinetitle + $nexttime + " : " + $nexttitle
(New-Object System.Net.WebClient).DownloadString("http://127.0.0.1:8088/API/?Function=SetText&Input=3&SelectedName=Heading&Value=$nextheadlinetitle")
write-host "updateing the headline with $nextheadlinetitle"
(New-Object System.Net.WebClient).DownloadString("http://www.tvbydemand.com/live_tv_update.asp?nexttitle=$nexttitle&nextheadlinetitle=$nextheadlinetitle&currenttitle=$title")

(New-Object System.Net.WebClient).DownloadString("http://127.0.0.1:8088/api/?Function=StartStreaming")

}


}


}



write-host "------waiting-------"
Start-Sleep -Seconds 10
$lasttitle = $title
if ($transcount -eq $trans_no) {
write-host "Transitioning $input_no Out"
(New-Object System.Net.WebClient).DownloadString("$transinurl")
}
$transcount++
if ($Host.UI.RawUI.KeyAvailable -and ("q" -eq $Host.UI.RawUI.ReadKey("IncludeKeyUp,NoEcho").Character)) {
Write-Host "Exiting now..."
break;
}






}
thanks 1 user thanked mitchstein443 for this useful post.
studiodelta on 4/12/2021(UTC)
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.