album_shuffle 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +10 -0
- data/Rakefile +1 -0
- data/album_shuffle.gemspec +26 -0
- data/bin/album_shuffle +25 -0
- data/lib/album_shuffle.rb +55 -0
- data/lib/album_shuffle/version.rb +3 -0
- data/spec/album_shuffle_spec.rb +63 -0
- data/spec/spec_helper.rb +14 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YTYyZWI3M2QzYzI1Y2ZlNTVjYzYzNzE4MTI0NGRmMGZhYmRlNjU2MA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YjAxN2IxNDIzMTVmMTZmZTcyYzY2NWYwYmJmMDQ3ZDE0NTY4YThiYg==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YTdhN2JhZTk0YmEyNjg4M2VlMzZmZWFjNTYzOGE1MTBjMWU4ZGFlNDg5NjQx
|
10
|
+
ZDdmZThhOGE1MGFhMjA0N2M4N2YwMmI1NmM2MDAwYTE5ZGMwNTUyMWNjODkx
|
11
|
+
NzA2ZjUyZTY5NzM2NTkwMmU4ZTdhMzE1NTJkODU4ZmJhYmNhMjc=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MDY1YTQ4NzBkOWJjNGM0NjhiZDEyNDIwZDNiZjQzMzVlMTUwYzI4MTExODc0
|
14
|
+
NDgyNThjMGQyZjc1Y2E2NTI5ZGNhNTUwZDJlNzIwMDZiNjQwZTcxZjIxYmY3
|
15
|
+
OGUxNjUyYzgwNmY2NGM4Y2JlNTAxYjkyNGMxMDQ2N2FjZmFmOTE=
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Dan Schuman
|
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,10 @@
|
|
1
|
+
# AlbumShuffle
|
2
|
+
|
3
|
+
A basic shell tool to list random music directories. It is assumed that the directories are organized into music albums.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
`album_shuffle shuffle [--path="/your/music"] [folder limit]`
|
8
|
+
|
9
|
+
* `[folder limit]` is the maximum folders outputted
|
10
|
+
* `--path` defaults to current directory.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'album_shuffle/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "album_shuffle"
|
8
|
+
spec.version = AlbumShuffle::VERSION
|
9
|
+
spec.authors = ["Dan Schuman"]
|
10
|
+
spec.email = ["danschuman@gmail.com"]
|
11
|
+
spec.summary = %q{Command line tool to list random music directories}
|
12
|
+
spec.description = %q{Outputs a list of shuffled music directories. Assumes your music is already organized in a directory-per-album structure.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
|
25
|
+
spec.add_runtime_dependency "thor"
|
26
|
+
end
|
data/bin/album_shuffle
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'thor'
|
3
|
+
require 'album_shuffle'
|
4
|
+
|
5
|
+
class ShuffleExec < Thor
|
6
|
+
class_option :path
|
7
|
+
|
8
|
+
desc "shuffle [COUNT=10]", "Shuffles things and stuff"
|
9
|
+
def shuffle(limit=10)
|
10
|
+
limit = limit.to_i
|
11
|
+
|
12
|
+
shuffleOptions = {
|
13
|
+
folder_limit: limit,
|
14
|
+
base_path: options[:path] ? options[:path] : Dir.pwd
|
15
|
+
}
|
16
|
+
|
17
|
+
shuffler = AlbumShuffle.new(shuffleOptions)
|
18
|
+
|
19
|
+
shuffler.shuffle.each do |dir|
|
20
|
+
puts dir
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
ShuffleExec.start(ARGV)
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'album_shuffle/version'
|
2
|
+
require 'find'
|
3
|
+
|
4
|
+
class AlbumShuffle
|
5
|
+
|
6
|
+
def initialize( options = {} )
|
7
|
+
options( options )
|
8
|
+
end
|
9
|
+
|
10
|
+
# Returns options after overriding existing or setting defaults
|
11
|
+
def options( options = {} )
|
12
|
+
|
13
|
+
if @options
|
14
|
+
# If called when options exist, override pass options
|
15
|
+
@options = @options.merge( options )
|
16
|
+
else
|
17
|
+
# Default options
|
18
|
+
@options = {
|
19
|
+
base_path: Dir.pwd,
|
20
|
+
folder_limit: 0,
|
21
|
+
}.merge( options )
|
22
|
+
end
|
23
|
+
|
24
|
+
@options
|
25
|
+
end
|
26
|
+
|
27
|
+
def collect
|
28
|
+
song_dirs = []
|
29
|
+
|
30
|
+
# Finds all directories that contain mp3 files
|
31
|
+
Find.find( @options[:base_path] ) do | path |
|
32
|
+
yield(path) if block_given?
|
33
|
+
# Find.prune if @options[:folder_limit] && song_dirs.length >= options[:folder_limit]
|
34
|
+
if ( File.basename( path ) =~ /.mp3$/ ) != nil
|
35
|
+
dirname = File.dirname( path )
|
36
|
+
song_dirs << dirname unless song_dirs.include?( dirname )
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
song_dirs
|
41
|
+
end
|
42
|
+
|
43
|
+
def shuffle
|
44
|
+
all_dirs = collect {|path| yield(path) if block_given? }
|
45
|
+
limit = @options[:folder_limit]
|
46
|
+
random_dirs = []
|
47
|
+
|
48
|
+
if( limit > 0 )
|
49
|
+
random_dirs = all_dirs.sample(limit)
|
50
|
+
end
|
51
|
+
|
52
|
+
random_dirs
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'album_shuffle'
|
3
|
+
require 'fakefs/spec_helpers'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
describe AlbumShuffle do
|
7
|
+
|
8
|
+
# This helper allows FakeFS to persist through all tests
|
9
|
+
include FakeFS::SpecHelpers::All
|
10
|
+
|
11
|
+
# Generate a fake file structure
|
12
|
+
before :all do
|
13
|
+
(1..4).each do |artist_n|
|
14
|
+
(1..2).each do |album_n|
|
15
|
+
(1..2).each do |disc_n|
|
16
|
+
path = "My Music/Some Artist #{artist_n}/2002 - Some Album #{album_n}/Disc #{disc_n}"
|
17
|
+
FileUtils.mkdir_p path
|
18
|
+
(1..7).each do |song_n|
|
19
|
+
FileUtils.touch path + "/#{song_n} - Song.mp3"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
before :each do
|
27
|
+
@album_shuffle = AlbumShuffle.new
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#options' do
|
31
|
+
it "sets options" do
|
32
|
+
options = @album_shuffle.options(:some_option => 'x')
|
33
|
+
options[:some_option].should eq 'x'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#collect' do
|
38
|
+
it "returns some directories" do
|
39
|
+
folders = @album_shuffle.collect
|
40
|
+
folders.should be_an Array
|
41
|
+
folders.grep(/Some Album/).length.should be > 2
|
42
|
+
end
|
43
|
+
|
44
|
+
it "only collects folders with music" do
|
45
|
+
folders = @album_shuffle.collect
|
46
|
+
folders.sample(2).each do |folder|
|
47
|
+
Dir[ File.join( folder, '*.mp3' ) ].length.should be > 0
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#shuffle' do
|
53
|
+
it "outputs specifc number of folders" do
|
54
|
+
@album_shuffle.options(:folder_limit => 5)
|
55
|
+
folders = @album_shuffle.shuffle
|
56
|
+
folders.length.should eq 5
|
57
|
+
|
58
|
+
@album_shuffle.options(:folder_limit => 10)
|
59
|
+
folders = @album_shuffle.shuffle
|
60
|
+
folders.length.should eq 10
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
RSpec.configure do |config|
|
3
|
+
# config.treat_symbols_as_metadata_keys_with_true_values = true
|
4
|
+
# config.run_all_when_everything_filtered = true
|
5
|
+
# config.filter_run :focus
|
6
|
+
|
7
|
+
# Run specs in random order to surface order dependencies. If you find an
|
8
|
+
# order dependency and want to debug it, you can fix the order by providing
|
9
|
+
# the seed, which is printed after each run.
|
10
|
+
# --seed 1234
|
11
|
+
# config.order = 'random'
|
12
|
+
|
13
|
+
# config.formatter = :d
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: album_shuffle
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dan Schuman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-07-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: thor
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Outputs a list of shuffled music directories. Assumes your music is already
|
70
|
+
organized in a directory-per-album structure.
|
71
|
+
email:
|
72
|
+
- danschuman@gmail.com
|
73
|
+
executables:
|
74
|
+
- album_shuffle
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- .gitignore
|
79
|
+
- .rspec
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- album_shuffle.gemspec
|
85
|
+
- bin/album_shuffle
|
86
|
+
- lib/album_shuffle.rb
|
87
|
+
- lib/album_shuffle/version.rb
|
88
|
+
- spec/album_shuffle_spec.rb
|
89
|
+
- spec/spec_helper.rb
|
90
|
+
homepage: ''
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ! '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.0.3
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: Command line tool to list random music directories
|
114
|
+
test_files:
|
115
|
+
- spec/album_shuffle_spec.rb
|
116
|
+
- spec/spec_helper.rb
|