Skip to content

Instantly share code, notes, and snippets.

@lastbattle
Last active January 9, 2024 20:11
Show Gist options
  • Save lastbattle/6eeeccd0802a18fdff22be4d5ec2a7cf to your computer and use it in GitHub Desktop.
Save lastbattle/6eeeccd0802a18fdff22be4d5ec2a7cf to your computer and use it in GitHub Desktop.
Recursively download youtube videos from multiple channels/playlist, and sync local folder to Azure (Windows Powershell + youtube-dl) --- regain your sovereignty by backing up, dont get deplatformed!
# ##### Uploading changes to Azure blob storage
$CurDirectory = Get-Location;
"Uploading changes from '$CurDirectory' directory to Azure Blob storage...";
azcopy sync $CurDirectory 'https://xxx.blob.core.windows.net/containername' --recursive=true --exclude-path '_CommitFiles.ps1'
# Download all videos from the playlist/channel to the current folder.
# Place this in each individual folder along with the URL.
# For more information on downloading https://github.com/ytdl-org/youtube-dl#configuration
# -- alternative youtube-dl https://github.com/yt-dlp/yt-dlp
$Command = "../_youtube-dl.exe"
$Parms = @('-i', 'YOUR YOUTUBE URL OR PLAYLIST GOES HERE', '--geo-bypass', '-f', 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best')
$Prms = $Parms.Split(" ")
& "$Command" $Prms
### You need PowerShell module 4.4.0 or newer in order to be able to tier blobs to archive storage
Install-module Azure -requiredVersion 4.4.0
Install-Module -Name Azure.Storage -RequiredVersion 4.6.1
Install-Module AzureRM -AllowClobber
Set-ExecutionPolicy RemoteSigned
Get-ExecutionPolicy -List
Get-InstalledModule -Name Azure -AllVersions
Get-InstalledModule -Name Azure.Storage -AllVersions
Get-InstalledModule -Name AzureRM -AllVersions
# ##### Changing file tiers on Azure Blob Storage to Archive to reduce cost
# https://github.com/TomJanetscheck/AzurePS/blob/master/BlobLevelTiering/tierBlobsToArchive.ps1
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.1
Import-Module AzureRM.profile
### Import Azure PowerShell module
Import-Module Azure
### Login to your Azure Account
Login-AzureRmAccount
### Storage Account information
### In case you have several subscriptions select the proper one
Select-AzureRmSubscription (Get-AzureRMSubscription | Out-GridView -Title "Select your Azure Subscription" -PassThru)
### Select the Azure Resource Group and Storage Account
$ResourceGroupName = (Get-AzureRmResourceGroup | Out-GridView -Title "Select your Resource Group" -PassThru).ResourceGroupName
$StorageAccount = Get-AzureRmStorageAccount -ResourceGroupName $ResourceGroupName | Out-GridView -Title "Select your Storage Account" -PassThru
$StorageAccountKey = (Get-AzureRmStorageAccountKey -ResourceGroupName $ResourceGroupName -Name $StorageAccount.StorageAccountName)[0].Value
### Create a storage context
$context = New-AzureStorageContext -StorageAccountName $StorageAccount.StorageAccountName -StorageAccountKey $StorageAccountKey
$containername = (Get-AzureStorageContainer -Context $context | Out-GridView -Title "Select your Storage Container" -PassThru).name
$blobs = Get-AzureStorageBlob -Container $containerName -Context $context
### Use the .Net client library API to change the access tier
Foreach ($blob in $blobs) {
$blob.ICloudBlob.SetStandardBlobTier("Archive")
}
pause
https://docs.microsoft.com/en-us/azure/storage/common/storage-use-azcopy-blobs-synchronize
Setup: https://docs.microsoft.com/en-us/azure/storage/common/storage-use-azcopy-v10
# All services -> Storage accounts -> storage -> Shared Access Signature to create the SAS URL.
# https://gist.github.com/lastbattle/6eeeccd0802a18fdff22be4d5ec2a7cf
# The main .ps1 Windows Powershell script to recursively execute all sub folder containing
# '_Download.ps1'
$Directories = Get-ChildItem -Recurse –Directory;
$CurDirectory = Get-Location;
$FileName = ".\_Download.ps1";
Foreach ($item in $Directories)
{
# Set current path to save the files in
$Directory = -join($CurDirectory, "\", $item, "\");
Set-Location -Path $Directory
# Execute
"Executing $Directory $FileName";
& $FileName
}
pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment