You are not logged in.

#1 2014-07-04 00:48:41

Tarqi
Member
From: Ixtlan
Registered: 2012-11-27
Posts: 179
Website

VLC Lua Plugin for Digital Imported Radio Stations (deprecated)

Due to several reasons I currently need to play music using my client instead of mpd on my server. While I often listen to Digital Imported, I do not own an account there (and don't want one, escpecially not for each site), so I am stuck with their flashplayer, which let my old notebook make some noise by the fan.

First I created a parser in python, which sucks the needed information from their site(s), but then I stumbled across a(n) (old and partially broken) json-interface to their services. Since I already had VLC installed and was curious about doing something with Lua, I created a simple script for my purpose.

Disclaimer (mainly for the mods)
This is completly legal. All the script does is to grab the stream from the streamurl, using their on api/interface, which leads to bypass some dumb javascript checks, which try to force you to create an account for using an external player. You will also get their advertisements - same as using the flashplayer, so no illegal stuff in here.

Sites included

  • dI.fm

  • jazzradio.com

  • rockradio.com

  • sky.fm

Issues

  • Due to multihtreading in VLC, the lists must be sorted manually by clicking on the appropriate columnheader

  • Since the URLs point to .pls files, selecting an entry will open a new node instead to play the stream, so one needs to select twice

  • Because their interface is partially broken, some stations will only be reachable in .mp3 instead of .aac

  • The VLC service used to fetch json data (vlc.stream) will not follow HTTP headers, so the lists will be sometimes empty (sites return 206 instead of 200).

Installation

  1. Create ~/.local/share/vlc/lua/sd and ~/.local/share/vlc/lua/sd/modules directories

  2. Put the code below into the file ~/.local/share/vlc/lua/sd/di_vlc.lua

  3. Link /usr/lib/vlc/lua/intf/modules/common.luac to ~/.local/share/vlc/lua/sd/modules/common.luac

Code

--
-- di_vlc.lua - VLC Service Discovery Plugin
-- Adds Digital Imported based Radiostations to the VLC Playlist Window
--
-- App (*nix): /usr/lib/vlc/
--      (win): C:\Program Files\VideoLAN\VLC\
--
-- Base (*nix): ~/.local/share/vlc/
--       (win): %appdata%\vlc\
--
-- Folder Structure:
--  $base/lua/sd/di_vlc.lua           # This Script
--  $base/lua/sd/modules/common.luac  # Found in $app/lua/intf/modules
--

lazy_loaded = false
json = nil

function lazy_load()
    if lazy_loaded then return nil end
    json = require "dkjson"
    json["parse_url"] = function(url)
        local string = ""
        local line = ""
        local stream = vlc.stream(url)
        repeat
            line = stream:readline()
            string = string..line
        until line ~= nil
        return json.decode(string)
    end
    lazy_loaded = true
end

function descriptor()
    return {title = "DI Radio Stations"}
end

function main()
    lazy_load()
    local stations = {["DI.FM"]     = {"di.fm", "2"},         -- 2 = aac
                      ["JazzRadio"] = {"jazzradio.com", "3"}, -- 3 = mp3 (aac pls = 404)
                      ["RockRadio"] = {"rockradio.com", "2"}, -- 2 = aac
                      ["Sky.FM"]    = {"sky.fm", "3"}}        -- 3 = mp3 (aac pls = 404)
    for key, data in pairs(stations) do
        local site = "http://www."..data[1]
        local url = "http://listen."..data[1].."/public"..data[2]
        local result = json.parse_url(url)
        local node = vlc.sd.add_node({title = key})
        if result then
            for index, item in ipairs(result) do
                node:add_subitem({title       = item["name"],
                                  path        = item["playlist"],
                                  description = item["description"],
                                  genre       = item["name"],
                                  url         = site,
                                  publisher   = "Digital Imported"})
            end
        end
    end
end

Usage
Restart VLC and open the playlist. On the left side, below Internet, you should find a new entry called DI Radio Stations. Click it and have fun.

Comments are welcome.

Edit 07/28/14: Added failure condition
Edit 07/31/14: Added HTTP header issue info
Edit 11/14/17: Added depracted info

Last edited by Tarqi (2017-11-14 03:06:23)


Knowing others is wisdom, knowing yourself is enlightenment. ~Lao Tse

Offline

Board footer

Powered by FluxBB