-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
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
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 |
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
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" | ||
#-------------------------------------------------------------------------------------------------#> |
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
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 |