Image 01
profile-image

legendinis

Jaroslav K.
Online Radio AD Blocker

VLC Extensions 16 comments

Score 56%
56 Likes
44 Dislikes
Aug 13 2015
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
- Dec 28 2013
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.. :] - Dec 28 2013
    Online Radio AD Blocker

    VLC Extensions

    Score 56%
    56 Likes
    44 Dislikes
    Dec 28 2013