nehm 1.5.6.2 → 1.6.1
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.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/CHANGELOG.md +8 -0
- data/README.md +6 -7
- data/bin/nehm +6 -1
- data/lib/nehm.rb +31 -48
- data/lib/nehm/applescript.rb +7 -2
- data/lib/nehm/artwork.rb +6 -6
- data/lib/nehm/cfg.rb +5 -1
- data/lib/nehm/client.rb +78 -6
- data/lib/nehm/command.rb +123 -0
- data/lib/nehm/command_manager.rb +66 -0
- data/lib/nehm/commands/configure_command.rb +44 -0
- data/lib/nehm/commands/dl_command.rb +41 -0
- data/lib/nehm/commands/get_command.rb +44 -0
- data/lib/nehm/commands/help_command.rb +85 -0
- data/lib/nehm/commands/version_command.rb +23 -0
- data/lib/nehm/option_parser.rb +31 -0
- data/lib/nehm/os.rb +5 -0
- data/lib/nehm/path_manager.rb +28 -31
- data/lib/nehm/playlist.rb +7 -1
- data/lib/nehm/playlist_manager.rb +31 -14
- data/lib/nehm/track.rb +23 -21
- data/lib/nehm/tracks.rb +153 -0
- data/lib/nehm/ui.rb +35 -0
- data/lib/nehm/user_manager.rb +19 -42
- data/lib/nehm/version.rb +1 -1
- data/nehm.gemspec +2 -2
- metadata +24 -18
- data/lib/nehm/configure.rb +0 -24
- data/lib/nehm/get.rb +0 -100
- data/lib/nehm/help.rb +0 -93
- data/lib/nehm/user.rb +0 -81
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'nehm/command'
|
2
|
+
|
3
|
+
module Nehm
|
4
|
+
|
5
|
+
##
|
6
|
+
# The command manager contains information about all nehm commands, find
|
7
|
+
# and run them
|
8
|
+
|
9
|
+
module CommandManager
|
10
|
+
|
11
|
+
COMMANDS = [
|
12
|
+
:configure,
|
13
|
+
:dl,
|
14
|
+
:get,
|
15
|
+
:help,
|
16
|
+
:version
|
17
|
+
]
|
18
|
+
|
19
|
+
##
|
20
|
+
# Run the command specified by 'args'.
|
21
|
+
|
22
|
+
def self.run(args)
|
23
|
+
if args.empty?
|
24
|
+
UI.say Nehm::Command::HELP
|
25
|
+
UI.term
|
26
|
+
end
|
27
|
+
|
28
|
+
cmd_name = args.shift.downcase
|
29
|
+
cmd = find_command(cmd_name)
|
30
|
+
cmd.invoke(args)
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.find_command(cmd_name)
|
34
|
+
possibilities = find_command_possibilities(cmd_name)
|
35
|
+
|
36
|
+
if possibilities.size > 1
|
37
|
+
UI.term "Ambiguous command #{cmd_name} matches [#{possibilities.join(', ')}]"
|
38
|
+
elsif possibilities.empty?
|
39
|
+
UI.term "Unknown command #{cmd_name}"
|
40
|
+
end
|
41
|
+
|
42
|
+
command_instance(possibilities.first)
|
43
|
+
end
|
44
|
+
|
45
|
+
module_function
|
46
|
+
|
47
|
+
def find_command_possibilities(cmd_name)
|
48
|
+
len = cmd_name.length
|
49
|
+
COMMANDS.select { |command| command[0, len] == cmd_name }
|
50
|
+
end
|
51
|
+
|
52
|
+
def command_instance(command_name)
|
53
|
+
command_name = command_name.to_s
|
54
|
+
const_name = command_name.capitalize << 'Command'
|
55
|
+
|
56
|
+
require_commands
|
57
|
+
Nehm.const_get(const_name).new
|
58
|
+
end
|
59
|
+
|
60
|
+
def require_commands
|
61
|
+
project_root = File.dirname(File.absolute_path(__FILE__))
|
62
|
+
Dir.glob(project_root + '/commands/*') { |file| require file }
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Nehm
|
2
|
+
class ConfigureCommand < Command
|
3
|
+
|
4
|
+
def execute
|
5
|
+
loop do
|
6
|
+
UI.say "Download path: #{Cfg[:dl_path].magenta}" if Cfg[:dl_path]
|
7
|
+
UI.say "Permalink: #{Cfg[:permalink].cyan}" if Cfg[:permalink]
|
8
|
+
UI.say "iTunes playlist: #{PlaylistManager.default_playlist.to_s.cyan}" if !OS.linux? && PlaylistManager.default_playlist
|
9
|
+
UI.newline
|
10
|
+
|
11
|
+
show_menu
|
12
|
+
|
13
|
+
sleep(1)
|
14
|
+
UI.newline
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def program_name
|
19
|
+
'nehm configure'
|
20
|
+
end
|
21
|
+
|
22
|
+
def summary
|
23
|
+
'Configure nehm app'
|
24
|
+
end
|
25
|
+
|
26
|
+
def usage
|
27
|
+
'nehm configure'
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def show_menu
|
33
|
+
HighLine.new.choose do |menu|
|
34
|
+
menu.prompt = 'Choose setting'.yellow
|
35
|
+
|
36
|
+
menu.choice('Edit download path'.freeze) { PathManager.set_dl_path }
|
37
|
+
menu.choice('Edit permalink'.freeze) { UserManager.set_uid }
|
38
|
+
menu.choice('Edit iTunes playlist'.freeze) { PlaylistManager.set_playlist } unless OS.linux?
|
39
|
+
menu.choice('Exit'.freeze) { fail Interrupt }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'nehm/tracks'
|
2
|
+
|
3
|
+
module Nehm
|
4
|
+
class DlCommand < Command
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
super
|
8
|
+
|
9
|
+
add_option(:from, 'from PERMALINK'.green,
|
10
|
+
'Get track(s) from user with PERMALINK')
|
11
|
+
|
12
|
+
add_option(:to, 'to PATH'.green,
|
13
|
+
'Download track(s) to PATH')
|
14
|
+
end
|
15
|
+
|
16
|
+
def execute
|
17
|
+
Tracks[:dl, @options]
|
18
|
+
end
|
19
|
+
|
20
|
+
def arguments
|
21
|
+
{ "#{'post'.green}" => 'Download last post (track or repost) from your profile',
|
22
|
+
"#{'<number> posts'.green}" => 'Download last <number> posts from your profile',
|
23
|
+
"#{'like'.green}" => 'Download your last like',
|
24
|
+
"#{'<number> likes'.green}" => 'Download your last <number> likes',
|
25
|
+
"#{'URL'.magenta}" => 'Download track from entered URL' }
|
26
|
+
end
|
27
|
+
|
28
|
+
def program_name
|
29
|
+
'nehm dl'
|
30
|
+
end
|
31
|
+
|
32
|
+
def summary
|
33
|
+
'Download and set tags any track from Soundcloud'
|
34
|
+
end
|
35
|
+
|
36
|
+
def usage
|
37
|
+
"#{program_name} ARGUMENT [OPTIONS]"
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'nehm/tracks'
|
2
|
+
|
3
|
+
module Nehm
|
4
|
+
class GetCommand < Command
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
super
|
8
|
+
|
9
|
+
add_option(:from, 'from PERMALINK'.green,
|
10
|
+
'Get track(s) from user with PERMALINK')
|
11
|
+
|
12
|
+
add_option(:to, 'to PATH'.green,
|
13
|
+
'Download track(s) to PATH')
|
14
|
+
|
15
|
+
add_option(:playlist, 'playlist PLAYLIST'.green,
|
16
|
+
'Add track(s) to iTunes playlist with PLAYLIST name')
|
17
|
+
end
|
18
|
+
|
19
|
+
def execute
|
20
|
+
Tracks[:get, @options]
|
21
|
+
end
|
22
|
+
|
23
|
+
def arguments
|
24
|
+
{ "#{'post'.green}" => 'Get last post (track or repost) from your profile',
|
25
|
+
"#{'<number> posts'.green}" => 'Get last <number> posts from your profile',
|
26
|
+
"#{'like'.green}" => 'Get your last like',
|
27
|
+
"#{'<number> likes'.green}" => 'Get your last <number> likes',
|
28
|
+
"#{'URL'.magenta}" => 'Get track from entered URL' }
|
29
|
+
end
|
30
|
+
|
31
|
+
def program_name
|
32
|
+
'nehm get'
|
33
|
+
end
|
34
|
+
|
35
|
+
def summary
|
36
|
+
'Download tracks, set tags and add to your iTunes library tracks from Soundcloud'
|
37
|
+
end
|
38
|
+
|
39
|
+
def usage
|
40
|
+
"#{program_name} ARGUMENT [OPTIONS]"
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module Nehm
|
2
|
+
class HelpCommand < Command
|
3
|
+
|
4
|
+
SPACES_BTW_NAME_AND_DESC = 5
|
5
|
+
|
6
|
+
def execute
|
7
|
+
command_name = options[:args].pop
|
8
|
+
if command_name.nil?
|
9
|
+
UI.say Nehm::Command::HELP
|
10
|
+
UI.term
|
11
|
+
end
|
12
|
+
|
13
|
+
@cmd = CommandManager.find_command(command_name)
|
14
|
+
|
15
|
+
show_usage
|
16
|
+
show_summary
|
17
|
+
show_arguments unless @cmd.arguments.empty?
|
18
|
+
show_options unless @cmd.options.empty?
|
19
|
+
end
|
20
|
+
|
21
|
+
def arguments
|
22
|
+
{ 'COMMAND'.magenta => 'name of command to show help' }
|
23
|
+
end
|
24
|
+
|
25
|
+
def program_name
|
26
|
+
'nehm help'
|
27
|
+
end
|
28
|
+
|
29
|
+
def summary
|
30
|
+
'Show help for specified command'
|
31
|
+
end
|
32
|
+
|
33
|
+
def usage
|
34
|
+
"#{program_name} COMMAND"
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def find_longest_name(names)
|
40
|
+
names.inject do |longest, word|
|
41
|
+
word.length > longest.length ? word : longest
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def show_usage
|
46
|
+
UI.say "#{'Usage:'.yellow} #{@cmd.usage}"
|
47
|
+
end
|
48
|
+
|
49
|
+
def show_summary
|
50
|
+
UI.newline
|
51
|
+
UI.say "#{'Summary:'.yellow}"
|
52
|
+
UI.say " #{@cmd.summary}"
|
53
|
+
end
|
54
|
+
|
55
|
+
def show_arguments
|
56
|
+
UI.newline
|
57
|
+
UI.say "#{'Arguments:'.yellow}"
|
58
|
+
show_info(@cmd.arguments)
|
59
|
+
end
|
60
|
+
|
61
|
+
def show_options
|
62
|
+
UI.newline
|
63
|
+
UI.say "#{'Options:'.yellow}"
|
64
|
+
show_info(@cmd.options_descs)
|
65
|
+
end
|
66
|
+
|
67
|
+
def show_info(hash)
|
68
|
+
@longest ||= nil
|
69
|
+
|
70
|
+
unless @longest
|
71
|
+
names = []
|
72
|
+
names += @cmd.arguments.keys unless @cmd.arguments.empty?
|
73
|
+
names += @cmd.options.keys unless @cmd.options.empty?
|
74
|
+
@longest ||= find_longest_name(names).length
|
75
|
+
end
|
76
|
+
|
77
|
+
hash.each do |name, desc|
|
78
|
+
need_spaces = @longest - name.length
|
79
|
+
|
80
|
+
UI.say " #{name}#{' ' * (need_spaces + SPACES_BTW_NAME_AND_DESC)}#{desc}"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'nehm/version'
|
2
|
+
|
3
|
+
module Nehm
|
4
|
+
class VersionCommand < Command
|
5
|
+
|
6
|
+
def execute
|
7
|
+
UI.say VERSION
|
8
|
+
end
|
9
|
+
|
10
|
+
def program_name
|
11
|
+
'nehm version'
|
12
|
+
end
|
13
|
+
|
14
|
+
def summary
|
15
|
+
"Show nehm's verion"
|
16
|
+
end
|
17
|
+
|
18
|
+
def usage
|
19
|
+
program_name
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Nehm
|
2
|
+
|
3
|
+
##
|
4
|
+
# OptionParser parses options and add hash with options to specified command
|
5
|
+
|
6
|
+
# TODO: make abbrebiated options
|
7
|
+
|
8
|
+
class OptionParser
|
9
|
+
|
10
|
+
def initialize(args, command)
|
11
|
+
@args = args
|
12
|
+
@command = command
|
13
|
+
end
|
14
|
+
|
15
|
+
def parse
|
16
|
+
options = @command.options.keys.map(&:to_s)
|
17
|
+
options.each do |option|
|
18
|
+
if @args.include? option
|
19
|
+
index = @args.index(option)
|
20
|
+
value = @args[index + 1]
|
21
|
+
@args.delete_at(index + 1)
|
22
|
+
@args.delete_at(index)
|
23
|
+
|
24
|
+
@command.options[option.to_sym] = value
|
25
|
+
end
|
26
|
+
end
|
27
|
+
@command.options[:args] = @args
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
data/lib/nehm/os.rb
CHANGED
data/lib/nehm/path_manager.rb
CHANGED
@@ -1,16 +1,37 @@
|
|
1
1
|
module Nehm
|
2
|
+
|
3
|
+
##
|
4
|
+
# Path manager works with download pathes
|
5
|
+
|
2
6
|
module PathManager
|
3
|
-
|
4
|
-
|
7
|
+
|
8
|
+
##
|
9
|
+
# Returns default download path (contains in ~/.nehmconfig)
|
10
|
+
|
11
|
+
def self.default_dl_path
|
12
|
+
Cfg[:dl_path]
|
13
|
+
end
|
14
|
+
|
15
|
+
##
|
16
|
+
# Checks path for validation and returns it if valid
|
17
|
+
|
18
|
+
def self.get_path(path)
|
19
|
+
# If path begins with ~
|
20
|
+
path = tilde_to_home(path) if tilde_at_top?(path)
|
21
|
+
|
22
|
+
# Check path for existence
|
23
|
+
UI.term 'Invalid download path! Please enter correct path' unless Dir.exist?(path)
|
24
|
+
|
25
|
+
path
|
5
26
|
end
|
6
27
|
|
7
28
|
def self.set_dl_path
|
8
29
|
loop do
|
9
|
-
default_path = File.join(ENV['HOME'], '/Music')
|
10
30
|
ask_sentence = 'Enter path to desirable download directory'
|
31
|
+
default_path = File.join(ENV['HOME'], '/Music')
|
11
32
|
|
12
33
|
if Dir.exist?(default_path)
|
13
|
-
ask_sentence << " (press enter to set it to #{
|
34
|
+
ask_sentence << " (press enter to set it to #{default_path.magenta})"
|
14
35
|
else
|
15
36
|
default_path = nil
|
16
37
|
end
|
@@ -25,41 +46,16 @@ module Nehm
|
|
25
46
|
|
26
47
|
if Dir.exist?(path)
|
27
48
|
Cfg[:dl_path] = path
|
28
|
-
|
49
|
+
UI.say "#{'Download directory set up to'.green} #{path.magenta}"
|
29
50
|
break
|
30
51
|
else
|
31
|
-
|
52
|
+
UI.error "This directory doesn't exist. Please enter correct path"
|
32
53
|
end
|
33
54
|
end
|
34
55
|
end
|
35
56
|
|
36
|
-
def self.temp_dl_path=(path)
|
37
|
-
# If 'to ~/../..' entered
|
38
|
-
path = tilde_to_home(path) if tilde_at_top?(path)
|
39
|
-
|
40
|
-
# If 'to current' entered
|
41
|
-
path = Dir.pwd if path == 'current'
|
42
|
-
|
43
|
-
if Dir.exist?(path)
|
44
|
-
@temp_dl_path = path
|
45
|
-
else
|
46
|
-
puts Paint['Invalid download path! Please enter correct path', :red]
|
47
|
-
exit
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
57
|
module_function
|
52
58
|
|
53
|
-
def default_dl_path
|
54
|
-
if Cfg[:dl_path]
|
55
|
-
Cfg[:dl_path]
|
56
|
-
else
|
57
|
-
puts Paint["You don't set up download path!", :red]
|
58
|
-
puts "Set it up from #{Paint['nehm configure', :yellow]} or use #{Paint['[to PATH_TO_DIRECTORY]', :yellow]} option"
|
59
|
-
exit
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
59
|
def tilde_at_top?(path)
|
64
60
|
path[0] == '~'
|
65
61
|
end
|
@@ -67,5 +63,6 @@ module Nehm
|
|
67
63
|
def tilde_to_home(path)
|
68
64
|
File.join(ENV['HOME'], path[1..-1])
|
69
65
|
end
|
66
|
+
|
70
67
|
end
|
71
68
|
end
|
data/lib/nehm/playlist.rb
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
module Nehm
|
2
|
+
|
3
|
+
##
|
4
|
+
# iTunes playlist primitive
|
5
|
+
|
2
6
|
class Playlist
|
7
|
+
|
3
8
|
attr_reader :name
|
4
9
|
|
5
10
|
def initialize(name)
|
@@ -7,12 +12,13 @@ module Nehm
|
|
7
12
|
end
|
8
13
|
|
9
14
|
def add_track(track_path)
|
10
|
-
|
15
|
+
UI.say 'Adding to iTunes'
|
11
16
|
AppleScript.add_track_to_playlist(track_path, @name)
|
12
17
|
end
|
13
18
|
|
14
19
|
def to_s
|
15
20
|
@name
|
16
21
|
end
|
22
|
+
|
17
23
|
end
|
18
24
|
end
|