ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Post New Requests Here

IDEA - Create a text doc of an artists discography.

<< < (5/5)

4wd:
Now uses Chrome's UserAgent and can set a delay from the command line:


--- Code: PowerShell ---<#  .\DiscoFile-MB3.ps1 -uri <Uri> [-delay <seconds>]   Given the URI from https://musicbrainz.org for an artist it will retrieve the  discography.   Where: Uri     = MusicBrainz artist page URI         seconds = [optional] number of seconds delay between Web Requests (0.1-90)    eg.   .\DiscoFile-MB3.ps1 -uri https://musicbrainz.org/artist/66c662b6-6e2f-4930-8610-912e24c63ed1   .\DiscoFile-MB3.ps1 -uri https://musicbrainz.org/artist/66c662b6-6e2f-4930-8610-912e24c63ed1 -delay 10   Will result in a file called 'AC_DC-MB - Discography.txt' in the same directory as  DiscoFile-MB3.ps1 #>param (        [Parameter(Mandatory=$true)][string]$Uri,        [ValidateRange(0.1,90)][decimal]$delay)$sleep = $falseif ($delay -gt 0) {  $sleep = $true}$userAgent = [Microsoft.PowerShell.Commands.PSUserAgent]::Chrome $web = (Invoke-WebRequest -Uri $Uri -UserAgent $userAgent).RawContent $temp = $web -replace '[\s\S]+application\/ld\+json..([\s\S]+?)<\/script>[\s\S]*$', '$1'$json = $temp | ConvertFrom-Json $outFile = ($json.name + "-MB - Discography.txt").Split([IO.Path]::GetInvalidFileNameChars()) -join '_'if (Test-Path $outFile) {  Remove-Item $outFile -Force} for ($i = 0; $i -lt $json.album.Count; $i++) {  if ($sleep) {    Start-Sleep -seconds $delay  }  $temp = $json.album[$i].albumReleaseType  if ($temp -match 'AlbumRelease') {    $temp = $json.album[$i].albumProductionType    if (($temp -match '(LiveAlbum)|(StudioAlbum)') -and !($temp -match '(CompilationAlbum)|(SoundtrackAlbum)')) {      $albumUri = ($json.album[$i].'@id' + "?inc=releases&fmt=json") -replace '\.org\/', '.org/ws/2/'      $album = (Invoke-WebRequest -Uri "$($albumUri)" -UserAgent $userAgent) | ConvertFrom-Json      "$($album.releases[0].date.Substring(0,4)) - $($album.title)" | Out-File -FilePath $outFile -Append    }  }} Get-Content $outFile | Sort-Object | Set-Content $outFile

Navigation

[0] Message Index

[*] Previous page

Go to full version