Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
rytsikau authored Feb 2, 2021
1 parent 1ed1526 commit 86c0706
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 0 deletions.
8 changes: 8 additions & 0 deletions auto.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
rem EXAMPLES
rem First line saves 1 minute of live stream - from 05:00am to 05:01am
rem Second line saves 30 minutes of live stream - from 15:00pm to 15:30pm

powershell "& '%CD%\ee.record_bbc2.ps1' 0500 1"
powershell "& '%CD%\ee.record_bbc2.ps1' 1500 30"

pause & exit
125 changes: 125 additions & 0 deletions ee.record_bbc2.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
'--------------------------------------------------------------------------------------------------'
' ee.record_bbc2 (2021-02-02) '
'--------------------------------------------------------------------------------------------------'
set-executionpolicy unrestricted -scope currentuser
$erroractionpreference = "silentlycontinue"; remove-variable *; $erroractionpreference = "continue"
$dtScript = get-date

# Stream parameters
$dtRefer = [datetime]::ParseExact('20210101-000000','yyyyMMdd-HHmmss', $null)
$seqRefer = 251476315
$seqDuration = 6400
$urlInit = "https://as-dash-ww-live.akamaized.net/pool_904/live/ww/" `
+ "bbc_radio_two/bbc_radio_two.isml/dash/bbc_radio_two-audio=96000.dash"
$urlSeq = "https://as-dash-ww-live.bbcfmt.s.llnwi.net/pool_904/live/ww/" `
+ "bbc_radio_two/bbc_radio_two.isml/dash/bbc_radio_two-audio=96000-[seqNumber].m4s"

# Save parameters
$fileName = "bbc_radio_two_[start]_[duration]min.mp4"
$pathSave = (get-item $psscriptroot).fullname + "\recordings"
if (!(test-path $pathSave)) { new-item -itemtype directory $pathSave | out-null }


# FUNCTION OF DOWNLOADING
#<#-------------------------------------------------------------------------------------------------
function Downloader($seqBegin, $seqEnd, $fileName)
{
$fileNameTmp = $fileName.Replace(".mp4", "_TMP$(Get-Random).mp4")
$fs = [System.IO.File]::OpenWrite("$pathSave\$fileNameTmp")

$fs.Position = $fs.Length
$content = (New-Object System.Net.WebClient).DownloadData($urlInit)
$fs.Write($content, 0, $content.Length)

for ($i = $seqBegin; $i -le $seqEnd; $i++)
{
$fs.Position = $fs.Length
$content = (New-Object System.Net.WebClient).DownloadData($urlSeq.Replace("[seqNumber]", $i))
$fs.Write($content, 0, $content.Length)

$span = (new-timespan $dtRefer $(get-date)).TotalMilliseconds / $seqDuration
$seqCurrent = $seqRefer + $span
if ($i -gt $seqCurrent) { start-sleep -milliseconds $seqDuration }
}

$fs.Close()

Rename-Item "$pathSave\$fileNameTmp" -NewName $fileName
}
#-------------------------------------------------------------------------------------------------#>


"$(get-date) / 1. Parse START - 1st argument [HHmm]"
#<#-------------------------------------------------------------------------------------------------
if ($args[0] -like "default")
{
$dtStart = $dtScript
}
else
{
try
{
$dtStart = [datetime]::ParseExact($args[0],'HHmm', $null)
if ($(get-date) -lt $dtStart) { $dtStart = $dtStart.AddDays(-1) }
}
catch
{
write-host "Error! Check START - 1st argument [HHmm]"
exit
}
}
#-------------------------------------------------------------------------------------------------#>


"$(get-date) / 2. Parse DURATION - 2nd argument [minutes]"
#<#-------------------------------------------------------------------------------------------------
if ($args[1] -like "default")
{
$tsDuration = [timespan]::FromMinutes(60)
}
else
{
try
{
$tsDuration = [timespan]::FromMinutes($args[1])
}
catch
{
write-host "Error! Check DURATION - 2nd argument [minutes]"
exit
}
}
#-------------------------------------------------------------------------------------------------#>


"$(get-date) / 3. Generate file name, check if it exists"
#<#-------------------------------------------------------------------------------------------------
$fileName = $fileName.Replace("[start]", $dtStart.ToString("yyyyMMdd-HHmm"))
$fileName = $fileName.Replace("[duration]", $tsDuration.Minutes.ToString('0000'))
if (test-path "$pathSave\$fileName")
{
write-host "Error! File already exists"
exit
}
#-------------------------------------------------------------------------------------------------#>


"$(get-date) / 4. Calculate first and last sequences"
#<#-------------------------------------------------------------------------------------------------
$seqBegin = [int]($seqRefer + (new-timespan $dtRefer $dtStart).TotalMilliseconds / $seqDuration)
$numberOfSequences = [int]($tsDuration.TotalMilliseconds / $seqDuration)
$seqEnd = $seqBegin + $numberOfSequences - 1
#-------------------------------------------------------------------------------------------------#>


"$(get-date) / 5. Download media"
#<#-------------------------------------------------------------------------------------------------
write-host " saving: $fileName"
Downloader $seqBegin $seqEnd $fileName
#-------------------------------------------------------------------------------------------------#>


"$(get-date) / 6. Finished!"
#<#-------------------------------------------------------------------------------------------------
$erroractionpreference = "silentlycontinue"; remove-variable *; $erroractionpreference = "continue"
#-------------------------------------------------------------------------------------------------#>
18 changes: 18 additions & 0 deletions manual.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@echo off
set SCRIPTNAME=ee.record_bbc2
echo %SCRIPTNAME%

echo.
echo START TIME
echo To download any part from the last 24 hours of stream, enter the start time as [HHmm], in 24-hour format
echo To record from now, just press Enter
set /p START=Type start time as [HHmm]:
if [%START%]==[] set START="default"

echo.
echo DURATION
set /p DURATION=Type required duration in minutes:
if [%DURATION%]==[] set DURATION="default"

powershell "& '%CD%\%SCRIPTNAME%.ps1' %START% %DURATION%"
pause & exit

0 comments on commit 86c0706

Please sign in to comment.