diff --git a/theBrain/Resize-TheBrainNotesYouTubeThumbnail.ps1 b/theBrain/Resize-TheBrainNotesYouTubeThumbnail.ps1 index 5ef6006..96c2888 100644 --- a/theBrain/Resize-TheBrainNotesYouTubeThumbnail.ps1 +++ b/theBrain/Resize-TheBrainNotesYouTubeThumbnail.ps1 @@ -1,9 +1,9 @@ <# .SYNOPSIS - Resize YouTube thumbnails down to 30% in theBrain Notes + Resize YouTube thumbnails in TheBrain Notes. .DESCRIPTION - Scan all Markdown files in the user's Brain data directory, and apends `#$width=30p$` + Scan all Markdown files in the user's Brain data directory, and apends `#$width=50p$` to the image URL of embedded YouTube thumbnails within the Markdown files, and backs up the original notes to the Backup folder before changing the Markdown file content. @@ -19,7 +19,7 @@ PS C:\> .\Resize-TheBrainNotesYouTubeThumbnail.ps1 .NOTES - Version: 2.0.0 + Version: 2.1.0 Author: chriskyfung License: GNU GPLv3 license Original from: https://gist.github.com/chriskyfung/ff65df9a60a7a544ff12aa8f810d728a/ @@ -32,6 +32,16 @@ $ErrorActionPreference = "Stop" +<# +.PARAMETERS + Depending on the $ImageType parameter, it either finds the default YouTube + thumbnails or the resized ones. If the $ImageType is 'resized', it also takes + into account the $CurrentWidth parameter to find thumbnails of a specific width. +#> +$ImageType = 'default' # [ValidateSet('default', 'resized')] +$CurrentWidth = 30 # [ValidateRange(1,100)] +$NewWidth = 50 # [ValidateRange(1,100)] + # Look up the Notes.md files that locate under the Brain data folder and contain the YouTube thumbnail URLs. $BrainFolder = . "$PSScriptRoot\Get-TheBrainDataDirectory.ps1" $SubFolders = Get-ChildItem -Directory -Path $BrainFolder -Exclude 'Backup' @@ -42,7 +52,12 @@ $FilenameWithoutExtension = [System.IO.Path]::GetFileNameWithoutExtension($Filen $FileExtension = [System.IO.Path]::GetExtension($Filename) Write-Host 'Scanning YouTube thumbnail URLs in Brain Notes...' -$MatchInfo = Get-ChildItem -Path $SubFolders -Filter $Filename -Recurse | Select-String '\/(hq|maxres)default.jpg\)' -List + +if ($ImageType -eq 'default') { + $MatchInfo = Get-ChildItem -Path $SubFolders -Filter $Filename -Recurse | Select-String '\/(hq|maxres)default.jpg\)' -List +} else { + $MatchInfo = Get-ChildItem -Path $SubFolders -Filter $Filename -Recurse | Select-String ('\/(hq|maxres)default.jpg#\$width={0}p\$\)' -f $CurrentWidth) -List +} # For each matching result Write-Host 'Backing up and modifying Brain Notes...' @@ -57,7 +72,11 @@ ForEach ($Match in $MatchInfo) { Write-Verbose "Created --> '$BackupPath'" # Amend the link of the YouTube thumbnail with UTF8 encoding $Pattern = $Match.Matches.Value - $NewString = $Pattern.Replace(')', '#$width=30p$)') + if ($ImageType -eq 'default') { + $NewString = $Pattern.Replace(')', '#$width={0}p$)' -f $NewWidth) + } else { + $NewString = $Pattern.Replace('#$width=30p$)', '#$width={0}p$)' -f $NewWidth) + } (Get-Content $FilePath -Encoding UTF8).Replace($Pattern, $NewString) | Set-Content $FilePath -Encoding UTF8 Write-Verbose "Modified --> '$FilePath'" }