Jump to content

CD Cover Finder


sheeva
 Share

Recommended Posts

Hi,

I have write this code to find cd cover using www.gracenote.com

this script is very simple for now (is intended to come a function later)

So, the script ask for an artist or (and) album title so it do a request on gracenote site then download the cover founded

then a popup come and you can click on the right cover.

if any people have any idea to enhance this script (especially to make a better result) just modifie it as you like.

#include <Array.au3>
#include <Inet.au3>
#include <String.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#cs
    Script is supposed to search cover of a specific album on www.gracenote.com
    then display a selection in a popup window 
#ce

DIM $Infos[1][3],$PIC[18],$Label[18],$FCOV[1]
Global $Found,$Old,$Display = 0

#Region ### START Koda GUI section ### Form=
$CoverWin   = GUICreate("Cover Approximated", 741, 818, -1, -1)
$PIC[0]     =   GUICtrlCreatePic("", 8, 16, 170, 170,  BitOR($SS_NOTIFY,$WS_BORDER))
$PIC[1]     =   GUICtrlCreatePic("", 192, 16, 170, 170,  BitOR($SS_NOTIFY,$WS_BORDER))
$PIC[2]     =   GUICtrlCreatePic("", 376, 16, 170, 170,  BitOR($SS_NOTIFY,$WS_BORDER))
$PIC[3]     =   GUICtrlCreatePic("", 560, 16, 170, 170,  BitOR($SS_NOTIFY,$WS_BORDER))
$PIC[4]     =   GUICtrlCreatePic("", 8, 200, 170, 170,  BitOR($SS_NOTIFY,$WS_BORDER))
$PIC[5]     =   GUICtrlCreatePic("", 192, 200, 170, 170,  BitOR($SS_NOTIFY,$WS_BORDER))
$PIC[6]     =   GUICtrlCreatePic("", 376, 200, 170, 170,  BitOR($SS_NOTIFY,$WS_BORDER))
$PIC[7]     =   GUICtrlCreatePic("", 560, 200, 170, 170,  BitOR($SS_NOTIFY,$WS_BORDER))
$PIC[8]     =   GUICtrlCreatePic("", 8, 384, 170, 170,  BitOR($SS_NOTIFY,$WS_BORDER))
$PIC[9]     =   GUICtrlCreatePic("", 192, 384, 170, 170,  BitOR($SS_NOTIFY,$WS_BORDER))
$PIC[10]    =   GUICtrlCreatePic("", 376, 384, 170, 170,  BitOR($SS_NOTIFY,$WS_BORDER))
$PIC[11]    =   GUICtrlCreatePic("", 560, 384, 170, 170,  BitOR($SS_NOTIFY,$WS_BORDER))
$PIC[12]    =   GUICtrlCreatePic("", 8, 568, 170, 170,  BitOR($SS_NOTIFY,$WS_BORDER))
$PIC[13]    =   GUICtrlCreatePic("", 192, 568, 170, 170,  BitOR($SS_NOTIFY,$WS_BORDER))
$PIC[14]    =   GUICtrlCreatePic("", 376, 568, 170, 170,  BitOR($SS_NOTIFY,$WS_BORDER))
$PIC[15]    =   GUICtrlCreatePic("", 560, 568, 170, 170,  BitOR($SS_NOTIFY,$WS_BORDER))
$Cancel     =   GUICtrlCreateButton("Cancel", 321, 750, 100, 50, 0)
#EndRegion ### END Koda GUI section ###


DirRemove(@ScriptDir & "\GraceNote",1)
DirCreate(@ScriptDir & "\GraceNote")

$GL = "http://www.gracenote.com"
$Q = InputBox("test","Artist and Album Separate like 'Artist - Album' or just Album or Artist Name")

$Q = StringReplace($Q,"_"," ")

$Query = StringSplit($Q,"-")

if @error <> 1 then ; Si l'entrer est en deux partie
    $T = TimerInit()
    _QuakeTheNote($Query[1])
Else
    $T = TimerInit()
    _QuakeTheNote($Q)
EndIf

exit

Func _QuakeTheNote($Req)
    Local $Cover = 0
    $Req = StringReplace($Req," ","+")
    ConsoleWrite($Req & @crlf)
    $Grace = _INetGetSource("http://www.gracenote.com/search/?query=" & $Req & "&search_type=album")
;~  $Grace = _INetGetSource("http://www.gracenote.com/search/?query=" & $Req & "&search_type=track")
;~  $Grace = _INetGetSource("http://www.gracenote.com/search/?query=" & $Req & "&search_type=artist")
;~  ConsoleWrite($Grace)
    $Result = _StringBetween($Grace,'<div class="item"','<br clear="all">')
    $Grace2 = _ArrayToString($Result)
    ; ------------------------------ Seraching Album Name ------------------------------------------------------------------------------------------
    $Album = _StringBetween($Grace2,'<strong>Album:</strong>','/a><br>')
    $Album2 = _ArrayToString($Album)
    $Album3 = _StringBetween($Album2,'>','<')
    if $Album3 <> 0 Then
        $Index = _ArrayMaxIndex($album3)
    Else
        return -1
        ProgressOff()
    EndIf
    ; ------------------------------ Searching Artist Name -----------------------------------------------------------------------------------------
    $Artist = _StringBetween($Grace2,'<strong>Artist:</strong>','/a>')
    $Artist2 = _ArrayToString($Artist)
    $Artist3 = _StringBetween($Artist2,'> ','<')
    ; ------------------------------ Searching Album Cover ------------------------------------------------------------------------------------------
    $Link = _StringBetween($Grace2,'<div class="album-image" style="border:1px solid #ccc">','width="75" height="75" border="0"></a>')
    $Grace3 = _ArrayToString($Link)
    $Link2 = _StringBetween($Grace3,'<img src="','" ')
    ; ----------------------------- Populating $Infos ------------------------------------------------------------------------------------------------ 
    Redim $Infos[$Index+1][3]

    for $AN = 0 to $Index
        $Infos[$AN][0] = $Artist3[$AN]
        $Infos[$AN][1] = $album3[$AN]
        $Infos[$AN][2] = $Link2[$AN]
    Next
    _ArraySort($Infos, 0, 0, 0, 2) ; Sorting by Cover Link !!! much eazyer to find double cover.
    _ArrayDisplay($Infos)
    ; ----------------------------- Processing Entry ------------------------------------------------------------------------------------------------
    ProgressOn("GraceNote","Downloading")
    
    For $i = 0 to $Index
        If Not StringInStr($infos[$i][2],"/covers/default/75/default_cover") Then ; not processing Default Cover
            
            If StringTrimRight($Query[1],1) = $Infos[$i][0] then ; Parfaite Correspondance 
                
                ConsoleWrite("Exact Correspondance Founded" & @CRLF)
                FileDelete(@ScriptDir & "\GraceNote\*.jpg") ; If prefect on is founded erasing all other jpg and saving Good One
                ProgressSet(($i/$Index)*100)
                ConsoleWrite("Downloading : " & $i & "->" & $GL & $Infos[$i][2] & @CRLF)
                InetGet($GL & $Infos[$i][2],@ScriptDir & "\GraceNote\" & StringReplace($Req,"+"," ") & "_" & $Cover & ".jpg",1,0)
                $Cover = $Cover + 1
                ProgressOff()
                Return
                
            Else
                
                if $old <> $infos[$i][2] then ; Enlève les Doublons eventuels
                    
                    $display = 1
                    ConsoleWrite($Infos[$i][0] & @CRLF & $Infos[$i][1] & " = Approximating Result" & @CRLF)
                    ProgressSet(($i/$Index)*100)
                    ConsoleWrite("Downloading : " & $i & "->" & $GL & $Infos[$i][2] & @CRLF)
                    ; si les nom contienent des '/' ça marche pô....
                    InetGet($GL & $Infos[$i][2],@ScriptDir & "\GraceNote\" & StringReplace($Req,"+"," ") & "_" & $Cover & ".jpg",1,0)
                    GUICtrlSetImage($Pic[$cover],@ScriptDir & "\GraceNote\" & StringReplace($Req,"+"," ") & "_" & $Cover & ".jpg")
                    _ArrayAdd($FCOV,@ScriptDir & "\GraceNote\" & StringReplace($Req,"+"," ") & "_" & $Cover & ".jpg")
                    $Cover = $Cover + 1
                    $Old = $Infos[$i][2]
                    
                EndIf
            EndIf
        EndIf
    Next
    
    ProgressOff()
    
    if $display = 1 Then
        _ArrayDelete($FCOV,0)
        GUISetState(@SW_SHOW,$CoverWin)
        
        While 1 ; Boucle d'attente des Selection de Covers
            $nMsg = GUIGetMsg()
            for $T = 0 to _ArrayMaxIndex($FCOV)
                Switch $nMsg
                    Case $GUI_EVENT_CLOSE
                        Return
                    Case $Cancel
                        Return
                    Case $Pic[$T]
                        ConsoleWrite($FCOV[$T] & @CRLF)
                EndSwitch
            next
        Sleep(25)
        WEnd
    EndIf
    
EndFunc

Any Help are welcome. :D

Link to comment
Share on other sites

Works well but it's kinda useless

Hi Jjo,

This script is just for test purpose. (it's my participation to this WONDERFULL forum)

of course if any user have any enhancement, i take it. :D

Users can freely use it. :D

Just think of a directory scan instead of a simple inputbox() function.

anyway thank's to your test.

Regards.

Link to comment
Share on other sites

Thanks for sharing!

I haven't tested it yet, but it looks promising to add to my CD Cover program (addon to my CDIni Database program). I must get around to uploading latest versions of both ... though the CD Cover addon is still incomplete. Life is just too busy at mo ... and I'm just a little too burnt out lately ... not much programming.

@skrip - good idea!

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

Thanks for sharing!

I haven't tested it yet, but it looks promising to add to my CD Cover program (addon to my CDIni Database program). I must get around to uploading latest versions of both ... though the CD Cover addon is still incomplete. Life is just too busy at mo ... and I'm just a little too burnt out lately ... not much programming.

@skrip - good idea!

Just add it freely to your CDini Database or any other script. Let me now when it's done.

Just add a little 'thank's' if possible :D

Enjoy.

Link to comment
Share on other sites

Just add it freely to your CDini Database or any other script. Let me now when it's done.

Just add a little 'thank's' if possible :D

Enjoy.

Not a worry, I always give credit where it's due!

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...