Scrobbling from Shazam on Android via Tasker (...and PHP)
Published: 2023-10-22 23:57:11

<h1>TL; DR;</h1>
<p>Schematically:</p>
<p>Shazam on Your Android in AutoShazam Mode -&gt; Sends notifications to Android -&gt; Tasker listens and grabs notifications -&gt; Parses Notification with track metadata -&gt; Sends track metadata to Last.FM trough PHP script</p>
<h1>The long story</h1>
<p>Usually I rely for scrobbling my musical listenings on my Android Phone that the Player Apps have its own scrobbling capabality built-in. Spotify has it, VLC has it also. But if the app doesn't have it and it uses a fixed notification in your notification area with player controls on it, it's just a matter of using the wonderful [Pano Scrobbler] application. This app detects automatically this kind of notification, grabs the track metadata and sends them to last.fm . This is fine if you are listening to the music in the very app which provides the notifications, but if you are listening from music from an external source not related to your phone like online radio, or youtube ? Yes, you can use Shazam or other similar like SoundHound, but only Shazam possess continuos recognizing, which is called AutoShazam Mode. Shazam sends the automatically recognitions to a notification, but Pano Scrobbler is not able to reasd them.
Enters Tasker, the one and most complete source for automating and programming something tailored to your needs and you can't find an already made app for it: if you're a programmer this is what you want ! Tasker can read all your notifications (if you give permission to do so, of course) and you can filter by the app that generated and them and their contents.</p>
<h2>Tasker script</h2>
<p>In the XML code below, replace <code>yourserver.org</code> with your domain.</p>
<pre><code class="language-xml">&lt;TaskerData sr=&quot;&quot; dvi=&quot;1&quot; tv=&quot;6.1.32&quot;&gt;
    &lt;dmetric&gt;1080.0,2134.0&lt;/dmetric&gt;
    &lt;Profile sr=&quot;prof212&quot; ve=&quot;2&quot;&gt;
        &lt;cdate&gt;1691602106114&lt;/cdate&gt;
        &lt;clp&gt;true&lt;/clp&gt;
        &lt;edate&gt;1691601090420&lt;/edate&gt;
        &lt;flags&gt;8&lt;/flags&gt;
        &lt;id&gt;212&lt;/id&gt;
        &lt;mid0&gt;211&lt;/mid0&gt;
        &lt;nme&gt;Autoshazam Notifications&lt;/nme&gt;
        &lt;Event sr=&quot;con0&quot; ve=&quot;2&quot;&gt;
            &lt;code&gt;461&lt;/code&gt;
            &lt;pri&gt;0&lt;/pri&gt;
            &lt;App sr=&quot;arg0&quot;&gt;
                &lt;appClass&gt;com.shazam.android.activities.SplashActivity&lt;/appClass&gt;
                &lt;appPkg&gt;com.shazam.android&lt;/appPkg&gt;
                &lt;label&gt;Shazam&lt;/label&gt;
            &lt;/App&gt;
            &lt;Str sr=&quot;arg1&quot; ve=&quot;3&quot;/&gt;
            &lt;Str sr=&quot;arg2&quot; ve=&quot;3&quot;&gt;A reproduzir*&lt;/Str&gt;
            &lt;Str sr=&quot;arg3&quot; ve=&quot;3&quot;/&gt;
            &lt;Str sr=&quot;arg4&quot; ve=&quot;3&quot;/&gt;
            &lt;Str sr=&quot;arg5&quot; ve=&quot;3&quot;/&gt;
            &lt;Str sr=&quot;arg6&quot; ve=&quot;3&quot;/&gt;
            &lt;Int sr=&quot;arg7&quot; val=&quot;0&quot;/&gt;
        &lt;/Event&gt;
    &lt;/Profile&gt;
    &lt;Project sr=&quot;proj0&quot; ve=&quot;2&quot;&gt;
        &lt;cdate&gt;1691601049652&lt;/cdate&gt;
        &lt;name&gt;TaskerScrobblr&lt;/name&gt;
        &lt;pids&gt;212&lt;/pids&gt;
        &lt;scenes&gt;Popup&lt;/scenes&gt;
        &lt;tids&gt;210,211&lt;/tids&gt;
    &lt;/Project&gt;
    &lt;Scene sr=&quot;scenePopup&quot;&gt;
        &lt;cdate&gt;1419546101360&lt;/cdate&gt;
        &lt;edate&gt;1643196942800&lt;/edate&gt;
        &lt;gridSize&gt;15&lt;/gridSize&gt;
        &lt;heightLand&gt;-1&lt;/heightLand&gt;
        &lt;heightPort&gt;370&lt;/heightPort&gt;
        &lt;nme&gt;Popup&lt;/nme&gt;
        &lt;widthLand&gt;-1&lt;/widthLand&gt;
        &lt;widthPort&gt;444&lt;/widthPort&gt;
        &lt;TextElement sr=&quot;elements0&quot; ve=&quot;3&quot;&gt;
            &lt;flags&gt;4&lt;/flags&gt;
            &lt;geom&gt;9,0,435,106,6,0,294,72&lt;/geom&gt;
            &lt;Str sr=&quot;arg0&quot; ve=&quot;3&quot;&gt;Title&lt;/Str&gt;
            &lt;Str sr=&quot;arg1&quot; ve=&quot;3&quot;&gt;Title&lt;/Str&gt;
            &lt;Int sr=&quot;arg2&quot; val=&quot;12&quot;/&gt;
            &lt;Int sr=&quot;arg3&quot; val=&quot;100&quot;/&gt;
            &lt;Str sr=&quot;arg4&quot; ve=&quot;3&quot;&gt;#FF0099CC&lt;/Str&gt;
            &lt;Str sr=&quot;arg5&quot; ve=&quot;3&quot;/&gt;
            &lt;Int sr=&quot;arg6&quot; val=&quot;0&quot;/&gt;
            &lt;Int sr=&quot;arg7&quot; val=&quot;1&quot;/&gt;
            &lt;Int sr=&quot;arg8&quot; val=&quot;1&quot;/&gt;
        &lt;/TextElement&gt;
        &lt;RectElement sr=&quot;elements1&quot;&gt;
            &lt;flags&gt;4&lt;/flags&gt;
            &lt;geom&gt;0,106,444,4,0,106,444,4&lt;/geom&gt;
            &lt;Str sr=&quot;arg0&quot; ve=&quot;3&quot;&gt;Header&lt;/Str&gt;
            &lt;Int sr=&quot;arg1&quot; val=&quot;0&quot;/&gt;
            &lt;Str sr=&quot;arg2&quot; ve=&quot;3&quot;&gt;#77333333&lt;/Str&gt;
            &lt;Str sr=&quot;arg3&quot; ve=&quot;3&quot;/&gt;
            &lt;Int sr=&quot;arg4&quot; val=&quot;0&quot;/&gt;
            &lt;Str sr=&quot;arg5&quot; ve=&quot;3&quot;&gt;#FF000000&lt;/Str&gt;
            &lt;Int sr=&quot;arg6&quot; val=&quot;0&quot;/&gt;
            &lt;Int sr=&quot;arg7&quot; val=&quot;0&quot;/&gt;
        &lt;/RectElement&gt;
        &lt;TextElement sr=&quot;elements2&quot; ve=&quot;3&quot;&gt;
            &lt;clickTask&gt;-936&lt;/clickTask&gt;
            &lt;flags&gt;5&lt;/flags&gt;
            &lt;geom&gt;0,148,444,197,10,116,423,216&lt;/geom&gt;
            &lt;Str sr=&quot;arg0&quot; ve=&quot;3&quot;&gt;Text1&lt;/Str&gt;
            &lt;Str sr=&quot;arg1&quot; ve=&quot;3&quot;&gt;Text&lt;/Str&gt;
            &lt;Int sr=&quot;arg2&quot; val=&quot;10&quot;/&gt;
            &lt;Int sr=&quot;arg3&quot; val=&quot;100&quot;/&gt;
            &lt;Str sr=&quot;arg4&quot; ve=&quot;3&quot;&gt;#FFFFFFFF&lt;/Str&gt;
            &lt;Str sr=&quot;arg5&quot; ve=&quot;3&quot;/&gt;
            &lt;Int sr=&quot;arg6&quot; val=&quot;0&quot;/&gt;
            &lt;Int sr=&quot;arg7&quot; val=&quot;2&quot;/&gt;
            &lt;Int sr=&quot;arg8&quot; val=&quot;1&quot;/&gt;
            &lt;RectElement sr=&quot;background&quot;&gt;
                &lt;flags&gt;4&lt;/flags&gt;
                &lt;geom&gt;-1,-1,-1,-1,-1,-1,-1,-1&lt;/geom&gt;
                &lt;Str sr=&quot;arg0&quot; ve=&quot;3&quot;/&gt;
                &lt;Int sr=&quot;arg1&quot; val=&quot;0&quot;/&gt;
                &lt;Str sr=&quot;arg2&quot; ve=&quot;3&quot;/&gt;
                &lt;Str sr=&quot;arg3&quot; ve=&quot;3&quot;/&gt;
                &lt;Int sr=&quot;arg4&quot; val=&quot;0&quot;/&gt;
                &lt;Str sr=&quot;arg5&quot; ve=&quot;3&quot;&gt;#FF000000&lt;/Str&gt;
                &lt;Int sr=&quot;arg6&quot; val=&quot;0&quot;/&gt;
                &lt;Int sr=&quot;arg7&quot; val=&quot;0&quot;/&gt;
            &lt;/RectElement&gt;
        &lt;/TextElement&gt;
        &lt;PropertiesElement sr=&quot;props&quot;&gt;
            &lt;Int sr=&quot;arg0&quot; val=&quot;1&quot;/&gt;
            &lt;Int sr=&quot;arg1&quot; val=&quot;0&quot;/&gt;
            &lt;Str sr=&quot;arg2&quot; ve=&quot;3&quot;&gt;#FF000000&lt;/Str&gt;
            &lt;Int sr=&quot;arg3&quot; val=&quot;0&quot;/&gt;
            &lt;Str sr=&quot;arg4&quot; ve=&quot;3&quot;&gt;Popup&lt;/Str&gt;
            &lt;Str sr=&quot;arg5&quot; ve=&quot;3&quot;/&gt;
            &lt;Img sr=&quot;arg6&quot; ve=&quot;2&quot;/&gt;
            &lt;Str sr=&quot;arg7&quot; ve=&quot;3&quot;/&gt;
        &lt;/PropertiesElement&gt;
    &lt;/Scene&gt;
    &lt;Task sr=&quot;task210&quot;&gt;
        &lt;cdate&gt;1691528745485&lt;/cdate&gt;
        &lt;edate&gt;1691589896085&lt;/edate&gt;
        &lt;id&gt;210&lt;/id&gt;
        &lt;nme&gt;Scrobble via your server&lt;/nme&gt;
        &lt;pri&gt;100&lt;/pri&gt;
        &lt;Action sr=&quot;act0&quot; ve=&quot;7&quot;&gt;
            &lt;code&gt;37&lt;/code&gt;
            &lt;ConditionList sr=&quot;if&quot;&gt;
                &lt;Condition sr=&quot;c0&quot; ve=&quot;3&quot;&gt;
                    &lt;lhs&gt;%artist&lt;/lhs&gt;
                    &lt;op&gt;13&lt;/op&gt;
                    &lt;rhs&gt;&lt;/rhs&gt;
                &lt;/Condition&gt;
            &lt;/ConditionList&gt;
        &lt;/Action&gt;
        &lt;Action sr=&quot;act1&quot; ve=&quot;7&quot;&gt;
            &lt;code&gt;360&lt;/code&gt;
            &lt;Bundle sr=&quot;arg0&quot;&gt;
                &lt;Vals sr=&quot;val&quot;&gt;
                    &lt;net.dinglisch.android.tasker.RELEVANT_VARIABLES&gt;&lt;StringArray sr=&quot;&quot;&gt;&lt;_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES0&gt;%input
Input
The text that was inserted in the dialog&lt;/_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES0&gt;&lt;/StringArray&gt;&lt;/net.dinglisch.android.tasker.RELEVANT_VARIABLES&gt;
                    &lt;net.dinglisch.android.tasker.RELEVANT_VARIABLES-type&gt;[Ljava.lang.String;&lt;/net.dinglisch.android.tasker.RELEVANT_VARIABLES-type&gt;
                &lt;/Vals&gt;
            &lt;/Bundle&gt;
            &lt;Str sr=&quot;arg1&quot; ve=&quot;3&quot;&gt;artist&lt;/Str&gt;
            &lt;Str sr=&quot;arg2&quot; ve=&quot;3&quot;&gt;Artist name? &lt;/Str&gt;
            &lt;Str sr=&quot;arg3&quot; ve=&quot;3&quot;&gt;%artist&lt;/Str&gt;
            &lt;Int sr=&quot;arg4&quot; val=&quot;20&quot;/&gt;
            &lt;Str sr=&quot;arg5&quot; ve=&quot;3&quot;/&gt;
            &lt;Int sr=&quot;arg6&quot; val=&quot;0&quot;/&gt;
            &lt;Int sr=&quot;arg7&quot; val=&quot;0&quot;/&gt;
            &lt;Str sr=&quot;arg8&quot; ve=&quot;3&quot;/&gt;
            &lt;ConditionList sr=&quot;if&quot;&gt;
                &lt;Condition sr=&quot;c0&quot; ve=&quot;3&quot;&gt;
                    &lt;lhs&gt;%artist&lt;/lhs&gt;
                    &lt;op&gt;13&lt;/op&gt;
                    &lt;rhs&gt;&lt;/rhs&gt;
                &lt;/Condition&gt;
            &lt;/ConditionList&gt;
        &lt;/Action&gt;
        &lt;Action sr=&quot;act10&quot; ve=&quot;7&quot;&gt;
            &lt;code&gt;339&lt;/code&gt;
            &lt;se&gt;false&lt;/se&gt;
            &lt;Bundle sr=&quot;arg0&quot;&gt;
                &lt;Vals sr=&quot;val&quot;&gt;
                    &lt;net.dinglisch.android.tasker.RELEVANT_VARIABLES&gt;&lt;StringArray sr=&quot;&quot;&gt;&lt;_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES0&gt;%http_cookies
Cookies
The cookies the server sent in the response in the Cookie:COOKIE_VALUE format. You can use this directly in the &#039;Headers&#039; field of the HTTP Request action&lt;/_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES0&gt;&lt;_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES1&gt;%http_data
Data
Data that the server responded from the HTTP request.&lt;/_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES1&gt;&lt;_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES2&gt;%http_file_output
File Output
Will always contain the file&#039;s full path even if you specified a directory as the File to save.&lt;/_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES2&gt;&lt;_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES3&gt;%http_response_code
Response Code
The HTTP Code the server responded&lt;/_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES3&gt;&lt;_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES4&gt;%http_headers()
Response Headers
The HTTP Headers the server sent in the response. Each header is in the &#039;key:value&#039; format&lt;/_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES4&gt;&lt;_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES5&gt;%http_response_length
Response Length
The size of the response in bytes&lt;/_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES5&gt;&lt;/StringArray&gt;&lt;/net.dinglisch.android.tasker.RELEVANT_VARIABLES&gt;
                    &lt;net.dinglisch.android.tasker.RELEVANT_VARIABLES-type&gt;[Ljava.lang.String;&lt;/net.dinglisch.android.tasker.RELEVANT_VARIABLES-type&gt;
                &lt;/Vals&gt;
            &lt;/Bundle&gt;
            &lt;Int sr=&quot;arg1&quot; val=&quot;1&quot;/&gt;
            &lt;Int sr=&quot;arg10&quot; val=&quot;0&quot;/&gt;
            &lt;Int sr=&quot;arg11&quot; val=&quot;1&quot;/&gt;
            &lt;Int sr=&quot;arg12&quot; val=&quot;1&quot;/&gt;
            &lt;Str sr=&quot;arg2&quot; ve=&quot;3&quot;&gt;http://yourserver.org/scrobble.php&lt;/Str&gt;
            &lt;Str sr=&quot;arg3&quot; ve=&quot;3&quot;/&gt;
            &lt;Str sr=&quot;arg4&quot; ve=&quot;3&quot;/&gt;
            &lt;Str sr=&quot;arg5&quot; ve=&quot;3&quot;&gt;artist=%artist&amp;track=%track_name&lt;/Str&gt;
            &lt;Str sr=&quot;arg6&quot; ve=&quot;3&quot;/&gt;
            &lt;Str sr=&quot;arg7&quot; ve=&quot;3&quot;/&gt;
            &lt;Int sr=&quot;arg8&quot; val=&quot;30&quot;/&gt;
            &lt;Int sr=&quot;arg9&quot; val=&quot;1&quot;/&gt;
        &lt;/Action&gt;
        &lt;Action sr=&quot;act11&quot; ve=&quot;7&quot;&gt;
            &lt;code&gt;548&lt;/code&gt;
            &lt;Str sr=&quot;arg0&quot; ve=&quot;3&quot;&gt;%http_data&lt;/Str&gt;
            &lt;Int sr=&quot;arg1&quot; val=&quot;0&quot;/&gt;
            &lt;Str sr=&quot;arg10&quot; ve=&quot;3&quot;/&gt;
            &lt;Int sr=&quot;arg11&quot; val=&quot;1&quot;/&gt;
            &lt;Int sr=&quot;arg12&quot; val=&quot;0&quot;/&gt;
            &lt;Str sr=&quot;arg13&quot; ve=&quot;3&quot;/&gt;
            &lt;Int sr=&quot;arg14&quot; val=&quot;0&quot;/&gt;
            &lt;Str sr=&quot;arg15&quot; ve=&quot;3&quot;/&gt;
            &lt;Int sr=&quot;arg2&quot; val=&quot;0&quot;/&gt;
            &lt;Str sr=&quot;arg3&quot; ve=&quot;3&quot;/&gt;
            &lt;Str sr=&quot;arg4&quot; ve=&quot;3&quot;/&gt;
            &lt;Str sr=&quot;arg5&quot; ve=&quot;3&quot;/&gt;
            &lt;Str sr=&quot;arg6&quot; ve=&quot;3&quot;/&gt;
            &lt;Str sr=&quot;arg7&quot; ve=&quot;3&quot;/&gt;
            &lt;Str sr=&quot;arg8&quot; ve=&quot;3&quot;/&gt;
            &lt;Int sr=&quot;arg9&quot; val=&quot;1&quot;/&gt;
        &lt;/Action&gt;
        &lt;Action sr=&quot;act2&quot; ve=&quot;7&quot;&gt;
            &lt;code&gt;547&lt;/code&gt;
            &lt;Str sr=&quot;arg0&quot; ve=&quot;3&quot;&gt;%artist&lt;/Str&gt;
            &lt;Str sr=&quot;arg1&quot; ve=&quot;3&quot;&gt;%input&lt;/Str&gt;
            &lt;Int sr=&quot;arg2&quot; val=&quot;0&quot;/&gt;
            &lt;Int sr=&quot;arg3&quot; val=&quot;0&quot;/&gt;
            &lt;Int sr=&quot;arg4&quot; val=&quot;0&quot;/&gt;
            &lt;Int sr=&quot;arg5&quot; val=&quot;3&quot;/&gt;
            &lt;Int sr=&quot;arg6&quot; val=&quot;1&quot;/&gt;
        &lt;/Action&gt;
        &lt;Action sr=&quot;act3&quot; ve=&quot;7&quot;&gt;
            &lt;code&gt;38&lt;/code&gt;
        &lt;/Action&gt;
        &lt;Action sr=&quot;act4&quot; ve=&quot;7&quot;&gt;
            &lt;code&gt;37&lt;/code&gt;
            &lt;ConditionList sr=&quot;if&quot;&gt;
                &lt;Condition sr=&quot;c0&quot; ve=&quot;3&quot;&gt;
                    &lt;lhs&gt;%track_name&lt;/lhs&gt;
                    &lt;op&gt;13&lt;/op&gt;
                    &lt;rhs&gt;&lt;/rhs&gt;
                &lt;/Condition&gt;
            &lt;/ConditionList&gt;
        &lt;/Action&gt;
        &lt;Action sr=&quot;act5&quot; ve=&quot;7&quot;&gt;
            &lt;code&gt;360&lt;/code&gt;
            &lt;Bundle sr=&quot;arg0&quot;&gt;
                &lt;Vals sr=&quot;val&quot;&gt;
                    &lt;net.dinglisch.android.tasker.RELEVANT_VARIABLES&gt;&lt;StringArray sr=&quot;&quot;&gt;&lt;_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES0&gt;%input
Input
The text that was inserted in the dialog&lt;/_array_net.dinglisch.android.tasker.RELEVANT_VARIABLES0&gt;&lt;/StringArray&gt;&lt;/net.dinglisch.android.tasker.RELEVANT_VARIABLES&gt;
                    &lt;net.dinglisch.android.tasker.RELEVANT_VARIABLES-type&gt;[Ljava.lang.String;&lt;/net.dinglisch.android.tasker.RELEVANT_VARIABLES-type&gt;
                &lt;/Vals&gt;
            &lt;/Bundle&gt;
            &lt;Str sr=&quot;arg1&quot; ve=&quot;3&quot;&gt;track name? &lt;/Str&gt;
            &lt;Str sr=&quot;arg2&quot; ve=&quot;3&quot;/&gt;
            &lt;Str sr=&quot;arg3&quot; ve=&quot;3&quot;&gt;%track_name&lt;/Str&gt;
            &lt;Int sr=&quot;arg4&quot; val=&quot;20&quot;/&gt;
            &lt;Str sr=&quot;arg5&quot; ve=&quot;3&quot;/&gt;
            &lt;Int sr=&quot;arg6&quot; val=&quot;0&quot;/&gt;
            &lt;Int sr=&quot;arg7&quot; val=&quot;0&quot;/&gt;
            &lt;Str sr=&quot;arg8&quot; ve=&quot;3&quot;/&gt;
            &lt;ConditionList sr=&quot;if&quot;&gt;
                &lt;Condition sr=&quot;c0&quot; ve=&quot;3&quot;&gt;
                    &lt;lhs&gt;%track_name&lt;/lhs&gt;
                    &lt;op&gt;13&lt;/op&gt;
                    &lt;rhs&gt;&lt;/rhs&gt;
                &lt;/Condition&gt;
            &lt;/ConditionList&gt;
        &lt;/Action&gt;
        &lt;Action sr=&quot;act6&quot; ve=&quot;7&quot;&gt;
            &lt;code&gt;547&lt;/code&gt;
            &lt;Str sr=&quot;arg0&quot; ve=&quot;3&quot;&gt;%track_name&lt;/Str&gt;
            &lt;Str sr=&quot;arg1&quot; ve=&quot;3&quot;&gt;%input&lt;/Str&gt;
            &lt;Int sr=&quot;arg2&quot; val=&quot;0&quot;/&gt;
            &lt;Int sr=&quot;arg3&quot; val=&quot;0&quot;/&gt;
            &lt;Int sr=&quot;arg4&quot; val=&quot;0&quot;/&gt;
            &lt;Int sr=&quot;arg5&quot; val=&quot;3&quot;/&gt;
            &lt;Int sr=&quot;arg6&quot; val=&quot;1&quot;/&gt;
        &lt;/Action&gt;
        &lt;Action sr=&quot;act7&quot; ve=&quot;7&quot;&gt;
            &lt;code&gt;38&lt;/code&gt;
        &lt;/Action&gt;
        &lt;Action sr=&quot;act8&quot; ve=&quot;7&quot;&gt;
            &lt;code&gt;550&lt;/code&gt;
            &lt;on&gt;false&lt;/on&gt;
            &lt;Str sr=&quot;arg0&quot; ve=&quot;3&quot;/&gt;
            &lt;Str sr=&quot;arg1&quot; ve=&quot;3&quot;&gt;api_key=%lasfm_api_key&amp;artist=%artist&amp;method=track.scrobble&amp;sk=%lasfm_sk&amp;timestamp=%timestamp&amp;track=%track_name&amp;format=json&amp;api_sig=%api_sig&lt;/Str&gt;
            &lt;Str sr=&quot;arg2&quot; ve=&quot;3&quot;/&gt;
            &lt;Str sr=&quot;arg3&quot; ve=&quot;3&quot;&gt;Popup&lt;/Str&gt;
            &lt;Int sr=&quot;arg4&quot; val=&quot;16&quot;/&gt;
            &lt;Int sr=&quot;arg5&quot; val=&quot;1&quot;/&gt;
        &lt;/Action&gt;
        &lt;Action sr=&quot;act9&quot; ve=&quot;7&quot;&gt;
            &lt;code&gt;30&lt;/code&gt;
            &lt;on&gt;false&lt;/on&gt;
            &lt;Int sr=&quot;arg0&quot; val=&quot;0&quot;/&gt;
            &lt;Int sr=&quot;arg1&quot; val=&quot;10&quot;/&gt;
            &lt;Int sr=&quot;arg2&quot;/&gt;
            &lt;Int sr=&quot;arg3&quot; val=&quot;0&quot;/&gt;
            &lt;Int sr=&quot;arg4&quot; val=&quot;0&quot;/&gt;
        &lt;/Action&gt;
    &lt;/Task&gt;
    &lt;Task sr=&quot;task211&quot;&gt;
        &lt;cdate&gt;1691505070601&lt;/cdate&gt;
        &lt;edate&gt;1691592228244&lt;/edate&gt;
        &lt;id&gt;211&lt;/id&gt;
        &lt;nme&gt;Scrobble Shazamed&lt;/nme&gt;
        &lt;pri&gt;6&lt;/pri&gt;
        &lt;Action sr=&quot;act0&quot; ve=&quot;7&quot;&gt;
            &lt;code&gt;547&lt;/code&gt;
            &lt;Str sr=&quot;arg0&quot; ve=&quot;3&quot;&gt;%label&lt;/Str&gt;
            &lt;Str sr=&quot;arg1&quot; ve=&quot;3&quot;&gt;%evtprm3&lt;/Str&gt;
            &lt;Int sr=&quot;arg2&quot; val=&quot;0&quot;/&gt;
            &lt;Int sr=&quot;arg3&quot; val=&quot;0&quot;/&gt;
            &lt;Int sr=&quot;arg4&quot; val=&quot;0&quot;/&gt;
            &lt;Int sr=&quot;arg5&quot; val=&quot;3&quot;/&gt;
            &lt;Int sr=&quot;arg6&quot; val=&quot;1&quot;/&gt;
        &lt;/Action&gt;
        &lt;Action sr=&quot;act1&quot; ve=&quot;7&quot;&gt;
            &lt;code&gt;598&lt;/code&gt;
            &lt;Str sr=&quot;arg0&quot; ve=&quot;3&quot;&gt;%label&lt;/Str&gt;
            &lt;Str sr=&quot;arg1&quot; ve=&quot;3&quot;&gt;A reproduzir&lt;/Str&gt;
            &lt;Int sr=&quot;arg2&quot; val=&quot;0&quot;/&gt;
            &lt;Int sr=&quot;arg3&quot; val=&quot;0&quot;/&gt;
            &lt;Int sr=&quot;arg4&quot; val=&quot;0&quot;/&gt;
            &lt;Str sr=&quot;arg5&quot; ve=&quot;3&quot;/&gt;
            &lt;Int sr=&quot;arg6&quot; val=&quot;1&quot;/&gt;
            &lt;Str sr=&quot;arg7&quot; ve=&quot;3&quot;/&gt;
        &lt;/Action&gt;
        &lt;Action sr=&quot;act10&quot; ve=&quot;7&quot;&gt;
            &lt;code&gt;130&lt;/code&gt;
            &lt;Str sr=&quot;arg0&quot; ve=&quot;3&quot;&gt;Scrobble via yourserver.org&lt;/Str&gt;
            &lt;Int sr=&quot;arg1&quot;&gt;
                &lt;var&gt;%priority&lt;/var&gt;
            &lt;/Int&gt;
            &lt;Int sr=&quot;arg10&quot; val=&quot;1&quot;/&gt;
            &lt;Str sr=&quot;arg2&quot; ve=&quot;3&quot;&gt;%artist&lt;/Str&gt;
            &lt;Str sr=&quot;arg3&quot; ve=&quot;3&quot;&gt;%title&lt;/Str&gt;
            &lt;Str sr=&quot;arg4&quot; ve=&quot;3&quot;/&gt;
            &lt;Int sr=&quot;arg5&quot; val=&quot;0&quot;/&gt;
            &lt;Int sr=&quot;arg6&quot; val=&quot;1&quot;/&gt;
            &lt;Str sr=&quot;arg7&quot; ve=&quot;3&quot;/&gt;
            &lt;Int sr=&quot;arg8&quot; val=&quot;0&quot;/&gt;
            &lt;Int sr=&quot;arg9&quot; val=&quot;0&quot;/&gt;
        &lt;/Action&gt;
        &lt;Action sr=&quot;act11&quot; ve=&quot;7&quot;&gt;
            &lt;code&gt;192&lt;/code&gt;
            &lt;Int sr=&quot;arg0&quot; val=&quot;1&quot;/&gt;
            &lt;Str sr=&quot;arg1&quot; ve=&quot;3&quot;&gt;Merope&lt;/Str&gt;
            &lt;Int sr=&quot;arg2&quot; val=&quot;5&quot;/&gt;
        &lt;/Action&gt;
        &lt;Action sr=&quot;act12&quot; ve=&quot;7&quot;&gt;
            &lt;code&gt;548&lt;/code&gt;
            &lt;Str sr=&quot;arg0&quot; ve=&quot;3&quot;&gt;Shazamed %artist - %track_name&lt;/Str&gt;
            &lt;Int sr=&quot;arg1&quot; val=&quot;0&quot;/&gt;
            &lt;Str sr=&quot;arg10&quot; ve=&quot;3&quot;/&gt;
            &lt;Int sr=&quot;arg11&quot; val=&quot;1&quot;/&gt;
            &lt;Int sr=&quot;arg12&quot; val=&quot;0&quot;/&gt;
            &lt;Str sr=&quot;arg13&quot; ve=&quot;3&quot;/&gt;
            &lt;Int sr=&quot;arg14&quot; val=&quot;0&quot;/&gt;
            &lt;Str sr=&quot;arg15&quot; ve=&quot;3&quot;/&gt;
            &lt;Int sr=&quot;arg2&quot; val=&quot;0&quot;/&gt;
            &lt;Str sr=&quot;arg3&quot; ve=&quot;3&quot;/&gt;
            &lt;Str sr=&quot;arg4&quot; ve=&quot;3&quot;/&gt;
            &lt;Str sr=&quot;arg5&quot; ve=&quot;3&quot;/&gt;
            &lt;Str sr=&quot;arg6&quot; ve=&quot;3&quot;/&gt;
            &lt;Str sr=&quot;arg7&quot; ve=&quot;3&quot;/&gt;
            &lt;Str sr=&quot;arg8&quot; ve=&quot;3&quot;/&gt;
            &lt;Int sr=&quot;arg9&quot; val=&quot;1&quot;/&gt;
        &lt;/Action&gt;
        &lt;Action sr=&quot;act13&quot; ve=&quot;7&quot;&gt;
            &lt;code&gt;547&lt;/code&gt;
            &lt;Str sr=&quot;arg0&quot; ve=&quot;3&quot;&gt;%Last_track&lt;/Str&gt;
            &lt;Str sr=&quot;arg1&quot; ve=&quot;3&quot;&gt;%track_name&lt;/Str&gt;
            &lt;Int sr=&quot;arg2&quot; val=&quot;0&quot;/&gt;
            &lt;Int sr=&quot;arg3&quot; val=&quot;0&quot;/&gt;
            &lt;Int sr=&quot;arg4&quot; val=&quot;0&quot;/&gt;
            &lt;Int sr=&quot;arg5&quot; val=&quot;3&quot;/&gt;
            &lt;Int sr=&quot;arg6&quot; val=&quot;1&quot;/&gt;
        &lt;/Action&gt;
        &lt;Action sr=&quot;act14&quot; ve=&quot;7&quot;&gt;
            &lt;code&gt;38&lt;/code&gt;
        &lt;/Action&gt;
        &lt;Action sr=&quot;act2&quot; ve=&quot;7&quot;&gt;
            &lt;code&gt;590&lt;/code&gt;
            &lt;Str sr=&quot;arg0&quot; ve=&quot;3&quot;&gt;%label&lt;/Str&gt;
            &lt;Str sr=&quot;arg1&quot; ve=&quot;3&quot;&gt;de&lt;/Str&gt;
            &lt;Int sr=&quot;arg2&quot; val=&quot;0&quot;/&gt;
            &lt;Int sr=&quot;arg3&quot; val=&quot;0&quot;/&gt;
        &lt;/Action&gt;
        &lt;Action sr=&quot;act3&quot; ve=&quot;7&quot;&gt;
            &lt;code&gt;547&lt;/code&gt;
            &lt;Str sr=&quot;arg0&quot; ve=&quot;3&quot;&gt;%track_name&lt;/Str&gt;
            &lt;Str sr=&quot;arg1&quot; ve=&quot;3&quot;&gt;%label1&lt;/Str&gt;
            &lt;Int sr=&quot;arg2&quot; val=&quot;0&quot;/&gt;
            &lt;Int sr=&quot;arg3&quot; val=&quot;0&quot;/&gt;
            &lt;Int sr=&quot;arg4&quot; val=&quot;0&quot;/&gt;
            &lt;Int sr=&quot;arg5&quot; val=&quot;3&quot;/&gt;
            &lt;Int sr=&quot;arg6&quot; val=&quot;1&quot;/&gt;
        &lt;/Action&gt;
        &lt;Action sr=&quot;act4&quot; ve=&quot;7&quot;&gt;
            &lt;code&gt;547&lt;/code&gt;
            &lt;Str sr=&quot;arg0&quot; ve=&quot;3&quot;&gt;%artist&lt;/Str&gt;
            &lt;Str sr=&quot;arg1&quot; ve=&quot;3&quot;&gt;%label2&lt;/Str&gt;
            &lt;Int sr=&quot;arg2&quot; val=&quot;0&quot;/&gt;
            &lt;Int sr=&quot;arg3&quot; val=&quot;0&quot;/&gt;
            &lt;Int sr=&quot;arg4&quot; val=&quot;0&quot;/&gt;
            &lt;Int sr=&quot;arg5&quot; val=&quot;3&quot;/&gt;
            &lt;Int sr=&quot;arg6&quot; val=&quot;1&quot;/&gt;
        &lt;/Action&gt;
        &lt;Action sr=&quot;act5&quot; ve=&quot;7&quot;&gt;
            &lt;code&gt;550&lt;/code&gt;
            &lt;on&gt;false&lt;/on&gt;
            &lt;Str sr=&quot;arg0&quot; ve=&quot;3&quot;/&gt;
            &lt;Str sr=&quot;arg1&quot; ve=&quot;3&quot;&gt;%track_name = %Last_track?&lt;/Str&gt;
            &lt;Str sr=&quot;arg2&quot; ve=&quot;3&quot;/&gt;
            &lt;Str sr=&quot;arg3&quot; ve=&quot;3&quot;&gt;Popup&lt;/Str&gt;
            &lt;Int sr=&quot;arg4&quot; val=&quot;5&quot;/&gt;
            &lt;Int sr=&quot;arg5&quot; val=&quot;1&quot;/&gt;
        &lt;/Action&gt;
        &lt;Action sr=&quot;act6&quot; ve=&quot;7&quot;&gt;
            &lt;code&gt;37&lt;/code&gt;
            &lt;on&gt;false&lt;/on&gt;
            &lt;ConditionList sr=&quot;if&quot;&gt;
                &lt;Condition sr=&quot;c0&quot; ve=&quot;3&quot;&gt;
                    &lt;lhs&gt;%track_name&lt;/lhs&gt;
                    &lt;op&gt;3&lt;/op&gt;
                    &lt;rhs&gt;%Last_track&lt;/rhs&gt;
                &lt;/Condition&gt;
            &lt;/ConditionList&gt;
        &lt;/Action&gt;
        &lt;Action sr=&quot;act7&quot; ve=&quot;7&quot;&gt;
            &lt;code&gt;548&lt;/code&gt;
            &lt;on&gt;false&lt;/on&gt;
            &lt;Str sr=&quot;arg0&quot; ve=&quot;3&quot;&gt;Track didn&#039;t change! &lt;/Str&gt;
            &lt;Int sr=&quot;arg1&quot; val=&quot;0&quot;/&gt;
            &lt;Str sr=&quot;arg10&quot; ve=&quot;3&quot;/&gt;
            &lt;Int sr=&quot;arg11&quot; val=&quot;1&quot;/&gt;
            &lt;Int sr=&quot;arg12&quot; val=&quot;0&quot;/&gt;
            &lt;Str sr=&quot;arg13&quot; ve=&quot;3&quot;/&gt;
            &lt;Int sr=&quot;arg14&quot; val=&quot;0&quot;/&gt;
            &lt;Str sr=&quot;arg15&quot; ve=&quot;3&quot;/&gt;
            &lt;Int sr=&quot;arg2&quot; val=&quot;0&quot;/&gt;
            &lt;Str sr=&quot;arg3&quot; ve=&quot;3&quot;/&gt;
            &lt;Str sr=&quot;arg4&quot; ve=&quot;3&quot;/&gt;
            &lt;Str sr=&quot;arg5&quot; ve=&quot;3&quot;/&gt;
            &lt;Str sr=&quot;arg6&quot; ve=&quot;3&quot;/&gt;
            &lt;Str sr=&quot;arg7&quot; ve=&quot;3&quot;/&gt;
            &lt;Str sr=&quot;arg8&quot; ve=&quot;3&quot;/&gt;
            &lt;Int sr=&quot;arg9&quot; val=&quot;1&quot;/&gt;
        &lt;/Action&gt;
        &lt;Action sr=&quot;act8&quot; ve=&quot;7&quot;&gt;
            &lt;code&gt;38&lt;/code&gt;
            &lt;on&gt;false&lt;/on&gt;
        &lt;/Action&gt;
        &lt;Action sr=&quot;act9&quot; ve=&quot;7&quot;&gt;
            &lt;code&gt;37&lt;/code&gt;
            &lt;ConditionList sr=&quot;if&quot;&gt;
                &lt;Condition sr=&quot;c0&quot; ve=&quot;3&quot;&gt;
                    &lt;lhs&gt;%track_name&lt;/lhs&gt;
                    &lt;op&gt;3&lt;/op&gt;
                    &lt;rhs&gt;%Last_track&lt;/rhs&gt;
                &lt;/Condition&gt;
            &lt;/ConditionList&gt;
        &lt;/Action&gt;
    &lt;/Task&gt;
&lt;/TaskerData&gt;
</code></pre>
<p>Save the code as ScrobbleShazam.prj.xml. Copy to your Android Phone and store it in <code>MARKDOWN_HASH72f2ff9cd151668e4455c7cb9fc4230fMARKDOWN<em>HASH</code>. If you tap on the lower bar it must appear an Import project option.
First, on this project I tried to send the scrobble requests directly from Tasker but every time I tried it, the server refused the request with a 403 error (badly signed request). According to the specs, you have to calculate a MD5 checksum using all the arguments of the method. Tasker doesn't have this feature, you have to use external code to implement it, but i used an external javascript library, and calculated the checksum without errors last.fm API server refused it, even after having sucess after implementing it with Python code.  You can also download the [script here](<a href="https://codehouse.digfish.org/wp-content/uploads/2023/08/ScrobleShazam.prj">https://codehouse.digfish.org/wp-content/uploads/2023/08/ScrobleShazam.prj</a></em>.zip) .</p>
<h2>The PHP script</h2>
<p>The PHP script called by the Tasker project uses data from an application [created by you in Last.FM apps](<a href="https://www.last.fm/api/account/create">Create API account | Last.fm</a>). It will generate an <em>API Key</em> and a <em>secret</em> which you'll use in the PHP script. Besides these two, you'all also need a <code>session key</code> (which is actually a access token). To get this, you can use the following python script:</p>
<pre><code class="language-python">import pylast

skg = pylast.SessionKeyGenerator(network)
url = skg.get_web_auth_url()

print(f&quot;Please authorize this script to access your account: {url}\n&quot;)
import time
import webbrowser

webbrowser.open(url)
session_key = skg.get_web_auth_session_key(url)

print(&quot;Your session key is&quot;, session_key)</code></pre>
<p>First install the <code>pylast</code> package with <code>pip install pylast</code> and you grab the session key.</p>
<p>The PHP Code:</p>
<pre><code class="language-php">&lt;?php

define(&#039;LASTFM_API_KEY&#039;, &#039;&#039;);
define(&#039;LASTFM_API_SECRET&#039;, &#039;&#039;);
define(&#039;LASTFM_SK&#039;, &#039;&#039;);

if (!empty($_POST)) {

    $postdata = array(
        &#039;api_key&#039; =&gt; LASTFM_API_KEY,
        &#039;artist&#039; =&gt; trim($_POST[&#039;artist&#039;]),
        &#039;method&#039; =&gt; &#039;track.scrobble&#039;,
        &#039;sk&#039; =&gt; LASTFM_SK,
        &#039;timestamp&#039; =&gt; time(),
        &#039;track&#039; =&gt; trim($_POST[&#039;track&#039;])
    );
    $aux = &#039;&#039;;
    foreach ($postdata as $key =&gt; $value) {
        $aux .= $key . $value;
    }

    $aux .= LASTFM_API_SECRET;
    $api_sig = md5($aux);

    $postdata[&#039;api_sig&#039;] = $api_sig;
    $postdata[&#039;format&#039;] = &#039;json&#039;;

    $ctx = stream_context_create(array(
        &#039;http&#039; =&gt; array(
            &#039;method&#039; =&gt; &#039;POST&#039;,
            &#039;header&#039; =&gt; &#039;Content-Type: application/x-www-form-urlencoded&#039;,
            &#039;timeout&#039; =&gt; 1,
            &#039;content&#039; =&gt; http_build_query($postdata)
        )
    ));

    $result = file_get_contents(&#039;http://ws.audioscrobbler.com/2.0/&#039;, false, $ctx);

    var_dump($result);
}
?&gt;

&lt;form action=&#039;&lt;?php echo $_SERVER[&#039;PHP_SELF&#039;] ?&gt;&#039; method=&#039;POST&#039;&gt;
    &lt;label&gt;
        artist
    &lt;/label&gt;
    &lt;input type=&#039;text&#039; name=&#039;artist&#039;&gt;
    &lt;label&gt;
        track
    &lt;/label&gt;
    &lt;input type=&#039;text&#039; name=&#039;track&#039;&gt;
    &lt;button type=&#039;submit&#039;&gt;Scrobble&lt;/button&gt;
&lt;/form&gt;</code></pre>
<p>The HTML Form below is not necessary but is only needed if you want first to test the script to see if everything is working fine without having to use the Tasker script. Replace the three constants at the start of the script and that's all ! Happy shazaming radio songs!</p>
<p>PS: The Autoshazam feature normally can recognize the same song more than once in a consecutive way, but the tasker script automatically detects this and doesn't scrobble the song if an initial scrobble was already sent.</p>