• Stars
    star
    192
  • Rank 197,358 (Top 4 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 14 years ago
  • Updated about 14 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Playdar - a content resolver for music
Playdar
=======
Playdar is a music content resolver, written in Erlang, MIT licensed.
It's modular and can be extended using resolver scripts in any language.
It has an HTTP API to answer the question "can i play this song?".
If yes, you get a localhost URL that will play the song, from whichever souce
playdar resolved it to (plugins do the resolving).

Read on for build instructions and an "Understanding Playdar" tutorial.
More information and binary installers / packages can be found at:
http://www.playdar.org/

Building
--------
To build all the erlang code:

    $ make

To build the collection scanner (needs taglib, g++):

    $ make scanner

Running
-------

    $ ./playdarctl start-debug

In another terminal you can now do:

    $ ./playdarctl numfiles
    $ ./playdarctl scan "/path/to/music"
    $ ./playdarctl numfiles

Then check out http://localhost:60210/ and http://www.playdar.org/demos/

Understanding Playdar
=====================

The core playdar daemon is a generic content-resolver engine.
It contains a simple http server (Mochiweb), a resolver infrastructure, external
module loader (plugins) and configuration management. 

Playdar core allows you to dispatch queries and check query status, but by 
itself it can't resolve content. This is all handled by plugins.

Clients talk to Playar using the HTTP API. JSON is used for everything.

Resolver Queries
----------------
All queries passed to Playdar are simply JSON objects of any shape or size. 
Playdar checks for a "qid" propery - a GUID for the query, in each object,
but nothing else - it's up to the plugins to decode the query objects.

If a plugin doesn't recognise a query it simply ignores it.

The following examples are similar in syntax to how Playdar is built, but may
not necessarily be exactly correct. They serve to illustrate the query
mechanics:

Music Query Example
-------------------
The query object:
{
    "qid" : "XXX123",
    "artist" : "Big Bad Sun",
    "track"  : "Sweet Melissa"
}

This is a simple query for a specific song. In this case, the default plugins
that ship with Playdar know how to handle it - because we're using Playdar as
a music content resolver. The library plugin will search your disk and respond
with a result if you have a copy of the song being searched for:
A result object:
{
    "sid" : "YYY456",
    "qid" : "XXX123",
    "result" : {
        "url" : "/path/to/sweet_melissa.mp3",
        "bitrate" : 128,
        "duration" : 283,
        "artist" : "Big Bad Sun",
        "track" : "Sweet Melissa (live)",
        "score" : 0.89
    }
}
In the the above example, the library plugin reports a result for the query 
with a score of 0.89 - it found a live version - but close enough.
The "sid" propery is a GUID for the result.

Resolvers can report multiple result objects for any query.

Non-music Example
-----------------
Depending on the plugins loaded, Playdar could be used to resolve anything.
Here's a fictional example query for an academic essay:
{
    "qid"    : "XXX789",
    "author" : "Jonathan swift",
    "year"   : 1729,
    "title"  : "a modest propsal"
}
... and if you have a resolver plugin that could search for essays and academic
papers, it might respond like this:
{
    "sid"    : "YYY123",
    "qid"    : "XXX789",
    "result" : {
        "author" : "Jonathan Swift",
        "year"   : 1729,
        "title"  : "A Modest Proposal",
        "score"  : 1.00,
        "category"   : "humour",
        "url"    : "http://art-bin.com/art/omodest.html"
    }
}

In this example, the resolver matched the query to an essay posted on the web
instead of the local filesystem. 

Custom Protocols
----------------
Playdar ships with support for reading content from http:// and file:// URLs.
That is to say support for those protocols is implemented by plugins that ship
by default.

A resolver could provide an url like this: "custom://abc123-modest-blah" and
register itself as a handler for custom:// urls. This allows resolver plugins
to fetch and stream content in any way they like. 
You could add support for ftp:// or a custom p2p:// protocol if you wanted.

How Clients Fetch Results
-------------------------
The actual URL to the resolved content, be it a local filesystem or http URL,
is never exposed to clients using the Playdar HTTP API. The "url" propery is
stripped out of result objects before they are returned to clients.
The "sid" GUID in every result object is used to request the content, like so:
 http://localhost:60210/sid/<sid>
Playdar will then fetch the content using the appropriate protocol handler
internally (file, http, p2p, custom, etc), and respond to the client with a 
well formed HTTP response. This means that clients only need to understand
HTTP. The details of how content is fetched by Playdar are hidden from clients.
Clients don't need to know where or how you access your music. 
The Playdar API lets them ask "Can you play this song". The details of where
and how you access the song are kept private.
To reiterate: clients can't tell whether you are playing a song you have on
your local disk, or are streaming over the internet from some other service.

How webpages interact with Playdar
----------------------------------
Desktop apps can obviously just use the HTTP API on localhost without any 
special considerations. Webapps and anything running in the browser is 
subject to the browser security model, specifically the "same-origin policy".
This means that you can't access content in a document loaded from a domain
different to the domain your javascript executes in.

To solve this problem, playdar uses JSONP callbacks. Instead of requesting
http://localhost:60210/api/?method=stat
and getting json in response, you inject a script tag into the dom like this:
<script language="javascript" 
        src="http://localhost:60210/api/?method=stat&jsonp=my_callback"/>
Playdar responds with the json object wrapped in your padding:
 my_callback(...normal json response...);
which then fires the my_callback function - voilia, cross domain RPC.

More Repositories

1

ketama

C library for consistent hashing, and langauge bindings
C
825
star
2

irccat

IRC bot that simplifies posting to IRC from shell scripts
Java
277
star
3

erlang-spdy

Library implementing the SPDY protocol
Erlang
104
star
4

relflow

Version-incrementing, appup-generating, relx-coaxing, workflow-assistant for Erlang projects using rebar3.
Erlang
92
star
5

estatsd

Erlang stats aggregation app that periodically flushes data to graphite
Erlang
88
star
6

playdar

Abandoned C++ codebase, see playdar-core repo!
C
49
star
7

heatmiser-neohub.py

Python library to talk the direct-lan-api to control a Heatmiser Neohub / Neostats - and home-assistant component
Python
31
star
8

erlang_rebar_example_project

Basic project using rebar, to demonstrate upgrades and packaging etc
Erlang
24
star
9

erlang-reup

Watches for .erl & .hrl changes, recompiles and reloads. You know, for development.
Erlang
24
star
10

erlang-cassandra-cql

cassandra driver in erlang that speaks native cassandra protocol
Erlang
22
star
11

mochiweb-websockets

***OBSOLETE, using my mochiweb repo now ***
Erlang
20
star
12

libf2f

Library for building p2p networks, C++ boost/asio
C++
16
star
13

libportfwd

Set up port fwds and find external IP: C++/CMake wrapper for miniupnpc and nat-pmp libs
C
14
star
14

greynet

A darknet/mesh network plugin for legacy C++ playdar codebase
C++
11
star
15

doorbird-mdns-vlan-subnet-bridge

Allow ios/android apps to discover and direct connect to doorbirds in a different subnet
Python
8
star
16

gocat

IRCCat in Go
Go
7
star
17

musickit

Qt+Webkit container app that exposes phonon/etc APIs to js
JavaScript
6
star
18

logtail

tail -f logfiles in a browser using websockets (erlang)
Erlang
6
star
19

sonos-shipping-forecast

Play the Shipping Forecast from BBC Radio 4, then return Sonos to original state.
Python
6
star
20

libmemcached

temporary repo for patching libmemcached
Shell
6
star
21

dotvim

my .vim
Vim Script
5
star
22

www.playdar.org

Playdar website
JavaScript
5
star
23

bevy_timewarp

A rollback library that buffers component state. Useful for netcode.
Rust
5
star
24

captainhook

Batch set github service hooks for all repos in an org
Python
4
star
25

vagrant-chef-basebox

Basic vagrant+chef setup
Ruby
4
star
26

estr-erlang-elixir-binary-string

Adaptor for using Elixir's UTF8 binary string module in Erlang
Erlang
3
star
27

bevy_naia_laminar

bevy plugin for laminar atop naia-socket
Rust
2
star
28

appupper

deprecated, see relflow:
Erlang
2
star
29

relsandbox

Release sandbox app (various changes, with appups)
Erlang
2
star
30

irccat-cookbook

chef cookbook for irccat
HTML
2
star
31

dot-janus

My .janus dir, containing vim config and plugins in addition to janus vim distro
Vim Script
2
star
32

erlang-countess

rebar3 release playground for blog post
Erlang
1
star
33

qdaapd

An embeddable C++/Qt DAAP server library
C
1
star
34

conjist

music network thing
C
1
star
35

radioblink

WIP - Circuit which takes the audio output of a PMR radio and blinks LEDs when it receives a signal
C
1
star
36

sharesight-custom-investment-price-updater

updates vg small cap price to sharesight
Rust
1
star