Last active
March 12, 2025 14:03
-
-
Save SysProfile/da297bcd982ac79aa017b649296e6a00 to your computer and use it in GitHub Desktop.
vMix Script Weather Information with Automatic Location Detection
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
'Cómo se utiliza el código | |
'How to use the code | |
' | |
'Label: Temperature | |
'Dim strTemp As String = String.Format("{0:0.0}", Microsoft.VisualBasic.Val(xmlDoc.SelectSingleNode("/current/temperature").Attributes("value").Value)) | |
'API.Function("SetText", Input:="My input", Value:=strTemp, SelectedName:="myTitle.Text") | |
' | |
'This command changes the background image: | |
'Dim strImage As String = "http://openweathermap.org/img/wn/" & xmlDoc.SelectSingleNode("/current/weather").Attributes("icon").Value & ".png" | |
'API.Function("SetImage", Input:="My input", Value:= strImage) | |
' | |
'This command changes the second picture | |
'API.Function("SetImage", Input:="My input", SelectedName:="Image Object", Value:= strImage) | |
'English descriptions | |
Dim htDescEN As New System.Collections.Hashtable() | |
'Thunderstorm | |
htDescEN.Add("200", "Thunderstorm with light rain") | |
htDescEN.Add("201", "Thunderstorm with rain") | |
htDescEN.Add("202", "Thunderstorm with heavy rain") | |
htDescEN.Add("210", "Light thunderstorm") | |
htDescEN.Add("211", "Thunderstorm") | |
htDescEN.Add("212", "Heavy thunderstorm") | |
htDescEN.Add("221", "Ragged thunderstorm") | |
htDescEN.Add("230", "Thunderstorm with light drizzle") | |
htDescEN.Add("231", "Thunderstorm with drizzle") | |
htDescEN.Add("232", "Thunderstorm with heavy drizzle") | |
'Drizzle | |
htDescEN.Add("300", "Light intensity drizzle") | |
htDescEN.Add("301", "Drizzle") | |
htDescEN.Add("302", "Heavy intensity drizzle") | |
htDescEN.Add("310", "Light intensity drizzle rain") | |
htDescEN.Add("311", "Drizzle rain") | |
htDescEN.Add("312", "Heavy intensity drizzle rain") | |
htDescEN.Add("313", "Shower rain and drizzle") | |
htDescEN.Add("314", "Heavy shower rain and drizzle") | |
htDescEN.Add("321", "Shower drizzle") | |
'Rain | |
htDescEN.Add("500", "Light rain") | |
htDescEN.Add("501", "Moderate rain") | |
htDescEN.Add("502", "Heavy intensity rain") | |
htDescEN.Add("503", "Very heavy rain") | |
htDescEN.Add("504", "Extreme rain") | |
htDescEN.Add("511", "Freezing rain") | |
htDescEN.Add("520", "Light intensity shower rain") | |
htDescEN.Add("521", "Shower rain") | |
htDescEN.Add("522", "Heavy intensity shower rain") | |
htDescEN.Add("531", "Ragged shower rain") | |
'Snow | |
htDescEN.Add("600", "Light snow") | |
htDescEN.Add("601", "Snow") | |
htDescEN.Add("602", "Heavy snow") | |
htDescEN.Add("611", "Sleet") | |
htDescEN.Add("612", "Light shower sleet") | |
htDescEN.Add("613", "Shower sleet") | |
htDescEN.Add("615", "Light rain and snow") | |
htDescEN.Add("616", "Rain and snow") | |
htDescEN.Add("620", "Light shower snow") | |
htDescEN.Add("621", "Shower snow") | |
htDescEN.Add("622", "Heavy shower snow") | |
'Atmosphere | |
htDescEN.Add("701", "Mist") | |
htDescEN.Add("711", "Smoke") | |
htDescEN.Add("721", "Haze") | |
htDescEN.Add("731", "Sand/dust whirls") | |
htDescEN.Add("741", "Fog") | |
htDescEN.Add("751", "Sand") | |
htDescEN.Add("761", "Dust") | |
htDescEN.Add("762", "Volcanic ash") | |
htDescEN.Add("771", "Squall") | |
htDescEN.Add("781", "Tornado") | |
'Clear | |
htDescEN.Add("800", "Clear sky") | |
'Clouds | |
htDescEN.Add("801", "Few clouds: 11-25%") | |
htDescEN.Add("802", "Scattered clouds: 25-50%") | |
htDescEN.Add("803", "Broken clouds: 51-84%") | |
htDescEN.Add("804", "Overcast clouds: 85-100%") | |
'Descriptions in Spanish | |
Dim htDescES As New System.Collections.Hashtable() | |
'Tormenta | |
htDescES.Add("200", "Tormenta eléctrica con lluvia ligera") | |
htDescES.Add("201", "Tormenta con lluvia") | |
htDescES.Add("202", "Tormenta eléctrica con fuertes lluvias") | |
htDescES.Add("210", "Tormenta ligera") | |
htDescES.Add("211", "Tormenta") | |
htDescES.Add("212", "Fuerte tormenta eléctrica") | |
htDescES.Add("221", "Tormenta eléctrica irregular") | |
htDescES.Add("230", "Tormenta eléctrica con llovizna ligera") | |
htDescES.Add("231", "Tormenta eléctrica con llovizna") | |
htDescES.Add("232", "Tormenta eléctrica con llovizna intensa") | |
'Llovizna | |
htDescES.Add("300", "Llovizna de intensidad ligera") | |
htDescES.Add("301", "Llovizna") | |
htDescES.Add("302", "Llovizna de fuerte intensidad") | |
htDescES.Add("310", "Lluvia llovizna de intensidad ligera") | |
htDescES.Add("311", "Llovizna lluvia") | |
htDescES.Add("312", "Lluvia lloviznosa de fuerte intensidad") | |
htDescES.Add("313", "Ducha lluvia y llovizna") | |
htDescES.Add("314", "Lluvias fuertes y lloviznas") | |
htDescES.Add("321", "Llovizna de ducha") | |
'Lluvia | |
htDescES.Add("500", "Lluvia ligera") | |
htDescES.Add("501", "Lluvia moderada") | |
htDescES.Add("502", "Lluvia de fuerte intensidad") | |
htDescES.Add("503", "Lluvia muy fuerte") | |
htDescES.Add("504", "Lluvia extrema") | |
htDescES.Add("511", "Lluvia helada") | |
htDescES.Add("520", "Lluvia de intensidad ligera") | |
htDescES.Add("521", "Lluvia ligera") | |
htDescES.Add("522", "Lluvia de fuerte intensidad") | |
htDescES.Add("531", "Lluvia torrencial") | |
'Nieve | |
htDescES.Add("600", "Nieve ligera") | |
htDescES.Add("601", "Nieve") | |
htDescES.Add("602", "Nevada intensa") | |
htDescES.Add("611", "Aguanieve") | |
htDescES.Add("612", "Chubasco ligero aguanieve") | |
htDescES.Add("613", "Aguanieve") | |
htDescES.Add("615", "Lluvia ligera y nieve") | |
htDescES.Add("616", "Lluvia y nieve") | |
htDescES.Add("620", "Chubasco ligero de nieve") | |
htDescES.Add("621", "Lluvia de nieve") | |
htDescES.Add("622", "Fuerte nevada") | |
'Atmósfera | |
htDescES.Add("701", "neblina") | |
htDescES.Add("711", "Fumar") | |
htDescES.Add("721", "Bruma") | |
htDescES.Add("731", "Remolinos de arena/polvo") | |
htDescES.Add("741", "Niebla") | |
htDescES.Add("751", "Arena") | |
htDescES.Add("761", "Polvo") | |
htDescES.Add("762", "Ceniza volcánica") | |
htDescES.Add("771", "Borrascas") | |
htDescES.Add("781", "Tornado") | |
'Claro | |
htDescES.Add("800", "Cielo despejado") | |
'Nubes | |
htDescES.Add("801", "Pocas nubes: 11-25%") | |
htDescES.Add("802", "Nubes dispersas: 25-50%") | |
htDescES.Add("803", "Nubes dispersas: 51-84%") | |
htDescES.Add("804", "Nubes cubiertas: 85-100%") | |
Dim xmlDoc As XmlDocument | |
Dim wc = New System.Net.WebClient | |
wc.Encoding = System.Text.Encoding.UTF8 | |
wc.Headers.Add("Cache-Control", "no-cache") | |
wc.Headers.Add("User-Agent", "Mozilla/5.0") | |
Dim strXMLContent As String = String.Empty | |
Dim strEndPoint As String = String.Empty | |
'EN: Delete the comment from the localization site you want to use. | |
'ES: Elimina el comentario del sitio de localización que deseas utilizar. | |
'strEndPoint = "http://ip-api.com/xml/" | |
strEndPoint = "https://ipwhois.app/xml/" | |
Try | |
strXMLContent = wc.DownloadString(strEndPoint) | |
xmlDoc = New XmlDocument | |
xmlDoc.LoadXML(strXMLContent) | |
Catch ex As Exception | |
strXMLContent = "Error: " & ex.Message | |
End Try | |
If xmlDoc IsNot Nothing Then | |
Dim strLat As String = String.Empty | |
Dim strLon As String = String.Empty | |
Select Case strEndPoint | |
Case "http://ip-api.com/xml/" | |
strLat = xmlDoc.SelectSingleNode("/query/lat").InnerText | |
strLon = xmlDoc.SelectSingleNode("/query/lon").InnerText | |
Case "https://ipwhois.app/xml/" | |
strLat = xmlDoc.SelectSingleNode("/query/latitude").InnerText | |
strLon = xmlDoc.SelectSingleNode("/query/longitude").InnerText | |
End Select | |
Try | |
'Usted debe cambiar donde dice API_KEY con su API del sitio https://openweathermap.org/api. Debe utilizar la opción gratuita | |
'You must change the API_KEY field to your API from the https://openweathermap.org/api site. You must use the free option. | |
Dim strURL As String = "https://api.openweathermap.org/data/2.5/weather?" | |
strURL &= "lat=" & strLat | |
strURL &= "&lon=" & strLon | |
strURL &= "&appid=API_KEY" | |
strURL &= "&lang=es&mode=xml&units=metric" | |
strXMLContent = wc.DownloadString(strURL) | |
xmlDoc = New XmlDocument | |
xmlDoc.LoadXML(strXMLContent) | |
'Seleccione uno o varios de los siguientes ítems que desea utillizar | |
'Select one or more of the following items you wish to use | |
Console.WriteLine("city id: " & xmlDoc.SelectSingleNode("/current/city").Attributes("id").Value) | |
Console.WriteLine("city name: " & xmlDoc.SelectSingleNode("/current/city").Attributes("name").Value) | |
Console.WriteLine("city coord lon: " & xmlDoc.SelectSingleNode("/current/city/coord").Attributes("lon").Value) | |
Console.WriteLine("city coord lat: " & xmlDoc.SelectSingleNode("/current/city/coord").Attributes("lat").Value) | |
Console.WriteLine("city country: " & xmlDoc.SelectSingleNode("/current/city/country").InnerText) | |
Dim shtSeconds As Short = CShort(xmlDoc.SelectSingleNode("/current/city/timezone").InnerText) | |
Dim tsSeconds As TimeSpan = TimeSpan.FromSeconds(shtSeconds) | |
Console.WriteLine("city timezone (in seconds): " & shtSeconds) | |
Console.WriteLine("city timezone (h:mm): " & tsSeconds.Hours.ToString & ":" & tsSeconds.Minutes.ToString.PadLeft(2, "0")) | |
Console.WriteLine("city sun rise: " & xmlDoc.SelectSingleNode("/current/city/sun").Attributes("rise").Value) | |
Console.WriteLine("city sun set: " & xmlDoc.SelectSingleNode("/current/city/sun").Attributes("set").Value) | |
Console.WriteLine("temperature value: " & String.Format("{0:0.0}", Microsoft.VisualBasic.Val(xmlDoc.SelectSingleNode("/current/temperature").Attributes("value").Value))) | |
Console.WriteLine("temperature min: " & String.Format("{0:0.0}", Microsoft.VisualBasic.Val(xmlDoc.SelectSingleNode("/current/temperature").Attributes("min").Value))) | |
Console.WriteLine("temperature max: " & String.Format("{0:0.0}", Microsoft.VisualBasic.Val(xmlDoc.SelectSingleNode("/current/temperature").Attributes("max").Value))) | |
Console.WriteLine("temperature unit: " & xmlDoc.SelectSingleNode("/current/temperature").Attributes("unit").Value) | |
Console.WriteLine("feels_like value: " & String.Format("{0:0.0}", Microsoft.VisualBasic.Val(xmlDoc.SelectSingleNode("/current/feels_like").Attributes("value").Value))) | |
Console.WriteLine("feels_like unit: " & xmlDoc.SelectSingleNode("/current/feels_like").Attributes("unit").Value) | |
Console.WriteLine("humidity value: " & xmlDoc.SelectSingleNode("/current/humidity").Attributes("value").Value) | |
Console.WriteLine("humidity unit: " & xmlDoc.SelectSingleNode("/current/humidity").Attributes("unit").Value) | |
Console.WriteLine("pressure value: " & xmlDoc.SelectSingleNode("/current/pressure").Attributes("value").Value) | |
Console.WriteLine("pressure unit: " & xmlDoc.SelectSingleNode("/current/pressure").Attributes("unit").Value) | |
Console.WriteLine("wind speed value: " & xmlDoc.SelectSingleNode("/current/wind/speed").Attributes("value").Value) | |
Console.WriteLine("wind speed unit: " & xmlDoc.SelectSingleNode("/current/wind/speed").Attributes("unit").Value) | |
Console.WriteLine("wind speed name: " & xmlDoc.SelectSingleNode("/current/wind/speed").Attributes("name").Value) | |
If xmlDoc.SelectSingleNode("/current/wind/gusts").Attributes("value") IsNot Nothing Then | |
Console.WriteLine("wind gusts value: " & xmlDoc.SelectSingleNode("/current/wind/gusts").Attributes("value").Value) | |
End If | |
Console.WriteLine("wind direction value: " & xmlDoc.SelectSingleNode("/current/wind/direction").Attributes("value").Value) | |
Console.WriteLine("wind direction code: " & xmlDoc.SelectSingleNode("/current/wind/direction").Attributes("code").Value) | |
Console.WriteLine("wind direction name: " & xmlDoc.SelectSingleNode("/current/wind/direction").Attributes("name").Value) | |
Console.WriteLine("clouds value: " & xmlDoc.SelectSingleNode("/current/clouds").Attributes("value").Value) | |
Console.WriteLine("clouds name: " & xmlDoc.SelectSingleNode("/current/clouds").Attributes("name").Value) | |
Console.WriteLine("visibility value: " & xmlDoc.SelectSingleNode("/current/visibility").Attributes("value").Value) | |
Console.WriteLine("precipitation mode: " & xmlDoc.SelectSingleNode("/current/precipitation").Attributes("mode").Value) | |
Console.WriteLine("weather weather number: " & xmlDoc.SelectSingleNode("/current/weather").Attributes("number").Value) | |
Console.WriteLine("weather weather value: " & xmlDoc.SelectSingleNode("/current/weather").Attributes("value").Value) | |
Console.WriteLine("weather weather icon: " & xmlDoc.SelectSingleNode("/current/weather").Attributes("icon").Value) | |
Console.WriteLine("weather weather icon x1 URI: " & "http://openweathermap.org/img/wn/" & xmlDoc.SelectSingleNode("/current/weather").Attributes("icon").Value & ".png") | |
Console.WriteLine("weather weather icon x2 URI: " & "http://openweathermap.org/img/wn/" & xmlDoc.SelectSingleNode("/current/weather").Attributes("icon").Value & "@2x.png") | |
Console.WriteLine("weather weather desc ES: " & htDescES.Item(xmlDoc.SelectSingleNode("/current/weather").Attributes("number").Value)) | |
Console.WriteLine("weather weather desc EN: " & htDescEN.Item(xmlDoc.SelectSingleNode("/current/weather").Attributes("number").Value)) | |
Console.WriteLine("lastupdate value: " & xmlDoc.SelectSingleNode("/current/lastupdate").Attributes("value").Value) | |
Catch ex As Exception | |
strXMLContent = "Error: " & ex.Message ' Maneja el error sin congelar vMix | |
End Try | |
End If | |
wc.Dispose() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment