1

My code is below, it's pretty much complete, however a tiny part I am stuck on.

Basically what the code does is, based on a Song, the script goes out to a couple of websites on the internet to bring back the song label, composer & year that the song was released.

Only thing is, with the particular song Alicia Keys - Girl On Fire, if you manually go to the website http://staff.australian-charts.com/showitem.asp?interpret=Alicia+Keys+feat%2E+Nicki+Minaj&titel=Girl+On+Fire&cat=s you will notice that there is more than one Composer listed under the Music/Lyrics section.

In the event the song has more than one composer, my script below in it's current state will grab the first composer listed only.

What I need is for the script to grab all the composers. If there's one composer, or if there are multiple composers, I need them captured in the format of "Composer1, Composer2, Composer3, Composer4" etc (Commas included)

I am thinking of changing the Invoke-Webrequest to get TABLES back and particular tables with rows etc, not sure....

$song = "Alicia Keys - Girl On Fire"
Write-Host $song
$SearchSong = $song -replace '\(' -replace '\)' -replace '&' -replace ' - ', ' ' -replace '\s','+'
$MatchSong = $song -replace ' - ', '&titel=' -replace '\s','\+'

#Check iTunes for music Label information
$uri = "https://itunes.apple.com/search?term=$SearchSong&country=au&entity=song"
$x = Invoke-WebRequest -Uri $uri
$iTunesResults = ($x.Content | ConvertFrom-Json).results
$y = Invoke-WebRequest -Uri $iTunesResults[0].trackViewUrl
$iTunesSongCopyright = ($y.ParsedHtml.getElementsByTagName('li') | ? {$_.ClassName -eq 'copyright'}).innerText -replace '℗ '
$iTunesSongLabel = $iTunesSongCopyright -replace '.*\d\s'

#The check australian-charts for Composer & Year infomation
$domain = 'http://staff.australian-charts.com/'
$uri = $domain + "search.asp?search=$SearchSong&cat=s"
$x = Invoke-WebRequest -Uri $uri

$x.AllElements[462].outerHTML -match 'A.href="(.*)"';$resultURL = $domain + $Matches[1]
$resultURL = $resultURL -replace("&","&") -replace('"','"')

$y = Invoke-WebRequest -Uri $resultURL

$Element = ($y.AllElements | ? {$_.tagName -eq 'HTML'})

    if($Element.innerText -match 'Music\/Lyrics:(.*)')
    {
        $Element.innerText -match 'Music\/Lyrics:(.*)'
        $Composer = $Matches[1]
        Write-Host $Composer

    } else {

        $Composer = $null
    }

    if($Element.innerText -match 'Year:(.*)')
    {
        $Element.innerText -match 'Year:(.*)'
        $Year = $Matches[1]
        Write-Host $Year

    } else {

        $Year = $null
    }

    Write-Host $iTunesSongLabel
2
  • Hi Marc, there is no need to repeat the -match inside the if curly brackets - the $matches[1] are still valid. Commented Dec 3, 2016 at 10:14
  • If you dot source your script and take a look at $elements.innertext you will notice that it takes a different approac to grep multiline elements with a regex, maybe differentiate with the html dom Commented Dec 3, 2016 at 11:10

1 Answer 1

1

you can use this for getting composer list :

 if($Element.innerText -match 'Music\/Lyrics:(.*)')
    {
    $startpos = $Element.innertext.IndexOf("Lyrics:") + 7
    $endpos = $Element.innertext.IndexOf("Producer:") -1
    $composer=$Element.innertext.substring($startpos,($endpos - $startpos))
    #even the below line will give the same result as the above line if uncommented
    #$composer = $Element.innertext[$startpos..$endpos] -join ""
    Write-Host $Composer

    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.