Git Product home page Git Product logo

lautfm_js_tools's Introduction

laut.fm Javascript API Tools

Javascript-Bibliothek zur Benutzung der laut.fm API.

Achtung: Beta-Software. Bei Problemen bitte Issue öffnen oder im laut.fm Forum melden.

Features

  • Sämtliche API-Call gehen über CORS (Cross Origin Resource Sharing). Die Unterschiede zwischen den Internet-Explorern und modernen Browsern gleichen die laut.fm API Tools aus.
  • Uhrzeiten werden in Javascript Time-Objekte konvertiert.
  • Einzel-Stations-Infos und Song-Infos können automatisch wiederholt abgerufen werden.
  • Uhrzeit-Unterschiede zwischen Server und Client werden erkannt und die nötigen Offsets automatisch eingerechnet.
  • Keine weiteren Abhängigkeiten

Convenience

  • Der Array-Prototyp wird mit forEach() erweitert. (siehe tutorialspoint.com).
  • Zeiten haben humanTimeShort() und humanTimeLong() für Uhrzeiten ala “12:34” und “12:34:56”.

Über den Javascript-Wrapper bereitgestellt API-Resourcen

CALLBACK_OR_OPTIONS ist die Funktion, mit der jeweils die Antwort verarbeitet werden soll.

Ab Version 0.3.0: Experimentell kann CALLBACK_OR_OPTIONS auch ein Options-Hash sein:

{container:CONTAINER, template:TEMPLATE, callback:CALLBACK}

CONTAINER und TEMPLATE können Dom-Elemente oder HTML IDs sein. TEMPLATE kann auch ein String als Template sein. Ein CALLBACK ist dann optional.

Eine komplette Einbindung des gerade laufenden Songs per Template inklusive Autoupdate sieht dann z.B. so aus:

<div id="song"></div>

<script type="text/html" id="song_template" charset="utf-8">
  <%= this.title %> - <%= this.artist.name %> (<%= this.started_at.humanTimeLong() %> - <%= this.ends_at.humanTimeLong() %>)
</script>

<script type="text/javascript" charset="utf-8">
  laut.fm.station('maxeinsdreissig').current_song({container:'song', template:'song_template'}, true);
</script>

Im Template gibt es zwei Tags: <%= ... %> (für Ausgabe) und <% ... %> für stille Auswertung. Ein Template für die letzen gespielten Songs sieht also z.B. so aus:

<script type="text/html" id="songs_template" charset="utf-8">
  <% this.forEach(function(song){ %>
    <li><%= song.started_at.humanTimeLong() %> <%= song.title %> - <%= song.artist.name %></li>
  <% }); %>
</script>

Allgmeine Resourcen

laut.fm.server_status(CALLBACK_OR_OPTIONS)
laut.fm.letters(CALLBACK_OR_OPTIONS)
laut.fm.genres(CALLBACK_OR_OPTIONS)
laut.fm.station_names(CALLBACK_OR_OPTIONS)
laut.fm.listeners(CALLBACK_OR_OPTIONS)

Stations-Auflistungen

Alle Stations-Auflistungen funktionieren mit Optionen zur Paginierung:

OPTIONS: limit und/oder offset

laut.fm.stations.all(CALLBACK_OR_OPTIONS[, OPTIONS])
laut.fm.stations.letter(LETTER, CALLBACK_OR_OPTIONS[, OPTIONS])
laut.fm.stations.numbers(CALLBACK_OR_OPTIONS[, OPTIONS])
laut.fm.stations.genre(GENRE, CALLBACK_OR_OPTIONS[, OPTIONS])

GENRE muss eins der Genres von laut.fm.genres() sein.

laut.fm.stations.names(NAMES, CALLBACK_OR_OPTIONS)

NAMES müssen Sendernamen sein, als String Komma-separiert oder als Array.

Einzel-Stations-Infos

laut.fm.station('NAME').info(CALLBACK_OR_OPTIONS)
laut.fm.station(NAME).current_song(CALLBACK_OR_OPTIONS)
laut.fm.station(NAME).last_songs(CALLBACK_OR_OPTIONS)
laut.fm.station(NAME).next_artists(CALLBACK_OR_OPTIONS)
laut.fm.station(NAME).playlists(CALLBACK_OR_OPTIONS)
laut.fm.station(NAME).schedule(CALLBACK_OR_OPTIONS)
laut.fm.station(NAME).listeners(CALLBACK_OR_OPTIONS)

Einzel-Stations-Infos mit Auto-Update

Wird den Funktionen info, current_song, last_songs oder next_artists als zweiter parameter ein true übergeben, wird der API-Call und der zugehörige Callback automatisch wiederholt:

laut.fm.station(NAME).current_song(CALLBACK_OR_OPTIONS, true)

Wechselt man zum Beispiel die current_song-Anzeige zwischen mehreren Stationen, kann man das Autoupdate wieder canceln:

var watchedStation = laut.fm.station(NAME1).current_song(CALLBACK_OR_OPTIONS, true);
  // ...
watchedStation.unwatch();
var watchedStation = laut.fm.station(NAME2).current_song(CALLBACK_OR_OPTIONS, true);

Die API-Suche

TODO: Doku

  • laut.fm.search.stations(QUERY)

Release History

  • 2019-02-27 0.10.0 removed player (incl. flowplayer) and JSON polyfill
  • 2017-01-27 0.9.1 https support all over.
  • 2012-10-23 0.8.0 next_arists support. in production on the official laut.fm website.
  • 2012-03-26 0.7.0 added auto updates
  • 2012-03-26 0.6.0 all listeners bug fix
  • 2011-11-23 0.3.0 added experimental templating support. in production on the laut.de website.
  • 2011-11-21 0.2.0 first official release

lautfm_js_tools's People

Contributors

niko avatar seeekr avatar

Watchers

James Cloos 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.