theDisliker - Spotify Song Ignoring

Veröffentliche deine funktionierenden Skripte und Funktionen

Moderator: jNizM

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

theDisliker - Spotify Song Ignoring

Post by BoBo » 18 Feb 2022, 06:53

tl:dr - script will skip a blacklisted song if detected within an active (even minimized) Windows Spotify Webplayer session.
Disclaimer

Nachfolgendes Script wurde basierend auf einer Anfrage :arrow: hier gefrickelt.

Die Situation: Spotify ermöglicht das 'disliken' von Songs, allerdings nur unter Android/iOS (und/oder weiteren mir unbekannten Voraussetzungen).
Diese Funktion fehlt jedoch für den Spotify WebPlayer im (Chrome/Edge) Browser.

Verwendet wurde …
Google Chrome Browser (v98). Info dazu in 'Chrome > Hilfe > Über Google Chrome'
Optionale Chrome Extension: Spotify Web Player Hotkeys - Alexandre Macabies.
Anmerkung: Das script läuft auch ohne diese Browser Extension, und dient lediglich dazu das Vor-/Zurückspringen von Songs per Tastendruck an das (geschlossene) Browserfenster zu ermöglichen (bei mir zu Testzwecken). Wer ein Gerät mit 'Mediakeys' hat kann es auch damit probieren.

a) für die 'Testumgebung' wurde ein Album von Snoop Dog gewählt (mit ausreichend 'explicit content' :mrgreen: ) Frau Fischer war beim Testen schlicht unaushaltbar :silent:
b) das Script ermittelt bei 'laufendem Betrieb' den Songtitel (benötigt im Tab den Aktivitätsnachweis "Audiowiedergabe" als Unterscheidungsmerkmal).
c) zum Test wurde der dritte Song im Album disliked ("Drop It Like It's Hot · Snoop Dogg, Pharrell Williams – Audiowiedergabe")
d) mittels der Chrome-Extension wird beim Erfassen eines 'Übeltäters' die Tastenkombination STRG+Rechts ("^{Right"}) AKA "Nächster Song" an den Browser gesendet.
Anmerkung: soll dies auch bei minimiertem Browser funktionieren, ist die Tastenkombination in der Extension auf 'Global' zu setzen.
e) zum Testen einfach mal versuchen den dritten Song im Player mittels Click abzuspielen - es wird zum nächsten Song geskipped.

So here we go... https://open.spotify.com/artist/7hJcb9fa4alzcOq3EaNPoG :thumbup:

Wunschliste:
1) das jemand die Chrome Extension überflüssig macht (dürfte sich um JavaScript handeln?)
2) Anbindung an eine 'blacklist' ("mySpotify.txt"). Die Validierung gegen diese steht (noch) aus.
3) das jemand das vom Browser im TAB gesetzte Englische Äquivalent für "Audiowiedergabe" ermitteln kann (sonst laufen hier einige Amok) :silent:
4) es lassen sich noch einige Infos im Browser abgreifen (z.B. der Pfad des aktuell gespielten Songs), ich weiss nur nicht wirklich wie dies bei Child-Dingens zu machen wäre??

Code: Select all

; 'https://open.spotify.com'
; 'https://open.spotify.com/artist/7hJcb9fa4alzcOq3EaNPoG' - Snoop Dog
; 'https://chrome.google.com/webstore/detail/spotify-web-player-hotkey/pdcbjjmgfakcbbchppeemlfpfgkdmjji' - Spotify Web Player Hotkeys by Alexandre Macabies

#SingleInstance, Force                                                                                                                                                        
#Include Acc.Ahk																	; https://github.com/Drugoy/Autohotkey-scripts-.ahk/blob/master/Libraries/Acc.ahk                         
SetBatchLines, -1
SetWorkingDir, A_ScriptDir


SetTimer, dropThatShit, 500															; check every 500ms..                                                                                                                                                                                                              
Return


dropThatShit:
file := !InStr(getChromeUrl(),"open.spotify.com")									; extract spotify media ID from URL to create specific '<blacklist ID>.txt'                                                                                                                                                               
?	""																				; bc no spotify URL/instance has been identified no blacklist file/ID                                                                                                                                                              
:	StrSplit(getChromeUrl(),"/").3 . ".txt"											; creating '<blacklist ID>.txt'
ToolTip % validate(getChromeTab("Audiowiedergabe"),file)=1							; validation against '<blacklist ID>.txt'
?	spotifyKey("^{Right}")															; therefore, let's skip that sh...
: 	"" ; Still cruisin'..."															; Calm down Buddy & let's listen!
Return                                                                                                                                                                                                                                                                                                                 

                                                                                                                                                                                                                                                               
getChromeUrl() {                                                                                                                                                                                                                                                                                                       
	local                                                                                                                                                                                                                                                                                                              
	hWnd := WinExist("ahk_class Chrome_WidgetWin_1")                                                                                                                                                                                                                                                                   
	oAcc := Acc_Get("Object", "4.1.1.2.1.2.5.3", 0, "ahk_id " hWnd)                                                                                                                                                                                                                                                    
	if !IsObject(oAcc) || !(oAcc.accName(0) = "Address and search bar")                                                                                                                                                                                                                                                
		oAcc := Acc_Get("Object", "4.1.1.2.1.2.5.3", 0, "ahk_id " hWnd)				; '4.1.1.2.1.2.5.3' (Chrome v98 address bar path). Use ACCViewer.ahk to update accordingly.                                                                                                                                                                                                                                           
	vUrl := oAcc.accValue(0)                                                                                                                                                                                                                                                                                           
	oAcc := ""																																																																											
	return vUrl                                                                                                                                                                                                                                                                                                        
	}


getChromeTab(playIndicator:="") {                                                                                                                                                                                                                                                                                       
	WinExist("ahk_class Chrome_WidgetWin_1")										; 'https://www.autohotkey.com/boards/viewtopic.php?p=436429#p436429'
	For each, oChild in Acc_Children(Acc_Get("Object", TABS := "4.1.1.2.1.1.1"))	; '4.1.1.2.1.1.1' (Chrome v98 TAB bar path). Use ACCViewer.ahk to update accordingly.
		vRes .= InStr(oChild.accName(0), playIndicator)								; 'playIndicator' = string the browser will add (ie "Audiowiedergabe") to a TAB indicating a playing media file.                                                                                                                                          
	?	oChild.accName(0) . "`r`n"													; press Alt+c to identify your language specific string that is trailing the character.
	:	Return
	Return Trim(vRes,"`r`n")                                                                                                                                                                                                                                                                                             
	}

                                                                                                                                                                                                                                                                                                                       
validate(currSong,file,sep:="`r`n") {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
	if !FileExist(file)																; if a blacklist doesn't exist...                                                                                                                                                                                                       
		Return	0																	; ...there are no blacklisted songs: 0/false                                                                                                                                                                                      
	FileRead, content,% file														; otherwise parse '<blacklist ID>.txt'
	array := StrSplit(Trim(content,sep),sep)										; remove trailing `n from blacklist content, otherwise a detected 'empty tab' will be considered a match
	Loop % array.Count() {
		} Until i:=(currSong=Trim(array[A_Index],"`r`n")) ? 1 : 0					; matching song 1/true 0/false
	Return i                                                                                                                                                                                                                                                                                                      
	}                                                                                                                                                                                                                                                                                                                  

                                                                                                                                                                                                                                                                                                                       
spotifyKey(key) {																	; ternary operator can't handle legacy commands, so 'outsourced' it into a function.                                                                                                                                                 
	Send % key                                                                                                                                                                                                                                                                                                         
	}                                                                                                                                                                                                                                                                                                                  

                                                                                                                                                                                                                                                                                                                       
!g::	clipboard := getChromeTab()													; get all TAB strings to the clipboard.                                                                                                                                            
!b::
		if (getChromeTab("Audiowiedergabe") = "")
			Return
		FileAppend,% getChromeTab("Audiowiedergabe") "`n",% file					; adding the playing song to '<blacklist ID>.txt'
		Return                                                                                                                                                                                       
!r::	Run % file																	; review '<blacklist ID>.txt'                                                                                                                                               
!c::	clipboard := getChromeTab("Audiowiedergabe")								; showing currently playing songs' title (and keep it at the clipboard)                                                                                                                                                                                  
~Left::	spotifyKey("^{Left}")														; moving left to select the previous track (for testing)                                                                                                                                                                           
~Right::spotifyKey("^{Right}")														; moving right to select the next track (for testing)
Chrome/Edge
Have phun.

8-)

Tags: spotify | playlist | hide | dislike | web player | windows | skip | song

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: theDisliker - Spotify Song Ignorer

Post by BoBo » 18 Feb 2022, 08:04

Die (noch) fehlende Anbindung der Validierung von laufenden Songs gegen die bereits als "pöse Pupen"-Gelisteten ergibt sich aus der Frage der zu erwartenden Performanceeinbuße.

Während sich der test-dummy-song quasi in Echtzeit gegen seinen Gegner vergleichen läßt, dürfte dies mit einer wachsenden Liste weniger performant zur Sache gehen.
Hier wäre ich für Vorschläge/Hinweise auf (auch bereits existierende) optimierte Lösungen dankbar.
Würde ungern das Rad mehrmals verbuxeln. Irgendwie tendiere ich zu FileOpen()/incremental search/ ... nur warum? :think:

BoBo (der hiermit ganz Ohrige!) :)

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: theDisliker - Spotify Song Ignoring

Post by BoBo » 18 Feb 2022, 16:45

Folks,
inzwischen hat die auf einer '<blacklist ID>.txt' basierende Validierung Einzug gehalten.

Drücken von Alt+b'anned' fügt den Titel des aktuell gespielten Songs der Blacklist hinzu, dabei wird dieser durch die Validierung sofort erkannt, und es wird zum darauf folgenden Song geskipped. Das parsen der blacklist hat mit der zum Test genutzten Menge (ca 50 "schwarze Schafe") noch zu keiner merklichen Performanceeinbuße geführt.

Drücken von Alt+c'urrent' zeigt den Titel des aktuell gespielten Song an.

Drücken von Alt+g'et' zeigt die Titel aller derzeit im Browser aufgereihten TABs an. Damit lässt sich der vom Browser zur Laufzeit dem Titel zugefügte 'Player-Indikator' ("Audiowiedergabe") ermitteln.

Drücken von Alt+r'eview' öffnet die '<blacklist ID>.txt' zum Review.

Drücken der Richtungstaste-Links springt zurück zum vorherigen Song.
Drücken der Richtungstaste-Rechts springt zum nächsten Song.

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: theDisliker - Spotify Song Ignoring

Post by BoBo » 20 Feb 2022, 13:05

Ein Update/BugFix :thumbup:
Zur Laufzeit führte das Pausieren ("Leertaste") eines Songs dazu, das beim 'Restart' mehrere skips/Sprünge stattfanden (Fehlfunktion bei der Validierung zwischen TAB und '<blacklist ID>.txt').
Das script wurde entsprechend angepasst und läuft derzeit stabil. :shh:

BTW, nachdem eine Playlist durchgelaufen ist (wonach ich jeweils die '<blacklist ID>.txt' benenne), läuft Spotify in die nächste hinein - womit sich dann allerdings Songs blacklisten lassen, welche mit der ursprünglichen 'Ausgangsplaylist' nichts zu tun haben, was dann eine spezifische '<blacklist ID>.txt' obsolet macht, jedoch eine übergreifende/allgemeine Playliste nur unnötig aufblähen würde. Ideas? :think:

parth1
Posts: 21
Joined: 28 Aug 2021, 11:55

Re: theDisliker - Spotify Song Ignoring

Post by parth1 » 28 Feb 2022, 07:26

i want to use it with edge , should i just replace chrome with edge and what is this ( https://github.com/Drugoy/Autohotkey-scripts-.ahk/blob/master/Libraries/Acc.ahk )

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: theDisliker - Spotify Song Ignoring

Post by BoBo » 28 Feb 2022, 15:15

parth1 wrote:
28 Feb 2022, 07:26
i want to use it with edge , should i just replace chrome with edge
Sort of. Minimum, you've to configure the AccPath-settings within the script using ...

(valid for 'Edge - Version 98.0.1108.62 (Official Build) (64-Bit)')
TABs :arrow: 4.1.1.4.1.1.2
Addressbar :arrow: 4.1.1.4.1.2.5.4
That's an AHK-library that you've to download and declare within your script using the :arrow: #Include-directive (if not done already).
Good luck.

parth1
Posts: 21
Joined: 28 Aug 2021, 11:55

Re: theDisliker - Spotify Song Ignoring

Post by parth1 » 01 Mar 2022, 04:24

i got this error ( #include file "Acc.Ahk" cannot be opend )
where i have to put acc.ahk

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: theDisliker - Spotify Song Ignoring

Post by BoBo » 01 Mar 2022, 04:28

Dropping it next to your script and #Include Acc.ahk should be fine. And yes, read AHK's Help about :arrow: #Include to get things done.

Post Reply

Return to “Skripte und Funktionen”