2023-05-03 21:21:04 +00:00
|
|
|
import "pkg:/source/api/baserequest.brs"
|
|
|
|
import "pkg:/source/utils/config.brs"
|
|
|
|
import "pkg:/source/roku_modules/log/LogMixin.brs"
|
|
|
|
|
2022-01-09 00:04:38 +00:00
|
|
|
sub init()
|
2023-05-03 21:21:04 +00:00
|
|
|
m.log = log.Logger("RecordProgramTask")
|
2022-01-09 05:43:17 +00:00
|
|
|
m.top.functionName = "RecordOrCancelProgram"
|
2022-01-09 00:04:38 +00:00
|
|
|
end sub
|
|
|
|
|
2022-01-09 05:43:17 +00:00
|
|
|
sub RecordOrCancelProgram()
|
2022-01-09 00:04:38 +00:00
|
|
|
if m.top.programDetails <> invalid
|
2022-01-09 05:43:17 +00:00
|
|
|
' Are we setting up a recording or canceling one?
|
|
|
|
TimerId = invalid
|
|
|
|
if m.top.programDetails.json.TimerId <> invalid and m.top.programDetails.json.TimerId <> ""
|
|
|
|
TimerId = m.top.programDetails.json.TimerId
|
|
|
|
end if
|
|
|
|
|
|
|
|
if TimerId = invalid
|
|
|
|
' Setting up a recording...
|
|
|
|
programId = m.top.programDetails.Id
|
2022-01-09 00:04:38 +00:00
|
|
|
|
2022-01-09 06:06:56 +00:00
|
|
|
' Get Live TV default params from server...
|
2022-01-09 05:43:17 +00:00
|
|
|
url = "LiveTv/Timers/Defaults"
|
|
|
|
params = {
|
|
|
|
programId: programId
|
|
|
|
}
|
2022-01-09 00:04:38 +00:00
|
|
|
|
2022-01-09 05:43:17 +00:00
|
|
|
resp = APIRequest(url, params)
|
|
|
|
data = getJson(resp)
|
|
|
|
|
|
|
|
if data <> invalid
|
|
|
|
' Create recording timer...
|
|
|
|
if m.top.recordSeries = true
|
|
|
|
url = "LiveTv/SeriesTimers"
|
|
|
|
else
|
|
|
|
url = "LiveTv/Timers"
|
|
|
|
end if
|
|
|
|
resp = APIRequest(url)
|
|
|
|
postJson(resp, FormatJson(data))
|
2022-01-09 14:56:10 +00:00
|
|
|
m.top.programDetails.hdSmallIconUrl = "pkg:/images/red.png"
|
2022-01-09 05:43:17 +00:00
|
|
|
else
|
|
|
|
' Error msg to user?
|
2023-05-03 21:21:04 +00:00
|
|
|
m.log.error("Could not retrieve live TV Defaults from Server")
|
2022-01-09 05:43:17 +00:00
|
|
|
end if
|
|
|
|
else
|
|
|
|
' Cancelling a recording...
|
2022-01-09 04:40:25 +00:00
|
|
|
if m.top.recordSeries = true
|
2022-01-09 05:43:17 +00:00
|
|
|
TimerId = m.top.programDetails.json.SeriesTimerId
|
|
|
|
url = Substitute("LiveTv/SeriesTimers/{0}", TimerId)
|
2022-01-09 04:40:25 +00:00
|
|
|
else
|
2022-01-09 05:43:17 +00:00
|
|
|
url = Substitute("LiveTv/Timers/{0}", TimerId)
|
2022-01-09 04:40:25 +00:00
|
|
|
end if
|
2022-01-09 00:04:38 +00:00
|
|
|
resp = APIRequest(url)
|
2022-01-09 05:43:17 +00:00
|
|
|
deleteVoid(resp)
|
2022-01-09 14:56:10 +00:00
|
|
|
m.top.programDetails.hdSmallIconUrl = invalid
|
2022-01-09 00:04:38 +00:00
|
|
|
end if
|
|
|
|
end if
|
|
|
|
|
2022-01-09 05:43:17 +00:00
|
|
|
m.top.recordOperationDone = true
|
2022-01-09 00:04:38 +00:00
|
|
|
end sub
|