skateguy

online_radio_ad_blocker.lua

Sep 27th, 2014
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.42 KB | None | 0 0
  1. function descriptor()
  2.    return {
  3.       title = "Online Radio AD blocker",
  4.       author = "[email protected]",
  5.       version = 0.2,
  6.       shortdesc = 'AdBlock',
  7.       url = '',
  8.       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",
  9.       capabilities = {"input-listener"}
  10.    }
  11. end
  12.  
  13. function meta_changed()
  14.    vlc.msg.info("... meta_changed ...")
  15.    t = get_now_playing()
  16.    vlc.msg.info("Now playing:")
  17.    vlc.msg.info(t)
  18.    prev = block
  19.    block =  string.find(t,"Digitally Imported.*TAG")
  20.    if block then
  21.       vlc.msg.info("Found AD, set volume level to 0")
  22.       if not prev then
  23.           volume_level = vlc.volume.get()
  24.       end
  25.       vlc.volume.set(0)
  26.    else
  27.       if prev then
  28.           vlc.volume.set(volume_level)
  29.       end
  30.    end
  31. end
  32.  
  33. function activate()
  34.     volume_level = vlc.volume.get()
  35. end
  36.  
  37. function deactivate()
  38. end
  39.  
  40. function get_now_playing(str)
  41.     local item = vlc.item or vlc.input.item()
  42.     if not item then
  43.         return ""
  44.     end
  45.     local metas = item:metas()
  46.     if metas["now_playing"] then
  47.         return metas["now_playing"]
  48.     else
  49.         return ""
  50.     end
  51. end
Advertisement
Add Comment
Please, Sign In to add comment