ongaku_ryoho_server 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +34 -0
- data/Rakefile +2 -0
- data/bin/ongaku_ryoho_server +22 -0
- data/lib/ongaku_ryoho_server/application.rb +164 -0
- data/lib/ongaku_ryoho_server/version.rb +6 -0
- data/lib/ongaku_ryoho_server.rb +11 -0
- data/ongaku_ryoho_server.gemspec +24 -0
- metadata +111 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 TODO: Write your name
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# Ongaku Ryoho Server
|
2
|
+
|
3
|
+
A little Sinatra web server wrapped in a gem specifically for the [Ongaku Ryoho client](https://github.com/icidasset/ongaku_ryoho).
|
4
|
+
|
5
|
+
## How to use
|
6
|
+
|
7
|
+
### Requirements
|
8
|
+
|
9
|
+
`Ruby 1.9.2`
|
10
|
+
|
11
|
+
### Installation
|
12
|
+
|
13
|
+
```bash
|
14
|
+
gem install ongaku_ryoho_server
|
15
|
+
```
|
16
|
+
|
17
|
+
### Usage
|
18
|
+
|
19
|
+
Go to a music directory and run the web server.
|
20
|
+
|
21
|
+
```bash
|
22
|
+
cd ~/Music
|
23
|
+
(rvmsudo) ongaku_ryoho_server (-p 80)
|
24
|
+
```
|
25
|
+
|
26
|
+
### Options
|
27
|
+
|
28
|
+
Some Sinatra options, that is.
|
29
|
+
|
30
|
+
```
|
31
|
+
-p port set the port (default is 4567)
|
32
|
+
-o addr set the host (default is 0.0.0.0)
|
33
|
+
-x turn on the mutex lock (default is off)
|
34
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require_relative '../lib/ongaku_ryoho_server.rb'
|
3
|
+
|
4
|
+
#
|
5
|
+
# Look for some of the Sinatra options and pass them along
|
6
|
+
|
7
|
+
options = {}
|
8
|
+
|
9
|
+
if ARGV.any?
|
10
|
+
require 'optparse'
|
11
|
+
OptionParser.new { |op|
|
12
|
+
op.on('-p port', 'set the port (default is 4567)') { |val| options[:port] = Integer(val) }
|
13
|
+
op.on('-o addr', 'set the host (default is 0.0.0.0)') { |val| options[:bind] = val }
|
14
|
+
op.on('-x', 'turn on the mutex lock (default is off)') { options[:lock] = true }
|
15
|
+
}.parse!(ARGV.dup)
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
#
|
20
|
+
# Run the server
|
21
|
+
|
22
|
+
OngakuRyohoServer.run(options)
|
@@ -0,0 +1,164 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'mp3info'
|
3
|
+
require 'sinatra'
|
4
|
+
require 'puma'
|
5
|
+
require 'uri'
|
6
|
+
|
7
|
+
module OngakuRyohoServer
|
8
|
+
#
|
9
|
+
# { Application }
|
10
|
+
#
|
11
|
+
# === Info
|
12
|
+
#
|
13
|
+
# Sinatra application which basicly takes care of everything
|
14
|
+
# More info inside
|
15
|
+
|
16
|
+
class Application < Sinatra::Base
|
17
|
+
set :environment, :production
|
18
|
+
set :server, :puma
|
19
|
+
|
20
|
+
|
21
|
+
# root
|
22
|
+
get '/' do
|
23
|
+
content_type :json
|
24
|
+
process_this_directory.to_json
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
# availability
|
29
|
+
get '/available?' do
|
30
|
+
"As it happens, I am."
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
# compare filelists
|
35
|
+
post '/check' do
|
36
|
+
content_type :json
|
37
|
+
check_files(params[:file_list]).to_json
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
# music file
|
42
|
+
get %r{.(mp3)$}i do
|
43
|
+
requested_item = URI.unescape(request.path_info[1..-1])
|
44
|
+
File.exists?(requested_item) ? send_file(requested_item) : 404
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
# everything else
|
49
|
+
get %r{.+} do
|
50
|
+
403
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
#
|
55
|
+
# Read directory
|
56
|
+
#
|
57
|
+
# => find music in the current directory
|
58
|
+
#
|
59
|
+
# [output]
|
60
|
+
# file list
|
61
|
+
#
|
62
|
+
def read_directory
|
63
|
+
Dir.glob('**/*.{mp3}')
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
#
|
68
|
+
# Check files
|
69
|
+
#
|
70
|
+
# => compares a given file list to the file list from the current directory
|
71
|
+
# show which files are missing and scan the ones that are new
|
72
|
+
#
|
73
|
+
# [params]
|
74
|
+
# file_list_from_client
|
75
|
+
#
|
76
|
+
# [output]
|
77
|
+
# object containing missing_files and new_tracks array
|
78
|
+
#
|
79
|
+
def check_files(file_list_from_client)
|
80
|
+
file_list_from_client = JSON.parse(file_list_from_client)
|
81
|
+
file_list_from_server = read_directory
|
82
|
+
|
83
|
+
missing_files = file_list_from_client - file_list_from_server
|
84
|
+
new_files = file_list_from_server - file_list_from_client
|
85
|
+
|
86
|
+
new_tracks = process_music(new_files, { last_modified: Time.now })
|
87
|
+
|
88
|
+
return {
|
89
|
+
missing_files: missing_files,
|
90
|
+
new_tracks: new_tracks
|
91
|
+
}
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
#
|
96
|
+
# Process this directory
|
97
|
+
#
|
98
|
+
# => read directory and process its contents
|
99
|
+
#
|
100
|
+
# [output]
|
101
|
+
# processed contents (see method below)
|
102
|
+
#
|
103
|
+
def process_this_directory
|
104
|
+
music_collection = read_directory
|
105
|
+
return process_music(music_collection)
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
#
|
110
|
+
# Process music
|
111
|
+
#
|
112
|
+
# => open each music track, get its tags and return all of them
|
113
|
+
#
|
114
|
+
# [params]
|
115
|
+
# music_collection : array of files to process (i.e. filepaths)
|
116
|
+
# extra_properties : properties to include in each track object/hash
|
117
|
+
#
|
118
|
+
# [output]
|
119
|
+
# tracks : collection of all the tracks their tags
|
120
|
+
#
|
121
|
+
def process_music(music_collection, extra_properties = {})
|
122
|
+
tracks = []
|
123
|
+
|
124
|
+
# loop over every track
|
125
|
+
music_collection.each do |location|
|
126
|
+
rpartition = location.rpartition('/')
|
127
|
+
filename = rpartition[2]
|
128
|
+
|
129
|
+
track = {}
|
130
|
+
|
131
|
+
case File.extname(filename)
|
132
|
+
when '.mp3'
|
133
|
+
Mp3Info.open(location) do |mp3|
|
134
|
+
tags = {
|
135
|
+
title: mp3.tag.title,
|
136
|
+
artist: mp3.tag.artist,
|
137
|
+
album: mp3.tag.album,
|
138
|
+
year: mp3.tag.year,
|
139
|
+
tracknr: mp3.tag.tracknum,
|
140
|
+
genres: mp3.tag.genre_s
|
141
|
+
}
|
142
|
+
|
143
|
+
tags.each do |key, value|
|
144
|
+
tags[key] = 'Unknown' if value.nil? or (value.respond_to?(:empty) and value.empty?)
|
145
|
+
end
|
146
|
+
|
147
|
+
tags.merge!({ filename: filename, location: location })
|
148
|
+
|
149
|
+
track = tags.clone
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
unless track.empty?
|
154
|
+
track.merge!(extra_properties)
|
155
|
+
tracks << track
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
# return all tracks
|
160
|
+
return tracks
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
164
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/ongaku_ryoho_server/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Steven Vandevelde"]
|
6
|
+
gem.email = ["icid.asset@gmail.com"]
|
7
|
+
gem.description = %q{Serves music to Ongaku Ryoho clients}
|
8
|
+
gem.summary = %q{Serves music to Ongaku Ryoho clients}
|
9
|
+
gem.homepage = "https://github.com/icidasset/ongaku_ryoho_server"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "ongaku_ryoho_server"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = OngakuRyohoServer::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency 'json', '~> 1.6.6'
|
19
|
+
gem.add_dependency 'ruby-mp3info', '~> 0.7.1'
|
20
|
+
gem.add_dependency 'sinatra', '~> 1.3.2'
|
21
|
+
gem.add_dependency 'puma'
|
22
|
+
|
23
|
+
gem.add_development_dependency 'rake'
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ongaku_ryoho_server
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Steven Vandevelde
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-10 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: json
|
16
|
+
requirement: &70299057328240 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.6.6
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70299057328240
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: ruby-mp3info
|
27
|
+
requirement: &70299057327740 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.7.1
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70299057327740
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: sinatra
|
38
|
+
requirement: &70299057327280 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.3.2
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70299057327280
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: puma
|
49
|
+
requirement: &70299057326900 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70299057326900
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: rake
|
60
|
+
requirement: &70299057326440 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *70299057326440
|
69
|
+
description: Serves music to Ongaku Ryoho clients
|
70
|
+
email:
|
71
|
+
- icid.asset@gmail.com
|
72
|
+
executables:
|
73
|
+
- ongaku_ryoho_server
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- .gitignore
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- bin/ongaku_ryoho_server
|
83
|
+
- lib/ongaku_ryoho_server.rb
|
84
|
+
- lib/ongaku_ryoho_server/application.rb
|
85
|
+
- lib/ongaku_ryoho_server/version.rb
|
86
|
+
- ongaku_ryoho_server.gemspec
|
87
|
+
homepage: https://github.com/icidasset/ongaku_ryoho_server
|
88
|
+
licenses: []
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
none: false
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 1.8.15
|
108
|
+
signing_key:
|
109
|
+
specification_version: 3
|
110
|
+
summary: Serves music to Ongaku Ryoho clients
|
111
|
+
test_files: []
|