Mute Spotify Ads Automatically [App]

Discussion in 'Mac Applications and Mac App Store' started by ctferrara, Aug 20, 2012.

  1. ctferrara, Aug 20, 2012
    Last edited: Dec 6, 2012

    macrumors newbie

    Joined:
    Nov 7, 2008
    #1
    Hey guys,

    I was messing around last night with some of the applescript capabilities for Spotify and was able to come up with a nice little solution for automatically detecting and muting ads in the free version of Spotify. I think I was able to write it in the most efficient way where it's not polling Spotify every second, only when it needs to. Let me know what you think.


    Here's the applescript code:
    Code:
    repeat
    	tell application "Spotify"
    		set cur_vol to sound volume
    		set trackk to track number of current track
    		set namme to name of current track
    		set pop to popularity of current track
    		set dur to duration of current track
    		set pos to player position
    	end tell
    	
    	if pop is 0 and dur is less than 31 then
    		tell application "Spotify"
    			pause
    			set sound volume to 0
    			play
    		end tell
    		delay dur - pos + 1
    		tell application "Spotify"
    			set sound volume to cur_vol
    		end tell
    	else
    		if dur - pos is less than 30 then
    			delay dur - pos
    		else
    			delay 30
    		end if
    	end if
    	
    end repeat

    Here's a link to github GitHub
     
  2. macrumors newbie

    Joined:
    Oct 12, 2012
    #2
    Hi! The link seems to be broken. Would you please upload your app again?
     
  3. br3nt, Oct 13, 2012
    Last edited: Oct 13, 2012

    macrumors member

    Joined:
    Jul 1, 2012
    #3
    you can just the code to apple script editor and run it :)
    I don't know how to keep it running in the background though. Make it an app and add it to start up list?


    Did a dry run, caught 2 commercials in a row and then setting the volume to previous level.
    Nice work!
     
  4. macrumors 6502

    Joined:
    Sep 8, 2012
    #4
    No offense but I think spotify should be with ads unless you paid. this is not so bad. I listen to spotify a lot (free version) and i appriciate their free service.

    I think you can find better things to do with scripting.
     
  5. macrumors member

    Joined:
    Jul 1, 2012
    #5
    you know they still get paid for the ads right?
    it's like you walking out of the area when the commercials start and get back when the song is there... you're not removing anything/altering the client
     
  6. Mephistopelus, Oct 14, 2012
    Last edited: Oct 15, 2012

    macrumors newbie

    Joined:
    Oct 12, 2012
    #6
    Thanks so much!
    I've changed it a little bit, and posted to the GitHub. Here.
     
  7. macrumors member

    Joined:
    Jul 1, 2012
    #7
    any changelog except making it an app and raising the duration to 40s? :)
     
  8. macrumors newbie

    Joined:
    Oct 12, 2012
    #8
    I've commented the script, so you can read it all yourself now :)

    In short:
    1. Added error handling
    2. Now it runs every 0.5 seconds instead of 5+ seconds
    3. Deleted the automatic delay in the latest "else". It misses an ad if you skip the song before it.
     
  9. macrumors member

    Joined:
    Jul 1, 2012
    #9
    thanks for the reply!
     
  10. macrumors newbie

    Joined:
    Oct 12, 2012
    #10
    You're very welcome!
     
  11. ctferrara, Dec 5, 2012
    Last edited: Dec 6, 2012

    thread starter macrumors newbie

    Joined:
    Nov 7, 2008
    #11
    Update

    Hey guys,

    Just noticed that this has gotten some attention after uploading it and never giving it a second though. Just a few things;

    1) The link should work again now. I had it saved in my dropbox public folder and had removed it (thinking nobody would ever download it). I have replaced it with an updated version.


    I really do suggest using Mephistopelus's version though. He got it to run invisibly somthing I had not known how to do before. That and making the startup item prompt were great. Link here. Just consider my ideas below. Thanks



    2) Updated Version: Just changes a few things.

    a) If you quit Spotify the app Spotimute will now quit once it realizes Spotify is closed. You don't want it running all the time using resources and clogging your dock. ​

    b) Option to have a growl notification show reminding you if you have the music paused for more than 1.5 minutes. I find this useful when you pause for a second to talk to someone or watch a quick video but forget to resume the music.

    You can change both of these functions if you want by dragging the app into AppleScript Editor and changing the first two lines:

    Code:
    set always_on to true
    set use_growl to true
    ex. set always_on to true if you want to use it as a startup item and have it never quit. ​

    ex2. set always_on to false if you want to use it like I do. I use Keyboard Maestro to automatically open Spotimute when Spotify opens. Then when I quit Spotify, Spotimute quits too. This way it's not always open sucking up resources.​

    ex3. Set use_growl true/false to choose whether or not to display growl notifications when musics been paused for a while. ​

    c) Thanks @Mephistopelus for updating it and commenting but just a few issues..
    1. Changing my name? Comon man...​
    2. Same thing with the icon...​
    3. (This one's real haha) There was no need to change the pause time in the repeat loop to .3 seconds. I wrote it the original very carefully in order to avoid having it run every second..

    By reading the current position in the track we can figure out how long until we test again. Granted, this could pose a problem if we tested at the start of the song and then left it alone. What if we changed the song!! Well I set it up so that if there is more than 30 seconds left in a song it just runs though again.

    In short: If theres more than 30 seconds in the song left it should wait 30 more seconds to test again. If it's less than 30 seconds it waits the remaining time, checks if it's an ad, then reacts to it.

    By doing so we never hear ads and we arn't looping through the AppleScript literally 200 times a minute, but more like 4 times a minute. No need for that. ​


    If you guys have any questions, comments, or requests let me know. I'm going to subscribe to this post now (don't know why I didnt beore) so I'll get them.


    Thanks again for all your support.

    ps. Hilarious story about how I remembered this app. While I use the app everyday I had completely forgotten I posted it here. Well, tonight me and my buddy were watching a movie that involves hackers (Die Hard 4) and he makes a quip about him being a hacker himself, as he recently downloaded a script that mutes Spotify on ads. Low and behold, he had download my app this morning, without even knowing I made it. Small world right..
     
  12. macrumors regular

    Joined:
    Apr 2, 2009
    #12
    Just to clarify... is the Mephistopelus version the one that is now a native OS X app "Spotifree", or is this something different?

    Did this start out as an AppleScript and was changed into an app?

    Also, I'm confused because you mention a "Spotimute", what is that?
     
  13. thread starter macrumors newbie

    Joined:
    Nov 7, 2008
    #13
    I only mention Spotimute because that is what I originally named it when I posted the app. Because the link to the app went dead but the code posted stayed on this page Mephistopelus was able to repackage it into an app. He never was able to download the original app so he never knew the original name, thus making up his own.


    To the best of my knowledge the timeline is as follows:

    1. I created the inital applescript and shared it here
    2. I forgot that I posted it and never replied to any comments for a while
    3. Mephistopelus copied my code, changed a few variables and packaged it up and called it Spotifree
    4. Mephistopelus improved upon code and code website, eventually turning it its own native app.
     

Share This Page