Online Radio AD Blocker

VLC Extensions

Source i (link to git-repo or to original if based on someone elses unmodified work):

Add the source-code for this project on opencode.net

4
Become a Fan
6.5

Description:
It always annoying when a commercial unexpectedly interrupts your relaxation and tries to sell you irrelevant products and services again and again every day. Hey, what happened? I want to listen my online radio without ads! With this extension (after configuration) the volume level is automatically set to 0 when an AD is recognized.

CONFIGURATION:
You have to configure which content is recognized as ad. My favorite radio station always sets the title of the ads as "ad|main http://adurl" or "Adcor - ad description" so the configuration in this case is easy! Everything which starts with "ad" is classified as blocked content. Maybe you have to change this simple pattern depending on your broadcasted content.

I hope you are familiar with regular expressions because the title pattern is a LUA regular expression. You can change the filter in the downloaded file at line 18. (Short LUA tutorial http://lua-users.org/wiki/PatternsTutorial)

INSTALLATION:
- click on the download button below
- save the file and extract "online_radio_adblocker.lua"
- create a directory "extensions" at this location and put the file "online_radio_adblocker.lua" inside:
* Windows (all users): %ProgramFiles%VideoLANVLCluaextensions
* Windows (current user): %APPDATA%vlcluaextensions
* Linux (all users): /usr/lib/vlc/lua/extensions/
* Linux (current user): ~/.local/share/vlc/lua/extensions/
* Mac OS X (all users): /Applications/VLC.app/Contents/MacOS/share/lua/extensions/
* Mac OS X (current user): /Users/%your_name%/Library/Application Support/org.videolan.vlc/lua/extensions/

To start the extension click on View > Online radio AD blocker.

Any comments, idea would be highly appreciated.

You can find the project on github as well : https://github.com/joemeszaros/vlc-ad-blocker.
Last changelog:

version 0.2:
-fix : if two ads are played consecutively, then volume_level is set to 0


Ratings & Comments

16 Comments

OneBadV8

I rewrote the original script to instead stop and then start playing the stream which I found causes the ad to be skipped entirely. I only tested this with DI.fm, but I would imagine this works with others. Please reach out with any questions. function descriptor()

   return {
      title = "Online Radio AD blocker",
      author = "joe.meszaros@gmail.com",
     version = 0.3,
      shortdesc = 'AdBlock',
     url = '',
      description = "It always annoying when a commercial unexpectedly interrupts your relaxation and tries to sell you irrelevant products and services again and again every day. Hey, what happened? I want to listen my online radio without ads! With this extension (after configuration) the volume level is automatically set to 0 when an AD is recognized",
      capabilities = {"input-listener"}
   }
end
function meta_changed()
   vlc.msg.info("... meta_changed ...")
   t = get_now_playing()
   vlc.msg.info("Now playing:")
   vlc.msg.info(t)
   prev = block
   block = string.find(t,"Digitally Imported.*TAG") or string.find(t, 'More of the show after these messages') or string.find(t, 'Get Digitally Imported Premium') or string.find(t, 'webex') or string.find(t, 'di.fm/premium') or string.find(t, "There's more to Digitally Imported!") or string.find(t, 'PhotonVPS.com') or string.find(t, 'DI.fm')
   if block then
      vlc.msg.info("Found AD, stop")
      vlc.playlist.stop()
	  vlc.msg.info("Go to first track in playlist")
	  vlc.playlist.goto(1)
	  vlc.msg.info("Replay stream to skip ad")
	  vlc.playlist.play()
   end
end
function activate() end function deactivate() end function get_now_playing(str)
    local item = vlc.item or vlc.input.item()
    if not item then
        return ""
    end
    local metas = item:metas()
    if metas["now_playing"] then
        return metas["now_playing"]
    else
        return ""
    end
end

legendinis

Hello dear Joe Meszaros, Thank you for great addon! It is very handy! I redesigned slightly the code of the addon:

  • It is currently not just "ad blocker" but more like "Ad Silencer"
  • It can be used not only to block (silence) ads but also to boost volume for news or some radio broadcast
  • It is easier configurable now: every user can add unlimited count of keywords ("adstring")
  • You can select preferred volume factor for each keyword ("ad_volumefactor" for particular "adstring") - just edit "set_settings()" function.
  • You can add the feature to the next version if you think it is worth. Cannot insert files, so the code is:
    function descriptor()
       return {
          title = "Online Radio AD blocker/silencer - eXtended",
          author = "joe.meszaros@gmail.com, me@serenissima.lt",
          version = 1.0,
          shortdesc = 'AdBlock eXtended',
          url = '',
          description = "It always annoying when a commercial unexpectedly interrupts your relaxation and tries to sell you irrelevant products and services again and again every day. Hey, what happened? I want to listen my online radio without ads! With this extension (after configuration) the volume level is automatically reduced to a desirable level when an AD is recognized",
          capabilities = {"input-listener"}
       }
    end
    
    function set_settings()
       ad_array = {}
       ad_volumefactor = {}
    
       smoth_vol_change = true
       vol_change_step = 1
     
       adstring = 1
       ad_array[adstring] = "AD"
       ad_volumefactor[adstring] = 1/3
       
       adstring = 2
       ad_array[adstring] = "SALE"
       ad_volumefactor[adstring] = 0.5
       
       adstring = 3
       ad_array[adstring] = "NEWS"
       ad_volumefactor[adstring] = 1.2
    end
    
    function meta_changed()
       now_playing = get_now_playing()
       vlc.msg.info('Now playing: '..now_playing)
    
       curr_volume = vlc.volume.get()
       if not ad_found then
          normal_volume = vlc.volume.get()	
       end  
     
       for vol_key,ad_value in pairs(ad_array) do
          if string.find(now_playing, ad_value) then
    		required_volume = round(normal_volume * ad_volumefactor[vol_key], 0)
    		ad_found = true
    		break
    	  end
    	  required_volume = normal_volume
    	  ad_found = false
       end
       
       if (curr_volume ~= required_volume) then
          if smoth_vol_change then	    
    	     if curr_volume > required_volume then
    		    step = -vol_change_step
    		 else
    			step = vol_change_step
    		 end
    		 for setvol = curr_volume, required_volume, step do
    		    vlc.volume.set(setvol)
    	     end	
    	  else
    	     vlc.volume.set(required_volume)
    	  end
       end 
    end
    
    function activate()
    	ad_found = false
        normal_volume = vlc.volume.get()
    	set_settings()
    end
    
    function deactivate()
    end
    
    function get_now_playing(str)
        local item = vlc.item or vlc.input.item()
        if not item then
            return ""
        end
        local metas = item:metas()
        if metas["now_playing"] then
            return metas["now_playing"]
        else
            return ""
        end
    end
    
    function round(num, idp)
      local mult = 10^(idp or 0)
      return math.floor(num * mult + 0.5) / mult
    end
    
    Usage:
  • Modify "set_settings()" function to meet your requirements: If you need more ad-strings - just copy all 3 lines beginning with "adstring = n" (where n=1,2,3,...) and assign n successive bigger number; Assign preferred "ad_volumefactor" for the configured "adstring": 1/2 (or 0.5) means the half as loud as normal (e.g. 50%); 1.2 means 20% louder than normal and so on.
  • "smoth_vol_change" means if you need smooth volume change; but this works only with certain output plugins because of the output buffer size... P.S.: maybe someone know some sort of "wait()" or "sleep()" function in Lua? I'm new to Lua and didn't find anything similar.
  • P.P.S.: sorry for so big comment.. :]

    legendinis

    Sorry, because mixed "Tab" and "Space" indents in the code - source becomes completely non-understandable. Try to solve that:

    function descriptor()
    	return {
    		title = "Online Radio AD blocker/silencer - eXtended",
    		author = "joe.meszaros@gmail.com, me@serenissima.lt",
    		version = 1.0,
    		shortdesc = 'AdBlock eXtended',
    		url = '',
    		description = "It always annoying when a commercial unexpectedly interrupts your relaxation and tries to sell you irrelevant products and services again and again every day. Hey, what happened? I want to listen my online radio without ads! With this extension (after configuration) the volume level is automatically reduced to a desirable level when an AD is recognized",
    		capabilities = {"input-listener"}
    	}
    end
    
    function set_settings()
    	ad_array = {}
    	ad_volumefactor = {}
    
    	smoth_vol_change = true
    	vol_change_step = 1
     
    	adstring = 1
    	ad_array[adstring] = "AD"
    	ad_volumefactor[adstring] = 1/3
    	
    	adstring = 2
    	ad_array[adstring] = "SALE"
    	ad_volumefactor[adstring] = 0.5
    	
    	adstring = 3
    	ad_array[adstring] = "NEWS"
    	ad_volumefactor[adstring] = 1.2
    end
    
    function meta_changed()
    	now_playing = get_now_playing()
    	vlc.msg.info('Now playing: '..now_playing)
    
    	curr_volume = vlc.volume.get()
    	if not ad_found then
    		normal_volume = vlc.volume.get()	
    	end
     
    	for vol_key,ad_value in pairs(ad_array) do
    		if string.find(now_playing, ad_value) then
    			required_volume = round(normal_volume * ad_volumefactor[vol_key], 0)
    			ad_found = true
    			break
    		end
    		required_volume = normal_volume
    		ad_found = false
    	end
    	
    	if (curr_volume ~= required_volume) then
    		if smoth_vol_change then		 
    			if curr_volume > required_volume then
    				step = -vol_change_step
    			else
    				step = vol_change_step
    			end
    			for setvol = curr_volume, required_volume, step do
    				vlc.volume.set(setvol)
    			end	
    		else
    			vlc.volume.set(required_volume)
    		end
    	end 
    end
    
    function activate()
    	ad_found = false
    	normal_volume = vlc.volume.get()
    	set_settings()
    end
    
    function deactivate()
    end
    
    function get_now_playing(str)
    	local item = vlc.item or vlc.input.item()
    	if not item then
    		return ""
    	end
    	local metas = item:metas()
    	if metas["now_playing"] then
    		return metas["now_playing"]
    	else
    		return ""
    	end
    end
    
    function round(num, idp)
    	local mult = 10^(idp or 0)
    	return math.floor(num * mult + 0.5) / mult
    end
    

    Breity

    I wasn't even able to download, when I pressed the download-Button a text page appeared which seems to be the sourcecode of the site

    joemeszaros

    It is the source code of the extension not the site. Please click on 'File/Save as' in the menu when you see the this source code. Thus you can download the file and save it to the right place. If you have further problems feel free to ask again :-)

    Breity

    Thank you I managed it meanwhile, which was in Ubuntu a bit more difficult : I had to make a new file and copy and paste the source there ... But I didnt manage to tell the addon to block ADs ( its checked in the view tab )

    joemeszaros

    You have to configure the extension to block your radio station's ads. This configuration varies from station to station. Please be vigilant and catch the title of the ads and post it to me and I will help you to configure the extension.

    Breity

    Here are some of the ADs: Choose premium for the best audio experience - Soulful House - DIGITALLY IMPORTED - house music selected from Paris with love! There's more to Digitally Imported! - Soulful House - DIGITALLY IMPORTED - house music selected from Paris with love! Digitally Imported TSTAG_60 ADWTAG - Soulful House - DIGITALLY IMPORTED - house music selected from Paris with love!

    arnongold

    was not listed in menu View ubuntu 13.10 vlc new 2.0.6 cannt post output of vlc -vvv it's too long

    joemeszaros

    Where did you save the file? If it's a mysterious phenomenon I will install a fresh Ubuntu 13.10 VM.

    arnongold

    if U send me an E-Mail I'll send U the output of vlc -vvv

    honkerdown

    Just a comment to confirm that this extension does appear to be working fine with VLC 2.1 on Windows 7.

    zipzipsaib

    if two ads are played consecutively, then volume_level is set to 0. To fix this, you can add an "if" like this: if block then vlc.msg.info("Found AD, set volume level to 0") if not prev then volume_level = vlc.volume.get() end vlc.volume.set(0) I also have an updated block for di.fm: block = string.find(t,"Choose premium.*") or string.find(t,"DI - Energizing") or string.find(t,"Digitally Imported.*TAG") or string.find(t, 'More of the show after these messages') or string.find(t, 'Get Digitally Imported Premium') or string.find(t, 'webex') or string.find(t, 'di.fm/premium') or string.find(t, "There's more to Digitally Imported!") or string.find(t, 'PhotonVPS.com') have fun!

    joemeszaros

    zipzipsaib, thanks for the comments and the bug report. Now everybody can download the updated file with the bug fix.

    honkerdown

    Thanks for the update. I just made the recommended change late yesterday and was testing it this morning. Seems to work well for me.

    zipzipsaib

    nice addon, but wasn't easy to make it work for a beginner. * when I saved the file, some xml markup was added by my browser, so you want to check the content of the file and make sure nothing is appended. * to get the %APPDATA% folder, you can press start, type cmd, type: echo %APPDATA% * vlc 2.0.8 complained about missing descriptor() function, I added to the beginning of the script: function descriptor() return { title = "AdBlock", version = "0.1", author = "joemeszaros", url = 'hello', shortdesc = "AdBlock"; } end * for di.fm, I used a block like this one: block = string.find(t,"Digitally Imported.*TAG") or string.find(t, 'More of the show after these messages') or string.find(t, 'Get Digitally Imported Premium') or string.find(t, 'webex') or string.find(t, 'di.fm/premium') or string.find(t, "There's more to Digitally Imported!") or string.find(t, 'PhotonVPS.com') the list was taken from here http://code.google.com/p/quodlibet/source/browse/plugins/events/radioadmute.py?spec=svn0d807ac2a1f919f1e008e0639b1d0ea530504a98&r=0d807ac2a1f919f1e008e0639b1d0ea530504a98

    Pling
    0 Affiliates
    Details
    license
    version
    updated
    added
    downloads 24h 0
    mediaviews 24h 0
    pageviews 24h 2

    Other VLC Extensions:

    Multiple VLC enhancments
    tubh
    last update date: 12 years ago

    Score 4.9

    TUNE IN RADIO
    willyboy63
    last update date: 12 years ago

    Score 5.0

    Etevaldo Scopel
    etevaldo
    last update date: 12 years ago

    Score 4.7

    VLsub 0.9
    nonkelleo
    last update date: 12 years ago

    Score 4.1

    IP Webcam
    manonlatramee62
    last update date: 12 years ago

    Score 5.1

    TandN Co LLC
    tandnone23
    last update date: 10 years ago

    Score 5.7



    System Tags