elcuervo / airplay

Airplay bindings to Ruby
MIT License
1.07k stars 70 forks source link

Airplay plugins #73

Open elcuervo opened 10 years ago

elcuervo commented 10 years ago

I was thinking about adding a plugin system for airplay. Something like:

Airplay.plugin Airplay::Youtube

Or something like that. The idea is to allow a middleware stack to be executed. The plugins can implement their own play and view to allow operations like get the source youtube video or apply a filter to the image.

This could open the door for customizations in the flow and a prettier CLI.

What do you guys think?

sodabrew commented 10 years ago

+1. Provides a place for useful non-core contributions to go.

Could distribute these in a third gem, airplay-plugins, from the same git repo.

sodabrew commented 10 years ago

Since Ruby modules and classes are open, the plugin can just register itself. Maybe provide media type and url hooks? I'm thinking of client code like this:

require 'airplay'
require 'airplay/plugins/youtube'

airplay.play 'youtube://youtubeurl'
elcuervo commented 10 years ago

I tend to hate automagic stuff but I have to say that this solutions seems pretty clean. My only concern is people forgetting about the custom protocol.

sodabrew commented 10 years ago

I'm not totally sold on the protocol part. There are times when that's a good indicator, like rtsp:// but in this case it's very contrived.

elcuervo commented 10 years ago

Yep. It's a tough call. Maybe leaving it like an explicit load is enough for now.

require "airplay"

module Airplay::Plugins::Youtube
  def play(url, options = {})
    # Fetches the mp4 version of the video
    "correct_mp4_url"
  end
end

Airplay.plugin Airplay::Plugins::Youtube
Airplay["Apple TV"].play("http://youtube.com...")

Or something like that.

sodabrew commented 10 years ago

Sure, but how does the plugin know to capture that call to play and interpret it as youtube?

Maybe plugins get to register a play hook that can do a regex against the url?

If calling the plugin simply monkey-patched in a new version of play I think that would be kind of ugly.

elcuervo commented 10 years ago

A middleware callstack. Every registered plugin that has a play or view method gets added to the stack. So you can have something like this:

+---------------+    +---------------+    +--------------+
| Plugin A play |    | Plugin B play |    | Airplay play |
|    method     +--->|    method     +--->|    method    |
+---------------+    +---------------+    +--------------+

Again... thinking out loud here :smiley:

sodabrew commented 10 years ago

Yes, that's what I'm thinking, too! This would also solve the transcoding problem. A plugin could match on known-incompatible media urls, set up a transcode chain, and pass an IO handle or alternate local service port to the next in the stack.

elcuervo commented 10 years ago

:joy: Awesome. I love being in the same page!.