GeeXboX

Extracting info music file

October 11th, 2013

Home Forums GeeXboX on ARM SoCs Extracting info music file

This topic contains 2 replies, has 2 voices, and was last updated by skelos 4 days, 5 hours ago.

Viewing 3 posts – 1 through 3 (of 3 total)
  • Author
    Posts
  • #7081

    skelos
    Moderator

    Hello.
    I’m making a script for autoidentify music files. I recovered music data from a webservice and I obtains something like this:

    {“status”: “ok”, “results”: [{“recordings”: [{“artists”: [{“id”: “4dd6b6cd-7e05-44f2-9d58-7b523a161643”, “name”: “Piccolo coro dell’Antoniano”}], “duration”: 182, “releasegroups”: [{“secondarytypes”: [“Compilation”], “type”: “Album”, “id”: “1dd1ddf3-2cb1-3f07-945b-93490f850a7d”, “title”: “Grandi successi dello Zecchino d’Oro”}], “title”: “Quarantaquattro gatti”, “id”: “9de37de1-925a-47e9-b776-27f6d6cb5730″}, {“artists”: [{“id”: “04ba9285-19d9-4b6f-bd82-357c96130507”, “name”: “Coccodrillo Band”}], “duration”: 187, “releasegroups”: [{“secondarytypes”: [“Compilation”], “type”: “Album”, “id”: “ee0dc7af-8278-493f-a5fb-cdd0a1e15a39″, “title”: “Il coccodrillo come fa??”}], “title”: “44 gatti”, “id”: “ee6e1d2c-b7c3-4fbf-960e-eeefc5e38068″}], “score”: 0.938291, “id”: “a65416d2-2c6f-4ff4-9827-cf55e149e21d”}]}’

    to be clear I indent it:

    {"status": "ok", "results": 
       [{"recordings": 
          [
           {"artists": 
             [{"id": "4dd6b6cd-7e05-44f2-9d58-7b523a161643", "name": "Piccolo coro dell'Antoniano"}]
             , "duration": 182
             , "releasegroups": 
                [
    	     {"secondarytypes": ["Compilation"], 
    	      "type": "Album", 
                  "id": "1dd1ddf3-2cb1-3f07-945b-93490f850a7d", 
                  "title": "Grandi successi dello Zecchino d'Oro"
                 }
                 ]
             , "title": "Quarantaquattro gatti"
    	 , "id": "9de37de1-925a-47e9-b776-27f6d6cb5730"
    	}
            , 
           {"artists": 
             [{"id": "04ba9285-19d9-4b6f-bd82-357c96130507", "name": "Coccodrillo Band"}]
             , "duration": 187
             , "releasegroups": 
                [
    	     {"secondarytypes": ["Compilation"],
    	      "type": "Album", 
                  "id": "ee0dc7af-8278-493f-a5fb-cdd0a1e15a39", 
                  "title": "Il coccodrillo come fa??"
                 }
                ]
             , "title": "44 gatti"
             , "id": "ee6e1d2c-b7c3-4fbf-960e-eeefc5e38068"
            }
           ]
          , "score": 0.938291
          , "id": "a65416d2-2c6f-4ff4-9827-cf55e149e21d"
       }]
    }'
    

    and put it into a variable named “txt”. It shows 2 different recordings each of them identified from :
    artist, duration , release group (with his name), title and id.

    So, I need to extract :
    – status (here is “ok” => the song is identified)
    – score (here is 0.938291 => there is 0.938291 probability to examined music is this one)

    and (only for the first recording if there are more then one)
    – Title (here “Quarantaquattro gatti”)
    – artist (here “Piccolo coro dell’Antoniano”)
    – Album (here “Grandi successi dello Zecchino d’Oro”)

    I’m thinking to regular expression but I’m not sure this will work.
    Fore recover status value I tried using :

    echo $txt | sed 's/^status": ".*",$/1/'

    but this dosn’t return nothing…

    Anyone has ideas?

    • This topic was modified 1 week ago by skelos.
    • This topic was modified 1 week ago by skelos.
    • This topic was modified 1 week ago by skelos.
    #7087

    tomlohave
    Moderator

    can you send all your results on a simple txt file ?
    It will be more easy to test.
    Cheers,

    #7091

    skelos
    Moderator

    This is the script for MP3s. Video, zip and other kind files are here not considered. This is my first script and I’m sure that you find many and many not-intelligent instructions: it is done adapting code samples find on the web. I know that same things may be done with code more more smart… please don’t laugh of me. ^_^

    #!/bin/bash
    APIKey=ALFK2ODc
    tollerance=0.90
    #file to analyze: in future will be a parameter
    FileName=/root/44gatti.mp3
    clear
    #cvalculate fpcalc
    out=$(fpcalc "$FileName")
    #adapting result
    out2=echo "$out" | tr "n" "&"
    out3="${out2/FINGERPRINT/fingerprint}"
    out4="${out3/DURATION/duration}"
    init="client=$APIKey&meta=recordings+releasegroups+compress&"
    #write file to pass to curl
    echo "$init$out4">da
    #recover webserver response
    txt=$(curl --data @da "http://api.acoustid.org/v2/lookup")
    #remove da temp file
    rm da
    #getting the status
    status=${txt:12:2}
    if [ "$status" = "ok" ]; then
        #getting score
        pos=$(echo "$txt" | awk '{print match($0,"score")}')
        let pos=pos+7
        score=${txt:$pos:7}
        echo "SCORE : $score  THRESHOLD: $tollerance"
        var=$(awk 'BEGIN{ print "'$tollerance'"<"'$score'" }')
        #if score is greather than treshold go on..
        if [ "$var" -eq 1 ]; then
           echo "The file $FileName has been recocngized"
           echo "$txt"
           echo ""
           string=${txt//"/}
           #try to extract title
           expr match "$string" '.*(title.*,)'
        else
           echo "The file $FilenNme it is recognized but i'm not sure"
        fi
    else
        echo "The file $FileName has not been recognised."
    fi

    This is the output:

      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100  4558  100   810  100  3748   1864   8627 --:--:-- --:--:-- --:--:-- 11676
    SCORE : 0.93829  THRESHOLD: 0.90
    The file /root/44gatti.mp3 has been recocngized
    {"status": "ok", "results": [{"recordings": [{"artists": [{"id": "4dd6b6cd-7e05-44f2-9d58-7b523a161643", "name": "Piccolo coro dell'Antoniano"}], "duration": 182, "releasegroups": [{"secondarytypes": ["Compilation"], "type": "Album", "id": "1dd1ddf3-2cb1-3f07-945b-93490f850a7d", "title": "Grandi successi dello Zecchino d'Oro"}], "title": "Quarantaquattro gatti", "id": "9de37de1-925a-47e9-b776-27f6d6cb5730"}, {"artists": [{"id": "04ba9285-19d9-4b6f-bd82-357c96130507", "name": "Coccodrillo Band"}], "duration": 187, "releasegroups": [{"secondarytypes": ["Compilation"], "type": "Album", "id": "ee0dc7af-8278-493f-a5fb-cdd0a1e15a39", "title": "Il coccodrillo come fa??"}], "title": "44 gatti", "id": "ee6e1d2c-b7c3-4fbf-960e-eeefc5e38068"}], "score": 0.938291, "id": "a65416d2-2c6f-4ff4-9827-cf55e149e21d"}]}
    title: 44 gatti, id: ee6e1d2c-b7c3-4fbf-960e-eeefc5e38068}], score: 0.938291,
    #

    I would find a regular espression that return
    title: 44 gatti,
    and use it also for return other parts of this string like :
    “name”: “Coccodrillo Band”
    “score”: 0.938291
    and so on…

Viewing 3 posts – 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

Comments are closed.