m3ugen 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +40 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +41 -0
- data/config/cucumber.yml +6 -0
- data/features/generate_m3u.feature +13 -0
- data/features/step_definitions/m3u_steps.rb +71 -0
- data/lib/m3ugen/m3u_generator.rb +46 -0
- data/nbproject/project.properties +3 -0
- data/nbproject/project.xml +11 -0
- data/notes.txt +19 -0
- data/test_data/data.ser +0 -0
- metadata +124 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "shoulda", ">= 0"
|
10
|
+
gem "bundler", "~> 1.0.0"
|
11
|
+
gem "jeweler", "~> 1.6.4"
|
12
|
+
gem "cucumber", "1.1.3"
|
13
|
+
gem "rspec", ">= 2.7.0"
|
14
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
builder (2.1.2)
|
5
|
+
cucumber (1.1.3)
|
6
|
+
builder (>= 2.1.2)
|
7
|
+
diff-lcs (>= 1.1.2)
|
8
|
+
gherkin (~> 2.6.7)
|
9
|
+
json (>= 1.4.6)
|
10
|
+
term-ansicolor (>= 1.0.6)
|
11
|
+
diff-lcs (1.1.2)
|
12
|
+
gherkin (2.6.9)
|
13
|
+
json (>= 1.4.6)
|
14
|
+
git (1.2.5)
|
15
|
+
jeweler (1.6.4)
|
16
|
+
bundler (~> 1.0)
|
17
|
+
git (>= 1.2.5)
|
18
|
+
rake
|
19
|
+
json (1.4.6)
|
20
|
+
rake (0.9.2.2)
|
21
|
+
rspec (2.7.0)
|
22
|
+
rspec-core (~> 2.7.0)
|
23
|
+
rspec-expectations (~> 2.7.0)
|
24
|
+
rspec-mocks (~> 2.7.0)
|
25
|
+
rspec-core (2.7.1)
|
26
|
+
rspec-expectations (2.7.0)
|
27
|
+
diff-lcs (~> 1.1.2)
|
28
|
+
rspec-mocks (2.7.0)
|
29
|
+
shoulda (2.11.3)
|
30
|
+
term-ansicolor (1.0.7)
|
31
|
+
|
32
|
+
PLATFORMS
|
33
|
+
ruby
|
34
|
+
|
35
|
+
DEPENDENCIES
|
36
|
+
bundler (~> 1.0.0)
|
37
|
+
cucumber (= 1.1.3)
|
38
|
+
jeweler (~> 1.6.4)
|
39
|
+
rspec (>= 2.7.0)
|
40
|
+
shoulda
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 hbt
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= m3ugen
|
2
|
+
|
3
|
+
Scans a directory recursively and generates m3u file
|
4
|
+
|
5
|
+
== Contributing to m3ugen
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2011 hbt. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
$LOAD_PATH.unshift('lib')
|
15
|
+
|
16
|
+
|
17
|
+
require 'jeweler'
|
18
|
+
require 'm3ugen'
|
19
|
+
Jeweler::Tasks.new do |gem|
|
20
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
21
|
+
gem.name = "m3ugen"
|
22
|
+
gem.homepage = "http://github.com/hbt/m3ugen"
|
23
|
+
gem.license = "MIT"
|
24
|
+
gem.summary = %Q{Generates m3u file}
|
25
|
+
gem.description = %Q{Generates m3u file for music players}
|
26
|
+
gem.email = "hassenbentanfous@gmail.com"
|
27
|
+
gem.authors = ["hbt"]
|
28
|
+
gem.executables = ["m3ugen"]
|
29
|
+
gem.version = M3uGen::VERSION
|
30
|
+
|
31
|
+
# dependencies defined in Gemfile
|
32
|
+
end
|
33
|
+
Jeweler::RubygemsDotOrgTasks.new
|
34
|
+
|
35
|
+
require "cucumber/rake/task"
|
36
|
+
Cucumber::Rake::Task.new(:test) do |task|
|
37
|
+
task.cucumber_opts = ["features"]
|
38
|
+
end
|
39
|
+
|
40
|
+
task :default => :test
|
41
|
+
|
data/config/cucumber.yml
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Feature: Generate m3u
|
2
|
+
generates m3u file listing all music files within a directory
|
3
|
+
|
4
|
+
Scenario: run the command
|
5
|
+
Given no command line parameters
|
6
|
+
When I use the command by default
|
7
|
+
Then it should scan all directories recursively and return a list of files
|
8
|
+
And it should save the list within the directory where the command was execute
|
9
|
+
And it should contain filenames with their full path
|
10
|
+
But it should not generate a m3u file if we have no music files
|
11
|
+
|
12
|
+
When -r is passed as an option
|
13
|
+
Then it should generate one music in each directory recursively
|
@@ -0,0 +1,71 @@
|
|
1
|
+
Dir["#{File.dirname(__FILE__)}/../../lib/**/*.rb"].each {|f| require f}
|
2
|
+
|
3
|
+
module M3uGen
|
4
|
+
class FileMock
|
5
|
+
class << self
|
6
|
+
def test_dir
|
7
|
+
"/tmp/tests/m3ugen"
|
8
|
+
end
|
9
|
+
def create
|
10
|
+
FileUtils.rm_rf test_dir if File.exist? test_dir
|
11
|
+
test_files = Marshal.load(File.new("#{File.dirname(__FILE__)}/../../test_data/data.ser", 'r'))
|
12
|
+
|
13
|
+
test_files.each do |file_name|
|
14
|
+
dir = File.dirname(file_name)
|
15
|
+
FileUtils.mkdir_p dir unless File.exists? dir
|
16
|
+
File.open(file_name, "w") {}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
Given /^no command line parameters$/ do
|
24
|
+
@gen = M3uGen::M3uGenerator.new
|
25
|
+
end
|
26
|
+
|
27
|
+
When /^I use the command by default$/ do
|
28
|
+
M3uGen::FileMock::create
|
29
|
+
File.size(M3uGen::FileMock.test_dir).should be >= 60
|
30
|
+
|
31
|
+
Dir.chdir M3uGen::FileMock::test_dir
|
32
|
+
end
|
33
|
+
|
34
|
+
Then /^it should scan all directories recursively and return a list of files$/ do
|
35
|
+
@files = @gen.scan
|
36
|
+
@files.size.should == 119
|
37
|
+
end
|
38
|
+
|
39
|
+
Then /^it should save the list within the directory where the command was execute$/ do
|
40
|
+
@gen.generate
|
41
|
+
File.exist?(Dir.pwd + "/music.m3u").should be true
|
42
|
+
end
|
43
|
+
|
44
|
+
Then /^it should contain filenames with their full path$/ do
|
45
|
+
@files = @gen.scan
|
46
|
+
@files.inject(true) {|valid, name| valid & name.start_with?(Dir.pwd) }.should be true
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
Then /^it should not generate a m(\d+)u file if we have no music files$/ do |arg1|
|
51
|
+
tmp = '/tmp/tests/m3ugen/monkey/'
|
52
|
+
Dir.mkdir(tmp)
|
53
|
+
Dir.chdir(tmp)
|
54
|
+
|
55
|
+
@gen.generate
|
56
|
+
|
57
|
+
File.exists?(tmp + 'music.m3u').should be false
|
58
|
+
end
|
59
|
+
|
60
|
+
When /^\-r is passed as an option$/ do
|
61
|
+
Dir.chdir M3uGen::FileMock::test_dir
|
62
|
+
@gen.generate :recursive => true
|
63
|
+
end
|
64
|
+
|
65
|
+
Then /^it should generate one music in each directory recursively$/ do
|
66
|
+
@files = @gen.scan
|
67
|
+
@files.each do |f|
|
68
|
+
File.exist?(File.dirname(f) + File::SEPARATOR + @gen.default_filename).should be true
|
69
|
+
end
|
70
|
+
File.exist?(Dir.pwd + "/music.m3u").should be true
|
71
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
module M3uGen
|
3
|
+
class M3uGenerator
|
4
|
+
|
5
|
+
def supported_extensions
|
6
|
+
%w[mp3 wav ogg wma]
|
7
|
+
end
|
8
|
+
|
9
|
+
def default_filename
|
10
|
+
"music.m3u"
|
11
|
+
end
|
12
|
+
|
13
|
+
def scan
|
14
|
+
extensions = supported_extensions.join(',')
|
15
|
+
Dir["**/*.{#{extensions}}"].map! { |f| Dir.pwd + File::SEPARATOR + f }
|
16
|
+
end
|
17
|
+
|
18
|
+
def generate(opts = {})
|
19
|
+
def write_files(dir, files)
|
20
|
+
File.open(dir + File::SEPARATOR + default_filename, 'w') { |f| f.write(files.join("\n")) }
|
21
|
+
end
|
22
|
+
|
23
|
+
files = scan
|
24
|
+
|
25
|
+
if files.size != 0
|
26
|
+
if opts[:recursive]
|
27
|
+
|
28
|
+
dir_files = {}
|
29
|
+
|
30
|
+
files.each do |f|
|
31
|
+
dir_files[File.dirname(f)] ||= []
|
32
|
+
dir_files[File.dirname(f)] << f
|
33
|
+
end
|
34
|
+
|
35
|
+
dir_files.each do |dir_name,files|
|
36
|
+
write_files(dir_name, files)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
write_files(Dir.pwd, files)
|
41
|
+
else
|
42
|
+
puts "No #{supported_extensions.join('|')} files found"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project xmlns="http://www.netbeans.org/ns/project/1">
|
3
|
+
<type>org.netbeans.modules.ruby.rubyproject</type>
|
4
|
+
<configuration>
|
5
|
+
<data xmlns="http://www.netbeans.org/ns/ruby-project/1">
|
6
|
+
<name>m3ugen</name>
|
7
|
+
<source-roots/>
|
8
|
+
<test-roots/>
|
9
|
+
</data>
|
10
|
+
</configuration>
|
11
|
+
</project>
|
data/notes.txt
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
option parser
|
2
|
+
# http://ruby.about.com/od/advancedruby/a/optionparser.htm
|
3
|
+
|
4
|
+
create binary + set permissions
|
5
|
+
create gem
|
6
|
+
create gem
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
Goals/Features:
|
11
|
+
- generate m3u file for an entire directory -- recursively but 1-* (1 m3u for all directories)
|
12
|
+
- generate m3u file per directory -- recursively but 1-1 (1 per directory)
|
13
|
+
- add filter for file formats + extensions in case I convert them
|
14
|
+
- clean filenames for unix usage i.e no spaces, no weird characters
|
15
|
+
|
16
|
+
generate full path filenames
|
17
|
+
|
18
|
+
check /home/hassen/.rvm/gems/ruby-1.9.2-head/gems/jeweler-1.6.4 for executable
|
19
|
+
/home/hassen/.rvm/gems/ruby-1.9.2-head/gems/jeweler-1.6.4
|
data/test_data/data.ser
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: m3ugen
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- hbt
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-12-04 00:00:00 -05:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: shoulda
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ">="
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: "0"
|
25
|
+
type: :development
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ~>
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 1.0.0
|
36
|
+
type: :development
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: jeweler
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 1.6.4
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: cucumber
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - "="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: 1.1.3
|
58
|
+
type: :development
|
59
|
+
version_requirements: *id004
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: rspec
|
62
|
+
prerelease: false
|
63
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.7.0
|
69
|
+
type: :development
|
70
|
+
version_requirements: *id005
|
71
|
+
description: Generates m3u file for music players
|
72
|
+
email: hassenbentanfous@gmail.com
|
73
|
+
executables: []
|
74
|
+
|
75
|
+
extensions: []
|
76
|
+
|
77
|
+
extra_rdoc_files:
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.rdoc
|
80
|
+
files:
|
81
|
+
- .document
|
82
|
+
- Gemfile
|
83
|
+
- Gemfile.lock
|
84
|
+
- LICENSE.txt
|
85
|
+
- README.rdoc
|
86
|
+
- Rakefile
|
87
|
+
- config/cucumber.yml
|
88
|
+
- features/generate_m3u.feature
|
89
|
+
- features/step_definitions/m3u_steps.rb
|
90
|
+
- lib/m3ugen/m3u_generator.rb
|
91
|
+
- nbproject/project.properties
|
92
|
+
- nbproject/project.xml
|
93
|
+
- notes.txt
|
94
|
+
- test_data/data.ser
|
95
|
+
has_rdoc: true
|
96
|
+
homepage: http://github.com/hbt/m3ugen
|
97
|
+
licenses:
|
98
|
+
- MIT
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: "0"
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ">="
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: "0"
|
116
|
+
requirements: []
|
117
|
+
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 1.6.2
|
120
|
+
signing_key:
|
121
|
+
specification_version: 3
|
122
|
+
summary: Generates m3u file
|
123
|
+
test_files: []
|
124
|
+
|