djjour 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
@@ -0,0 +1,24 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ djjour (0.0.1)
5
+ dnssd (>= 2.0)
6
+ nokogiri (>= 1.5.0)
7
+ sinatra (>= 1.2.6)
8
+
9
+ GEM
10
+ remote: http://rubygems.org/
11
+ specs:
12
+ dnssd (2.0)
13
+ nokogiri (1.5.0)
14
+ rack (1.3.3)
15
+ sinatra (1.2.6)
16
+ rack (~> 1.1)
17
+ tilt (>= 1.2.2, < 2.0)
18
+ tilt (1.3.3)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ djjour!
File without changes
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- mode: ruby -*-
3
+
4
+ require 'djjour'
5
+
6
+ DJjour::CLI.run(*ARGV)
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'djjour/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'djjour'
7
+ s.version = DJjour::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ['Glen Maddern', 'Ivan Vanderbyl', 'Pat Allan']
10
+ s.email = ['glenmaddern@gmail.com']
11
+ s.homepage = ''
12
+ s.summary = %q{Shared Music DJ}
13
+ s.description = %q{Client and server DJ Music system that hooks into iTunes.}
14
+
15
+ s.rubyforge_project = 'djjour'
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ['lib']
21
+
22
+ s.add_runtime_dependency 'dnssd', '>= 2.0'
23
+ s.add_runtime_dependency 'nokogiri', '>= 1.5.0'
24
+ s.add_runtime_dependency 'sinatra', '>= 1.2.6'
25
+ end
@@ -0,0 +1,14 @@
1
+ require 'dnssd'
2
+ require 'json'
3
+ require 'nokogiri'
4
+ require 'sinatra'
5
+ require 'socket'
6
+
7
+ module DJjour
8
+ #
9
+ end
10
+
11
+ require 'djjour/bonjour'
12
+ require 'djjour/cli'
13
+ require 'djjour/client'
14
+ require 'djjour/version'
@@ -0,0 +1,7 @@
1
+ class DJjour::Bonjour
2
+ def self.register
3
+ DNSSD.register Socket.gethostname.gsub(/\W/,'_'), '_djjour._tcp', nil, 1337 do |r|
4
+ puts "registered #{r.fullname}" if r.flags.add?
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ class DJjour::CLI
2
+ def self.run(*arguments)
3
+ DJjour::Client.run!
4
+ end
5
+ end
@@ -0,0 +1,82 @@
1
+ class DJjour::Client < Sinatra::Base
2
+ set :port, 1337
3
+
4
+ # runs once server is booted
5
+ configure do
6
+ DJjour::Bonjour.register
7
+ end
8
+
9
+ def mpeg?(t); t['Kind'] == "MPEG audio file" end
10
+ def aac?(t); t['Kind'] =~ /AAC audio file/ end
11
+
12
+ get '/' do
13
+ content_type :json
14
+ {count: tracks.count, tracks: tracks}.to_json
15
+ end
16
+
17
+ get '/mp3' do
18
+ content_type :json
19
+ mp3 = tracks.select(&method(:mpeg?))
20
+ {count: mp3.count, tracks: mp3}.to_json
21
+ end
22
+
23
+ get '/aac' do
24
+ content_type :json
25
+ aac = tracks.select(&method(:mpeg?))
26
+ {count: aac.count, tracks: aac}.to_json
27
+ end
28
+
29
+ get '/tracks/:id' do
30
+ content_type :json
31
+ tracks_by_id[params[:id].to_i].to_json
32
+ end
33
+
34
+ get '/tracks/:id/file' do
35
+ track = tracks_by_id[params[:id].to_i]
36
+ if mpeg?(track)
37
+ content_type 'audio/mpeg'
38
+ else
39
+ content_type 'audio/aac'
40
+ end
41
+
42
+ send_file URI.decode(track['Location'])[/file:\/\/localhost(.*)/,1]
43
+ end
44
+
45
+ private
46
+
47
+ def tracks_by_id
48
+ @tracks_by_id ||= tracks.inject({}) { |h,t| h[t['Track ID']] = t; h }
49
+ end
50
+
51
+ def tracks
52
+ @tracks||= tracks_dict.xpath("dict").map { |track|
53
+ h = {}
54
+ track.elements.each_slice(2) do |key, val|
55
+ raise "WATKEY #{key}" if key.name != 'key'
56
+ h[key.text] = case val.name
57
+ when 'integer'
58
+ val.text.to_i
59
+ when 'string'
60
+ val.text
61
+ when 'date'
62
+ val.text
63
+ when 'true'
64
+ true
65
+ when 'false'
66
+ true
67
+ else
68
+ raise "WATVAL #{val}"
69
+ end
70
+ end
71
+ h
72
+ }
73
+ end
74
+
75
+ def tracks_dict
76
+ @tracks_dict ||= document.xpath("*/dict/key[contains(text(), 'Tracks')]").first.next_element
77
+ end
78
+
79
+ def document
80
+ @document ||= Nokogiri::XML(File.read(File.expand_path("~/Music/iTunes/iTunes Music Library.xml")))
81
+ end
82
+ end
@@ -0,0 +1,3 @@
1
+ module DJjour
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: djjour
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Glen Maddern
9
+ - Ivan Vanderbyl
10
+ - Pat Allan
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2011-09-21 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: dnssd
18
+ requirement: &70172459749460 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
23
+ version: '2.0'
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *70172459749460
27
+ - !ruby/object:Gem::Dependency
28
+ name: nokogiri
29
+ requirement: &70172459748960 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: 1.5.0
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: *70172459748960
38
+ - !ruby/object:Gem::Dependency
39
+ name: sinatra
40
+ requirement: &70172459748500 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.2.6
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: *70172459748500
49
+ description: Client and server DJ Music system that hooks into iTunes.
50
+ email:
51
+ - glenmaddern@gmail.com
52
+ executables:
53
+ - djjour
54
+ extensions: []
55
+ extra_rdoc_files: []
56
+ files:
57
+ - Gemfile
58
+ - Gemfile.lock
59
+ - README.textile
60
+ - Rakefile
61
+ - bin/djjour
62
+ - djjour.gemspec
63
+ - lib/djjour.rb
64
+ - lib/djjour/bonjour.rb
65
+ - lib/djjour/cli.rb
66
+ - lib/djjour/client.rb
67
+ - lib/djjour/version.rb
68
+ homepage: ''
69
+ licenses: []
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project: djjour
88
+ rubygems_version: 1.8.6.1
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: Shared Music DJ
92
+ test_files: []