Skip to content

Commit

Permalink
update URLs, NTunes, other data calls
Browse files Browse the repository at this point in the history
  • Loading branch information
rorpage committed Oct 26, 2023
1 parent 1aa34b0 commit f9c5078
Show file tree
Hide file tree
Showing 11 changed files with 175 additions and 79 deletions.
77 changes: 73 additions & 4 deletions components/NTunesScene.brs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@ sub Init()
end sub

sub OnWasShown()
m.top.setFocus(true)

m.durationDisplay = ""
m.duration = 30
m.elapsed_time = 30
m.is_playing = false

setUpLabels()

buildNTunesTask()

setUpElapsedTimeTimer()
setUpRefreshTimer()

setUpAudio()
Expand All @@ -19,7 +25,11 @@ end sub
function setUpLabels() as void
m.current_track_title = m.top.findNode("current_track_title")
m.current_track_artist_name = m.top.findNode("current_track_artist_name")
m.current_show_name = m.top.findNode("current_show_name")

m.elapsed_time_label = m.top.findNode("elapsed_time_label")
m.duration_label = m.top.findNode("duration_label")
m.progress_bar = m.top.findNode("progress_bar")
m.progress_bar_background = m.top.findNode("progress_bar_background")

m.current_show_image_path = m.top.findNode("current_show_image_path")
m.background = m.top.findNode("background")
Expand All @@ -38,6 +48,16 @@ function setUpRefreshTimer() as void
m.refresh_timer.ObserveField("fire", "refreshData")
end function

function setUpElapsedTimeTimer() as void
m.elapsedTime_timer = m.top.findNode("elapsedTime_timer")

m.elapsedTime_timer.repeat = true
m.elapsedTime_timer.duration = 1
m.elapsedTime_timer.control = "start"

m.elapsedTime_timer.ObserveField("fire", "updateElapsedTime")
end function

function setUpAudio() as void
audiocontent = createObject("RoSGNode", "ContentNode")
audiocontent.url = "http://edge1-b.exa.live365.net/a31769"
Expand Down Expand Up @@ -74,11 +94,60 @@ function onKeyEvent(key as string, press as boolean) as boolean
end if
end function

sub updateElapsedTime()
m.elapsed_time--

if m.elapsed_time < 0 then
m.elapsed_time = 0
end if

elapsedTime = m.duration - m.elapsed_time
time_minutes = Int(elapsedTime / 60)
time_seconds = elapsedTime mod 60

time_seconds_formatted = time_seconds.tostr()

if time_seconds < 10 then
time_seconds_formatted = Substitute("0{0}", time_seconds.tostr())
end if

m.elapsed_time_label.text = Substitute("{0}:{1}", time_minutes.tostr(), time_seconds_formatted)

m.progress_bar.width = (1 - (m.elapsed_time / m.duration)) * 1820
end sub

sub onCurrentInfoChanged()
toggleVisibility(true)

current_info = m.nTunesTask.current_info["ntunes"]

m.current_track_title.text = current_info.current_track_title
m.current_track_artist_name.text = current_info.current_track_artist_name
m.current_show_name.text = current_info.current_show_name
m.current_track_artist_name.text = UCase(current_info.current_track_artist_name)

m.current_show_image_path.uri = current_info.current_show_image_path
m.background.uri = current_info.current_show_image_path
m.background.uri = current_info.current_show_blurredimage_path

refresh_duration = current_info.timeLeft

if refresh_duration <= 0 then
refresh_duration = 3
end if

m.refresh_timer.duration = refresh_duration

m.durationDisplay = current_info.durationDisplay
m.duration = current_info.duration
m.elapsed_time = refresh_duration

m.duration_label.text = current_info.durationDisplay

m.progress_bar.width = (1 - (m.elapsed_time / m.duration)) * 1820
end sub

function toggleVisibility(visible as boolean)
m.duration_label.visible = visible
m.elapsed_time_label.visible = visible

m.progress_bar.visible = visible
m.progress_bar_background.visible = visible
end function
137 changes: 77 additions & 60 deletions components/NTunesScene.xml
Original file line number Diff line number Diff line change
@@ -1,75 +1,92 @@
<?xml version="1.0" encoding="utf-8" ?>
<component name="NTunesScene" extends="SGDEXComponent" xsi:noNamespaceSchemaLocation="https://devtools.web.roku.com/schema/RokuSceneGraph.xsd" initialFocus="audio_control_button">
<component name="NTunesScene"
extends="SGDEXComponent"
xsi:noNamespaceSchemaLocation="https://devtools.web.roku.com/schema/RokuSceneGraph.xsd"
initialFocus="audio_control_button">
<script type="text/brightscript" uri="pkg:/components/NTunesScene.brs" />
<children>
<Group id="container">
<Poster id="background"
loadHeight="86.4"
loadWidth="153.6"
height="1080"
width="1920"
loadDisplayMode="scaleToFill" />
<Poster
id="current_show_image_path"
width="500"
height="500"
translation="[710, 100]" />
<Rectangle height="80" width="1920" color="0x22447134" />
<Label id="title"
text="WDWNTunes - Now Playing"
color="0xFFFFFFFF"
translation="[20, 20]">
<Font
height="1080"
width="1920"
loadDisplayMode="scaleToZoom" />
<Rectangle height="1080" width="1920" color="0x00000055" />
<LayoutGroup layoutDirection="horiz" itemSpacings="[50, 0]" translation="[50, 50]">
<Poster
id="current_show_image_path"
width="550"
height="550" />
<LayoutGroup layoutDirection="vert" itemSpacings="[0, 20]">
<Label id="current_track_artist_name"
color="0xFFFFFFAA"
horizAlign="left"
width="1200">
<Font
role="font"
uri="pkg:/components/fonts/avenir_35_light_latin.ttf"
id="avenir-light"
size="30"
/>
</Label>
<LayoutGroup translation="[0, 650]">
<Label id="current_show_name"
color="0xFFFFFFFF"
horizAlign="center"
width="1920">
<Font
role="font"
uri="pkg:/components/fonts/avenir_35_light_latin.ttf"
id="avenir-light"
size="30"
/>
size="36"
/>
</Label>
<Label id="current_track_title" text="Loading..."
color="0xFFFFFFFF"
horizAlign="center"
width="1920"
wrap="true">
<Font
role="font"
uri="pkg:/components/fonts/avenir_85_heavy_latin.ttf"
id="avenir-heavy-latin"
size="65"
/>
color="0xFFFFFFFF"
horizAlign="left"
width="1200"
wrap="true">
<Font
role="font"
uri="pkg:/components/fonts/avenir_85_heavy_latin.ttf"
id="avenir-heavy-latin"
size="55"
/>
</Label>
<Label id="current_track_artist_name"
color="0xFFFFFFFF"
horizAlign="center"
width="1920">
<Font
role="font"
uri="pkg:/components/fonts/avenir_35_light_latin.ttf"
id="avenir-light"
size="40"
/>
</LayoutGroup>
</LayoutGroup>
<Rectangle id="progress_bar_background"
visible="false" height="10" width="1820"
color="0xFFFFFF44" translation="[50, 720]" />
<Rectangle id="progress_bar" height="10" width="0"
visible="false" color="0xFFFFFFAA" translation="[50, 720]" />
<LayoutGroup translation="[50, 750]">
<LayoutGroup layoutDirection="horiz">
<Label id="elapsed_time_label"
color="0xFFFFFFFF"
horizAlign="left"
visible="false"
width="100">
<Font
role="font"
uri="pkg:/components/fonts/avenir_35_light_latin.ttf"
id="avenir-light"
size="40"
/>
</Label>
<Label id="audio_indicator" text="N" color="0xFFFFFFFF" horizAlign="center" width="1920">
<Font
role="font"
uri="pkg:/components/fonts/sosa-regular-webfont.ttf"
id="sosa-regular"
size="150"
/>
<Rectangle height="80" width="1620" color="0x00000000" />
<Label id="duration_label"
color="0xFFFFFFFF"
horizAlign="right"
visible="false"
width="100">
<Font
role="font"
uri="pkg:/components/fonts/avenir_35_light_latin.ttf"
id="avenir-light"
size="40"
/>
</Label>
<Audio id="audio_player" />
<Timer id="refresh_timer" repeat="true" duration="10" />
</LayoutGroup>
<Label id="audio_indicator" text="N" color="0xFFFFFFFF" horizAlign="center" width="1920">
<Font
role="font"
uri="pkg:/components/fonts/sosa-regular-webfont.ttf"
id="sosa-regular"
size="150"
/>
</Label>
<Audio id="audio_player" />
<Timer id="refresh_timer" repeat="true" duration="10" />
<Timer id="elapsedTime_timer" />
</LayoutGroup>
</Group>
</children>
</component>
4 changes: 2 additions & 2 deletions components/TodayScene.brs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ sub OnWasShown()

m.parks = []
m.park_id_index = 0
m.park_ids = [ "mk", "ep", "hs", "ak", "ds", "tl", "bb" ]
m.park_ids = ["mk", "ep", "hs", "ak", "ds", "tl", "bb"]

m.light_font = CreateObject("roSGNode", "Font")
m.light_font.uri = "pkg:/components/fonts/avenir_35_light_latin.ttf"
Expand Down Expand Up @@ -136,7 +136,7 @@ sub onWeatherChanged()
summary = Left(unformatted_summary, 1) + LCase(Right(unformatted_summary, Len(unformatted_summary) - 1))

m.weather.text = fahrenheit + "°F (" + celsius + "°C)" + chr(10) + summary
m.weather_icon.uri = Substitute("https://darksky.net/images/weather-icons/{0}.png", m.weather_info.currently_icon)
' m.weather_icon.uri = Substitute("https://darksky.net/images/weather-icons/{0}.png", m.weather_info.currently_icon)
end sub

sub onDateTimeChanged()
Expand Down
5 changes: 5 additions & 0 deletions components/nodes/NTunesNode.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
<field id="current_track_artist_name" type="string" />
<field id="current_show_name" type="string" />
<field id="current_show_image_path" type="string" />
<field id="current_show_blurredimage_path" type="string" />
<field id="next_track_title" type="string" />
<field id="next_track_artist_name" type="string" />

<field id="durationDisplay" type="string" />
<field id="duration" type="integer" />
<field id="timeLeft" type="integer" />
</interface>
</component>
6 changes: 3 additions & 3 deletions components/tasks/DateTimeTask.brs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
function executeTask() as void
urlTransfer = createUrlTransfer("https://vip.timezonedb.com/v2/get-time-zone?key=[key]&by=position&lat=28.4160036778&lng=-81.5811902834&format=json")
urlTransfer = createUrlTransfer("https://worldtimeapi.org/api/timezone/America/New_York")
json = getJson(urlTransfer)

datetime_info = CreateObject("roAssociativeArray")
datetime_node = CreateObject("roSGNode", "DateTimeNode")

datetime = CreateObject("roDateTime")
datetime.FromISO8601String(json.formatted)
datetime.FromISO8601String(json.datetime)

datetime_node.day_of_the_week = datetime.GetWeekday()
datetime_node.month_day = getMonthDay(datetime)
Expand All @@ -18,7 +18,7 @@ function executeTask() as void
end function

function getMonthDay(datetime) as string
months = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]
months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
month = months[datetime.GetMonth() - 1]

dayOfMonth = datetime.GetDayOfMonth().ToStr()
Expand Down
2 changes: 1 addition & 1 deletion components/tasks/DateTimeTask.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<component name="DateTimeTask" extends="BaseTask">
<interface>
<field id="datetime_info" type="associativearray" />
<field id="datetime_info" type="assocarray" />
</interface>

<script type="text/brightscript" uri="DateTimeTask.brs" />
Expand Down
13 changes: 9 additions & 4 deletions components/tasks/NTunesTask.brs
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
function executeTask() as void
urlTransfer = createUrlTransfer("https://fastpass.wdwnt.com/live365")
urlTransfer = createUrlTransfer("https://wdwntunes-api.vercel.app/api/songs/now-playing")
json = getJson(urlTransfer)

ntunes_info = CreateObject("roAssociativeArray")
current_info = CreateObject("roSGNode", "NTunesNode")

current_info.current_track_title = json["current-track"].title
current_info.current_track_artist_name = json["current-track"].artist
current_info.current_track_title = json.title
current_info.current_track_artist_name = json.artist
current_info.current_show_name = ""
current_info.current_show_image_path = json["current-track"].art
current_info.current_show_image_path = json.images.url
current_info.current_show_blurredimage_path = json.images.blurredUrl

current_info.durationDisplay = json["playback"].durationDisplay
current_info.duration = json["playback"].duration
current_info.timeLeft = json["playback"].timeLeft

ntunes_info.AddReplace("ntunes", current_info)

Expand Down
2 changes: 1 addition & 1 deletion components/tasks/NTunesTask.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<component name="NTunesTask" extends="BaseTask">
<interface>
<field id="current_info" type="associativearray" />
<field id="current_info" type="assocarray" />
</interface>

<script type="text/brightscript" uri="NTunesTask.brs" />
Expand Down
2 changes: 1 addition & 1 deletion components/tasks/TodayParkHoursTask.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<component name="TodayParkHoursTask" extends="BaseTask">
<interface>
<field id="parks" type="associativearray" />
<field id="parks" type="assocarray" />
</interface>

<script type="text/brightscript" uri="TodayParkHoursTask.brs" />
Expand Down
4 changes: 2 additions & 2 deletions components/tasks/WeatherTask.brs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function executeTask() as void
urlTransfer = createUrlTransfer("https://weather.wdwnt.com/api/wdw")
urlTransfer = createUrlTransfer("https://fastpass.wdwnt.com/weather/wdw")
json = getJson(urlTransfer)

weather_info = CreateObject("roAssociativeArray")
Expand All @@ -8,7 +8,7 @@ function executeTask() as void
weather_node.currently_summary = json.currently.summary
weather_node.currently_icon = json.currently.icon
weather_node.currently_temperature_f = Int(json.currently.temperature)
weather_node.currently_temperature_c = Int((5/9) * (json.currently.temperature - 32))
weather_node.currently_temperature_c = Int((5 / 9) * (json.currently.temperature - 32))

weather_info.AddReplace("weather", weather_node)

Expand Down
2 changes: 1 addition & 1 deletion components/tasks/WeatherTask.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<component name="WeatherTask" extends="BaseTask">
<interface>
<field id="weather_info" type="associativearray" />
<field id="weather_info" type="assocarray" />
</interface>

<script type="text/brightscript" uri="WeatherTask.brs" />
Expand Down

0 comments on commit f9c5078

Please sign in to comment.