Skip to content

Commit

Permalink
Check for existing tag
Browse files Browse the repository at this point in the history
  • Loading branch information
johnthebrit committed Mar 1, 2024
1 parent de7c872 commit aba93c5
Showing 1 changed file with 32 additions and 21 deletions.
53 changes: 32 additions & 21 deletions YouTube/PopulateBlobTags.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,43 @@ $blobs = Get-AzStorageBlob -Container $storageContainer -Context $storageContext
foreach ($blob in $blobs)
{
Write-Output "Working on $($blob.name)"
$docName = $blob.Name -replace "\.txt$", "" #remove only from end of the string
$cleanDocName = $docName -replace '[^a-zA-Z0-9]', ''

$videoMatch = $null
$props = $blob.blobclient.GetProperties()

$videoDetails.keys | ForEach-Object {
$maxLength = [Math]::Min($cleanDocName.Length, $_.Length)
if($props.Value.Metadata.DocName -eq $null)
{
Write-Output "No metadata found, adding"

$docName = $blob.Name -replace "\.txt$", "" #remove only from end of the string
$cleanDocName = $docName -replace '[^a-zA-Z0-9]', ''

$videoMatch = $null

# Compare the substrings
if ($cleanDocName.Substring(0, $maxLength) -eq $_.Substring(0, $maxLength)) {
Write-Host "Found match $($videoDetails.$_)"
$videoMatch = $videoDetails.$_
$videoDetails.keys | ForEach-Object {
$maxLength = [Math]::Min($cleanDocName.Length, $_.Length)

# Compare the substrings
if ($cleanDocName.Substring(0, $maxLength) -eq $_.Substring(0, $maxLength)) {
Write-Host "Found match $($videoDetails.$_)"
$videoMatch = $videoDetails.$_
}
}
}

Write-Output $videoDetails.$docName
Write-Output $videoDetails.$docName

$metadata = New-Object System.Collections.Generic.Dictionary"[String,String]"
$metadata.Add("DocName",$docName)
if($videoMatch -ne $null)
{
$metadata.Add("VideoURL","https://youtu.be/$videoMatch")
}else
{
$metadata.Add("VideoURL","https://www.youtube.com/channel/UCpIn7ox7j7bH_OFj7tYouOQ")
}
$metadata = New-Object System.Collections.Generic.Dictionary"[String,String]"
$metadata.Add("DocName",$docName)
if($videoMatch -ne $null)
{
$metadata.Add("VideoURL","https://youtu.be/$videoMatch")
}else
{
$metadata.Add("VideoURL","https://www.youtube.com/channel/UCpIn7ox7j7bH_OFj7tYouOQ")
}

$blob.BlobClient.SetMetadata($metadata, $null)
$blob.BlobClient.SetMetadata($metadata, $null)
}
else {
Write-Output "Existing metadata found, skipping"
}
}

0 comments on commit aba93c5

Please sign in to comment.