Coder Social home page Coder Social logo

victorolayemi / icecast-shoutcast-metadata-grabber Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cryptiksouls/icecast-shoutcast-metadata-grabber

0.0 1.0 0.0 15 KB

Service worker to extract icecast / shoutcast metadata from your stream. Browser based solution for perfectly timed now playing updates

Home Page: https://toohotradio.net/metadata/

JavaScript 100.00%

icecast-shoutcast-metadata-grabber's Introduction

icecast-shoutcast-metadata-grabber

Service worker to extract icecast / shoutcast metadata from your stream. Browser based solution for perfectly timed now playing updates

After trying many methods of updating the now playing info on our player and getting sick of the timing always being sketchy I decided to investigate how the servers pass the info.

Turns out that if you add an extra header when you connect to the server you can make it send you a different stream which is made up of the mp3 and the metadata spliced together. The problem is that your browser won't play it, as it's not a proper mp3.

This is a simple service worker which will intercept network requests from any html audio elements on your page and add the header to a fetch request to retrieve the metadata stream from your server.

It then handles the response, splitting the metadata and the mp3 data and returns the mp3 data as a readable stream to your audio element and posts a message containing the metadata to your main window.

The header needed to make the server output the metadata stream is only available under the same origin, this is a limitation of the fetch api so if your web server is on a different domain to your streaming server you'll have to come up with your own workaround for that.

Simply register the service worker on the page your player is on and it should start doing it's thing.

navigator.serviceWorker.register('worker.min.js')

You just need an event handler for messages from the worker to do something with the metadata.

navigator.serviceWorker.addEventListener('message', event => {
    if(event.origin != 'https://example.com'){
        return;
    }
    var meta = event.data.msg;
    meta = meta.substring(meta.indexOf("'") + 1,meta.lastIndexOf("'"));
    document.querySelector('div').innerText = meta;
});

Simple demo at https://toohotradio.net/metadata/

icecast-shoutcast-metadata-grabber's People

Contributors

cryptiksouls avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.