nehm 1.1 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -1
- data/README.md +11 -7
- data/lib/nehm.rb +25 -20
- data/lib/nehm/artwork.rb +14 -9
- data/lib/nehm/client.rb +8 -2
- data/lib/nehm/config.rb +3 -10
- data/lib/nehm/configure.rb +3 -10
- data/lib/nehm/{track_utils.rb → get.rb} +28 -35
- data/lib/nehm/help.rb +17 -17
- data/lib/nehm/os.rb +1 -2
- data/lib/nehm/path_control.rb +36 -11
- data/lib/nehm/track.rb +10 -10
- data/lib/nehm/user.rb +5 -19
- data/lib/nehm/user_control.rb +29 -22
- data/lib/nehm/version.rb +1 -1
- data/nehm.gemspec +12 -12
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5768d05298cc87c8d0cc0a0321ceda2a02da9062
|
4
|
+
data.tar.gz: 88c398ca600814eb8f808e0426a12989043f933f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca4ec26cc69d3beac67d282757bdda36119ea41cce5b2fd5a0e515fe1b502168ead270a3104a6fba3aa43d6f980fd3b8b49fc0ce52460a0e31bcdcf7e352f657
|
7
|
+
data.tar.gz: 248c24c28a67b8abdbff1de3d41329fb53fb7fa9b5290b91a14d36a8cbd0756feac804848018a9fe01e8fce899aa81ea928bc60cd9ae8f59e9d40aa37c9626f1
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,14 @@
|
|
1
1
|
# nehm change log
|
2
2
|
|
3
|
+
## 1.2
|
4
|
+
|
5
|
+
* Add 'to PARHTODIRECTORY' feature. See the 'Usage' for instructions
|
6
|
+
* Improve readability of help
|
7
|
+
* Add some error checks
|
8
|
+
|
3
9
|
## 1.1
|
4
10
|
|
5
|
-
* Add 'from PERMALINK' feature
|
11
|
+
* Add 'from PERMALINK' feature. See the 'Usage' for instructions
|
6
12
|
|
7
13
|
## 1.0.7.1
|
8
14
|
|
data/README.md
CHANGED
@@ -14,7 +14,7 @@ or
|
|
14
14
|
|
15
15
|
`sudo port install taglib`
|
16
16
|
|
17
|
-
**Linux
|
17
|
+
**Linux:**
|
18
18
|
|
19
19
|
Debian/Ubuntu: ` sudo apt-get install libtag1-dev`
|
20
20
|
|
@@ -28,9 +28,9 @@ Fedora/RHEL: ` sudo yum install taglib-devel`
|
|
28
28
|
|
29
29
|
## First usage
|
30
30
|
|
31
|
-
If you just installed nehm,
|
31
|
+
If you just installed nehm, write any command for its setup
|
32
32
|
|
33
|
-
|
33
|
+
For example, `nehm help`
|
34
34
|
|
35
35
|
nehm should answer like this:
|
36
36
|
```
|
@@ -58,14 +58,18 @@ Go to usage for further instructions
|
|
58
58
|
|
59
59
|
`nehm get 3 posts` or `nehm get 3 likes`
|
60
60
|
|
61
|
-
* To get last post(s) or like(s) from another user
|
62
|
-
|
63
|
-
`nehm get post from nasa` or `nehm get like from nasa`
|
64
|
-
|
65
61
|
* To just download and set tags any track, you can input
|
66
62
|
|
67
63
|
`nehm dl post` or `nehm dl like` or `nehm dl 3 likes` and etc.
|
68
64
|
|
65
|
+
* To get tracks from another user
|
66
|
+
|
67
|
+
`nehm get post from nasa` or `nehm dl like from bogem`
|
68
|
+
|
69
|
+
* To download tracks to custom directory
|
70
|
+
|
71
|
+
`nehm dl like to /Users/john/Music` or `nehm get post from nasa to ~/Downloads`
|
72
|
+
|
69
73
|
* And of course you can get or download track from url
|
70
74
|
|
71
75
|
`nehm get https://soundcloud.com/nasa/delta-iv-launch`
|
data/lib/nehm.rb
CHANGED
@@ -1,29 +1,30 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
require 'highline'
|
2
|
+
require 'paint'
|
3
|
+
|
4
|
+
require 'nehm/artwork'
|
5
|
+
require 'nehm/config'
|
6
|
+
require 'nehm/configure'
|
7
|
+
require 'nehm/client'
|
8
|
+
require 'nehm/get'
|
9
|
+
require 'nehm/help'
|
10
|
+
require 'nehm/os'
|
11
|
+
require 'nehm/path_control'
|
12
|
+
require 'nehm/track'
|
13
|
+
require 'nehm/user'
|
14
|
+
require 'nehm/user_control'
|
11
15
|
|
16
|
+
module App
|
12
17
|
def self.do(args)
|
13
18
|
init unless initialized?
|
14
19
|
|
15
20
|
command = args.shift
|
16
21
|
case command
|
17
22
|
when 'get'
|
18
|
-
|
23
|
+
Get[:get, args]
|
19
24
|
when 'dl'
|
20
|
-
|
25
|
+
Get[:dl, args]
|
21
26
|
when 'configure'
|
22
27
|
Configure.menu
|
23
|
-
when 'login'
|
24
|
-
UserControl.log_in
|
25
|
-
when 'init'
|
26
|
-
init
|
27
28
|
when 'help'
|
28
29
|
Help.show(args.first)
|
29
30
|
else
|
@@ -32,19 +33,23 @@ module App
|
|
32
33
|
end
|
33
34
|
end
|
34
35
|
|
35
|
-
# Private
|
36
|
-
|
37
36
|
module_function
|
38
37
|
|
39
38
|
def init
|
40
39
|
puts Paint['Hello!', :green]
|
41
40
|
puts 'Before using the nehm, you should set it up:'
|
42
41
|
Config.create unless Config.exist?
|
42
|
+
|
43
43
|
PathControl.set_dl_path
|
44
44
|
puts "\n"
|
45
|
-
|
46
|
-
|
45
|
+
|
46
|
+
unless OS.linux?
|
47
|
+
PathControl.set_itunes_path
|
48
|
+
puts "\n"
|
49
|
+
end
|
50
|
+
|
47
51
|
UserControl.log_in
|
52
|
+
|
48
53
|
puts Paint['Now you can use nehm :)', :green]
|
49
54
|
end
|
50
55
|
|
data/lib/nehm/artwork.rb
CHANGED
@@ -5,21 +5,26 @@ class Artwork
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def file_path
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
File.join('/tmp', "#{@track.id}.jpg")
|
9
|
+
end
|
10
|
+
|
11
|
+
# Use in Get.dl
|
12
|
+
def name
|
13
|
+
'artwork'
|
11
14
|
end
|
12
15
|
|
13
16
|
def suicide
|
14
17
|
File.delete(file_path)
|
15
18
|
end
|
16
19
|
|
17
|
-
def
|
20
|
+
def url
|
18
21
|
hash = @track.hash
|
19
|
-
|
20
|
-
hash['
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
url =
|
23
|
+
if hash['artwork_url'].nil?
|
24
|
+
hash['user']['avatar_url']
|
25
|
+
else
|
26
|
+
hash['artwork_url']
|
27
|
+
end
|
28
|
+
url.sub('large', 't500x500')
|
24
29
|
end
|
25
30
|
end
|
data/lib/nehm/client.rb
CHANGED
@@ -1,14 +1,20 @@
|
|
1
1
|
require 'soundcloud'
|
2
|
-
require_relative 'config.rb'
|
3
2
|
|
4
3
|
# Just a Soundcloud API client.
|
5
4
|
module Client
|
6
5
|
# Set a SSL certificate file path for SC API
|
7
6
|
ENV['SSL_CERT_FILE'] = File.join(__dir__, 'cacert.pem')
|
8
7
|
|
8
|
+
# SoundCloud API client ID
|
9
9
|
CLIENT_ID = '11a37feb6ccc034d5975f3f803928a32'
|
10
10
|
|
11
|
-
def self.
|
11
|
+
def self.get(*args)
|
12
|
+
sc_client.get(*args)
|
13
|
+
end
|
14
|
+
|
15
|
+
module_function
|
16
|
+
|
17
|
+
def sc_client
|
12
18
|
@client ||= Soundcloud.new(client_id: CLIENT_ID)
|
13
19
|
end
|
14
20
|
end
|
data/lib/nehm/config.rb
CHANGED
@@ -2,9 +2,6 @@ require 'yaml'
|
|
2
2
|
|
3
3
|
# Config module manipulate with nehm's config file (~/.nehmconfig)
|
4
4
|
module Config
|
5
|
-
|
6
|
-
# Public
|
7
|
-
|
8
5
|
def self.[](key)
|
9
6
|
config_hash = load_config
|
10
7
|
config_hash[key.to_s]
|
@@ -17,7 +14,7 @@ module Config
|
|
17
14
|
end
|
18
15
|
|
19
16
|
def self.create
|
20
|
-
File.open(file_path, 'w+') { |f| f.write("---\napp: nehm")}
|
17
|
+
File.open(file_path, 'w+') { |f| f.write("---\napp: nehm") }
|
21
18
|
end
|
22
19
|
|
23
20
|
def self.exist?
|
@@ -28,8 +25,6 @@ module Config
|
|
28
25
|
load_config.key?(key.to_s)
|
29
26
|
end
|
30
27
|
|
31
|
-
# Private
|
32
|
-
|
33
28
|
module_function
|
34
29
|
|
35
30
|
def file_path
|
@@ -37,12 +32,10 @@ module Config
|
|
37
32
|
end
|
38
33
|
|
39
34
|
def load_config
|
40
|
-
|
41
|
-
YAML.load_file(file)
|
35
|
+
YAML.load_file(file_path)
|
42
36
|
end
|
43
37
|
|
44
38
|
def save_config(config_hash)
|
45
|
-
|
46
|
-
IO.write(file, config_hash.to_yaml)
|
39
|
+
IO.write(file_path, config_hash.to_yaml)
|
47
40
|
end
|
48
41
|
end
|
data/lib/nehm/configure.rb
CHANGED
@@ -1,16 +1,9 @@
|
|
1
|
-
require 'highline'
|
2
|
-
require 'paint'
|
3
|
-
require_relative 'user_control.rb'
|
4
|
-
require_relative 'os.rb'
|
5
|
-
require_relative 'config.rb'
|
6
|
-
require_relative 'path_control.rb'
|
7
|
-
|
8
1
|
# Configure module responds to 'nehm configure' command
|
9
2
|
module Configure
|
10
3
|
def self.menu
|
11
|
-
puts 'Download path: ' + Paint[PathControl.dl_path, :magenta]
|
12
|
-
puts 'iTunes path: ' + Paint[PathControl.
|
13
|
-
puts 'Permalink: ' + Paint[Config[:permalink], :cyan]
|
4
|
+
puts 'Download path: ' + Paint[PathControl.dl_path, :magenta] if PathControl.dl_path
|
5
|
+
puts 'iTunes path: ' + Paint[PathControl.itunes_path_name, :magenta] if PathControl.itunes_path
|
6
|
+
puts 'Permalink: ' + Paint[Config[:permalink], :cyan] if Config[:permalink]
|
14
7
|
puts "\n"
|
15
8
|
|
16
9
|
HighLine.new.choose do |menu|
|
@@ -1,31 +1,35 @@
|
|
1
1
|
require 'taglib'
|
2
2
|
require 'fileutils'
|
3
|
-
require 'paint'
|
4
|
-
require_relative 'path_control.rb'
|
5
|
-
require_relative 'client.rb'
|
6
|
-
require_relative 'user.rb'
|
7
|
-
require_relative 'track.rb'
|
8
|
-
require_relative 'os.rb'
|
9
3
|
|
10
4
|
# TrackUtils module responds to 'nehm get/dl ...' commands
|
11
|
-
module
|
12
|
-
|
13
|
-
# Public
|
14
|
-
|
15
|
-
def self.get(dl, args)
|
5
|
+
module Get
|
6
|
+
def self.[](get_or_dl, args)
|
16
7
|
user =
|
17
|
-
# If option 'from ...'
|
8
|
+
# If option 'from ...' typed
|
18
9
|
if args.include? 'from'
|
19
10
|
index = args.index('from')
|
20
|
-
|
11
|
+
permalink = args[index + 1]
|
21
12
|
|
22
13
|
args.delete_at(index + 1)
|
23
14
|
args.delete_at(index)
|
24
|
-
|
15
|
+
UserControl.user(permalink)
|
25
16
|
else
|
26
|
-
|
17
|
+
UserControl.default_user
|
27
18
|
end
|
28
19
|
|
20
|
+
# If option 'to ...' typed
|
21
|
+
if args.include? 'to'
|
22
|
+
index = args.index('to')
|
23
|
+
path = args[index + 1]
|
24
|
+
|
25
|
+
path = File.join(ENV['HOME'], path[1..-1]) if path[0] == '~'
|
26
|
+
|
27
|
+
PathControl.temp_dl_path = path
|
28
|
+
|
29
|
+
args.delete_at(index + 1)
|
30
|
+
args.delete_at(index)
|
31
|
+
end
|
32
|
+
|
29
33
|
tracks = []
|
30
34
|
tracks +=
|
31
35
|
case args.last
|
@@ -54,37 +58,26 @@ module TrackUtils
|
|
54
58
|
|
55
59
|
tracks.each do |track|
|
56
60
|
dl(track)
|
61
|
+
dl(track.artwork)
|
57
62
|
tag(track)
|
58
|
-
cp(track) unless (
|
63
|
+
cp(track) unless (get_or_dl == :dl) || (OS.linux?)
|
59
64
|
track.artwork.suicide
|
60
65
|
end
|
61
66
|
puts Paint['Done!', :green]
|
62
67
|
end
|
63
68
|
|
64
|
-
# Private
|
65
|
-
|
66
69
|
module_function
|
67
70
|
|
68
71
|
def track_from_url(url)
|
69
|
-
|
70
|
-
|
71
|
-
tracks = []
|
72
|
-
tracks << Track.new(track)
|
72
|
+
hash = Client.get('/resolve', url: url)
|
73
|
+
[*Track.new(hash)]
|
73
74
|
end
|
74
75
|
|
75
|
-
def dl(
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
command = "curl -# -o '" + path + "' -L " + dl_url
|
81
|
-
system(command)
|
82
|
-
|
83
|
-
puts 'Downloading artwork'
|
84
|
-
artwork = track.artwork
|
85
|
-
path = artwork.file_path
|
86
|
-
dl_url = artwork.dl_url
|
87
|
-
command = "curl -# -o '" + path + "' -L " + dl_url
|
76
|
+
def dl(arg)
|
77
|
+
puts 'Downloading ' + arg.name
|
78
|
+
path = arg.file_path
|
79
|
+
url = arg.url
|
80
|
+
command = "curl -# -o '" + path + "' -L " + url
|
88
81
|
system(command)
|
89
82
|
end
|
90
83
|
|
data/lib/nehm/help.rb
CHANGED
@@ -1,65 +1,65 @@
|
|
1
1
|
# Help module responds to 'nehm help ...' command
|
2
2
|
module Help
|
3
|
-
|
4
|
-
# Public
|
5
|
-
|
6
3
|
def self.available_commands
|
7
4
|
puts Paint['Avalaible nehm commands:', :yellow]
|
8
5
|
puts ' ' + Paint['get', :green] + ' - Downloading, setting tags and adding to your iTunes library last post or like from your profile'
|
9
6
|
puts ' ' + Paint['dl', :green] + ' - Downloading and setting tags last post or like from your profile'
|
10
7
|
puts ' ' + Paint['configure', :green] + ' - Configuring application'
|
11
|
-
puts "See #{Paint['nehm help [command]']} to read about a specific subcommand"
|
8
|
+
puts "See #{Paint['nehm help [command]', :yellow]} to read about a specific subcommand"
|
12
9
|
end
|
13
10
|
|
14
11
|
def self.show(command)
|
15
12
|
case command
|
16
13
|
when 'get', 'dl', 'configure'
|
17
14
|
Help.send(command)
|
15
|
+
when nil
|
16
|
+
Help.available_commands
|
18
17
|
else
|
18
|
+
puts Paint["Command #{command} doesn't exist", :red]
|
19
|
+
puts "\n"
|
19
20
|
Help.available_commands
|
20
21
|
end
|
21
22
|
end
|
22
23
|
|
23
|
-
# Private
|
24
|
-
|
25
24
|
module_function
|
26
25
|
|
27
26
|
def configure
|
28
27
|
puts Paint['Input: ', :yellow] + 'nehm configure'
|
29
|
-
|
28
|
+
puts "\n"
|
30
29
|
puts Paint['Available options:', :yellow]
|
31
30
|
puts ' No options'
|
32
31
|
end
|
33
32
|
|
34
33
|
def dl
|
35
|
-
puts Paint['Input: ', :yellow] + 'nehm dl OPTIONS [from PERMALINK]'
|
36
|
-
|
34
|
+
puts Paint['Input: ', :yellow] + 'nehm dl OPTIONS [from PERMALINK] [to PATHTODIRECTORY]'
|
35
|
+
puts "\n"
|
37
36
|
puts Paint['OPTIONS:', :yellow]
|
38
37
|
puts ' ' + Paint['post', :green] + ' - Downloading and setting tags last post(track or repost) from your profile'
|
39
38
|
puts ' ' + Paint['<number> posts', :green] + ' - Downloading and setting tags last <number> posts from your profile'
|
40
39
|
puts ' ' + Paint['like', :green] + ' - Downloading and setting tags your last like'
|
41
40
|
puts ' ' + Paint['<number> likes', :green] + ' - Downloading and setting tags your last <number> likes'
|
42
|
-
|
41
|
+
puts "\n"
|
43
42
|
puts Paint['Extra options:', :yellow]
|
44
|
-
puts ' ' + Paint['from PERMALINK', :green]
|
43
|
+
puts ' ' + Paint['from PERMALINK', :green] + ' - Do the aforecited operations from the custom user profile'
|
44
|
+
puts ' ' + Paint['to PATHTODIRECTORY', :green] + ' - Do the aforecited operations to the custom directory'
|
45
45
|
end
|
46
46
|
|
47
47
|
def get
|
48
|
-
puts Paint['Input: ', :yellow] + 'nehm get OPTIONS [from PERMALINK]'
|
49
|
-
|
50
|
-
puts Paint['
|
48
|
+
puts Paint['Input: ', :yellow] + 'nehm get OPTIONS [from PERMALINK] [to PATHTODIRECTORY]'
|
49
|
+
puts "\n"
|
50
|
+
puts Paint['OPTIONS:', :yellow]
|
51
51
|
puts ' ' + Paint['post', :green] + ' - Downloading, setting tags and adding to your iTunes library last post(track or repost) from your profile'
|
52
52
|
puts ' ' + Paint['<number> posts', :green] + ' - Downloading, setting tags and adding to your iTunes library last <number> posts from your profile'
|
53
53
|
puts ' ' + Paint['like', :green] + ' - Downloading, setting tags and adding to your iTunes library your last like'
|
54
54
|
puts ' ' + Paint['<number> likes', :green] + ' - Downloading, setting tags and adding to your iTunes library your last <number> likes'
|
55
|
-
|
55
|
+
puts "\n"
|
56
56
|
puts Paint['Extra options:', :yellow]
|
57
|
-
puts ' ' + Paint['from PERMALINK', :green]
|
57
|
+
puts ' ' + Paint['from PERMALINK', :green] + ' - Do the aforecited operations from the profile with PERMALINK'
|
58
|
+
puts ' ' + Paint['to PATHTODIRECTORY', :green] + ' - Do the aforecited operations to the custom directory'
|
58
59
|
end
|
59
60
|
|
60
61
|
def permalink
|
61
62
|
puts 'Permalink is the last word in your profile url'
|
62
63
|
puts 'Example: for profile url ' + Paint['soundcloud.com/qwerty', :magenta] + ' permalink is ' + Paint['qwerty', :magenta]
|
63
64
|
end
|
64
|
-
|
65
65
|
end
|
data/lib/nehm/os.rb
CHANGED
data/lib/nehm/path_control.rb
CHANGED
@@ -1,36 +1,63 @@
|
|
1
|
-
|
2
|
-
require_relative 'config.rb'
|
3
|
-
module PathControl
|
1
|
+
class PathControl
|
4
2
|
def self.dl_path
|
5
|
-
Config[:dl_path]
|
3
|
+
@temp_dl_path ? @temp_dl_path : Config[:dl_path]
|
6
4
|
end
|
7
5
|
|
8
6
|
def self.set_dl_path
|
9
7
|
loop do
|
10
8
|
default_path = File.join(ENV['HOME'], '/Music')
|
11
|
-
|
12
|
-
|
9
|
+
path_ask = 'Enter a FULL path to default download directory'
|
10
|
+
|
11
|
+
if Dir.exist?(default_path)
|
12
|
+
path_ask << " (press enter to set it to #{Paint[default_path, :magenta]})"
|
13
|
+
else
|
14
|
+
default_path = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
path = HighLine.new.ask(path_ask + ':')
|
18
|
+
path = default_path if path == '' && default_path
|
13
19
|
|
14
20
|
if Dir.exist?(path)
|
15
21
|
Config[:dl_path] = path
|
16
22
|
puts Paint['Download directory set up!', :green]
|
17
23
|
break
|
18
24
|
else
|
19
|
-
puts "\n"
|
20
25
|
puts Paint["This directory doesn't exist. Please enter path again", :red]
|
21
26
|
end
|
22
27
|
end
|
23
28
|
end
|
24
29
|
|
30
|
+
def self.temp_dl_path=(path)
|
31
|
+
if Dir.exist?(path)
|
32
|
+
@temp_dl_path = path
|
33
|
+
else
|
34
|
+
puts Paint['Invalid path!', :red]
|
35
|
+
exit
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
25
39
|
def self.itunes_path
|
26
40
|
Config[:itunes_path]
|
27
41
|
end
|
28
42
|
|
43
|
+
# Use in Configure.menu
|
44
|
+
def self.itunes_path_name
|
45
|
+
PathControl.itunes_path.sub("/iTunes\ Media/Automatically\ Add\ to\ iTunes.localized", '')
|
46
|
+
end
|
47
|
+
|
29
48
|
def self.set_itunes_path
|
30
49
|
loop do
|
31
50
|
default_path = File.join(ENV['HOME'], '/Music/iTunes')
|
32
|
-
|
33
|
-
|
51
|
+
path_ask = 'Enter a FULL path to iTunes directory'
|
52
|
+
|
53
|
+
if Dir.exist?(default_path)
|
54
|
+
path_ask << " (press enter to set it to #{Paint[default_path, :magenta]})"
|
55
|
+
else
|
56
|
+
default_path = nil
|
57
|
+
end
|
58
|
+
|
59
|
+
path = HighLine.new.ask(path_ask + ':')
|
60
|
+
path = default_path if path == '' && default_path
|
34
61
|
|
35
62
|
path = File.join(path, "iTunes\ Media/Automatically\ Add\ to\ iTunes.localized")
|
36
63
|
|
@@ -39,10 +66,8 @@ module PathControl
|
|
39
66
|
puts Paint['iTunes directory set up!', :green]
|
40
67
|
break
|
41
68
|
else
|
42
|
-
puts "\n"
|
43
69
|
puts Paint["This directory doesn't exist. Please enter path again", :red]
|
44
70
|
end
|
45
|
-
|
46
71
|
end
|
47
72
|
end
|
48
73
|
end
|
data/lib/nehm/track.rb
CHANGED
@@ -1,7 +1,3 @@
|
|
1
|
-
require_relative 'client.rb'
|
2
|
-
require_relative 'artwork.rb'
|
3
|
-
require_relative 'path_control.rb'
|
4
|
-
|
5
1
|
class Track
|
6
2
|
attr_reader :hash
|
7
3
|
|
@@ -22,12 +18,8 @@ class Track
|
|
22
18
|
Artwork.new(self)
|
23
19
|
end
|
24
20
|
|
25
|
-
def dl_url
|
26
|
-
"#{@hash['stream_url']}?client_id=#{Client::CLIENT_ID}"
|
27
|
-
end
|
28
|
-
|
29
21
|
def file_name
|
30
|
-
"#{
|
22
|
+
"#{name}.mp3".tr('/', '')
|
31
23
|
end
|
32
24
|
|
33
25
|
def file_path
|
@@ -38,6 +30,11 @@ class Track
|
|
38
30
|
@hash['id'].to_s
|
39
31
|
end
|
40
32
|
|
33
|
+
# Use in Get.dl and in Track.file_name
|
34
|
+
def name
|
35
|
+
artist + ' - ' + title
|
36
|
+
end
|
37
|
+
|
41
38
|
def title
|
42
39
|
if @hash['title'].include?('-')
|
43
40
|
title = @hash['title'].split('-')
|
@@ -46,5 +43,8 @@ class Track
|
|
46
43
|
@hash['title']
|
47
44
|
end
|
48
45
|
end
|
49
|
-
|
46
|
+
|
47
|
+
def url
|
48
|
+
"#{@hash['stream_url']}?client_id=#{Client::CLIENT_ID}"
|
49
|
+
end
|
50
50
|
end
|
data/lib/nehm/user.rb
CHANGED
@@ -1,20 +1,9 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'faraday'
|
3
|
-
require 'paint'
|
4
|
-
require_relative 'client.rb'
|
5
|
-
require_relative 'config.rb'
|
6
|
-
require_relative 'user_control.rb'
|
7
3
|
|
8
4
|
class User
|
9
|
-
def initialize(
|
10
|
-
|
11
|
-
@id =
|
12
|
-
unless permalink.nil?
|
13
|
-
user = client.get('/resolve', url: "https://soundcloud.com/#{permalink}")
|
14
|
-
user.id
|
15
|
-
else
|
16
|
-
UserControl.default_id
|
17
|
-
end
|
5
|
+
def initialize(id)
|
6
|
+
@id = id
|
18
7
|
end
|
19
8
|
|
20
9
|
def likes(count)
|
@@ -23,9 +12,8 @@ class User
|
|
23
12
|
exit
|
24
13
|
end
|
25
14
|
|
26
|
-
|
27
|
-
likes
|
28
|
-
likes.map { |like| Track.new(like) }
|
15
|
+
likes = Client.get("/users/#{@id}/favorites?limit=#{count}")
|
16
|
+
likes.map { |hash| Track.new(hash) }
|
29
17
|
end
|
30
18
|
|
31
19
|
# Post is last track or repost in profile
|
@@ -36,14 +24,12 @@ class User
|
|
36
24
|
end
|
37
25
|
|
38
26
|
conn = Faraday.new(url: 'https://api-v2.soundcloud.com/') do |faraday|
|
39
|
-
faraday.request :url_encoded # form-encode POST params
|
40
27
|
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
|
41
28
|
end
|
42
|
-
|
43
29
|
response = conn.get("/profile/soundcloud:users:#{@id}?limit=#{count}&offset=0")
|
44
30
|
|
45
31
|
parsed = JSON.parse(response.body)
|
46
32
|
parsed = parsed['collection']
|
47
|
-
parsed.map { |
|
33
|
+
parsed.map { |hash| Track.new(hash['track']) }
|
48
34
|
end
|
49
35
|
end
|
data/lib/nehm/user_control.rb
CHANGED
@@ -1,12 +1,7 @@
|
|
1
|
-
require 'highline'
|
2
|
-
require 'paint'
|
3
|
-
require_relative 'config.rb'
|
4
|
-
require_relative 'client.rb'
|
5
|
-
|
6
1
|
module UserControl
|
7
|
-
def self.
|
2
|
+
def self.default_user
|
8
3
|
if UserControl.logged_in?
|
9
|
-
Config[:default_id]
|
4
|
+
User.new(Config[:default_id])
|
10
5
|
else
|
11
6
|
puts Paint["You didn't logged in", :red]
|
12
7
|
puts "Input #{Paint['nehm configure', :yellow]} to login"
|
@@ -14,18 +9,6 @@ module UserControl
|
|
14
9
|
end
|
15
10
|
end
|
16
11
|
|
17
|
-
def self.user_exist?(url)
|
18
|
-
Client.new.get('/resolve', url: url)
|
19
|
-
rescue SoundCloud::ResponseError => e
|
20
|
-
if e.message =~ /404/
|
21
|
-
raise e
|
22
|
-
else
|
23
|
-
false
|
24
|
-
end
|
25
|
-
else
|
26
|
-
true
|
27
|
-
end
|
28
|
-
|
29
12
|
def self.logged_in?
|
30
13
|
Config.key?(:default_id)
|
31
14
|
end
|
@@ -33,10 +16,9 @@ module UserControl
|
|
33
16
|
def self.log_in
|
34
17
|
loop do
|
35
18
|
permalink = HighLine.new.ask('Please enter your permalink (last word in your profile url): ')
|
36
|
-
client = Client.new
|
37
19
|
url = "https://soundcloud.com/#{permalink}"
|
38
|
-
if
|
39
|
-
user =
|
20
|
+
if user_exist?(permalink)
|
21
|
+
user = Client.get('/resolve', url: url)
|
40
22
|
Config[:default_id] = user.id
|
41
23
|
Config[:permalink] = permalink
|
42
24
|
puts Paint['Successfully logged in!', :green]
|
@@ -46,4 +28,29 @@ module UserControl
|
|
46
28
|
end
|
47
29
|
end
|
48
30
|
end
|
31
|
+
|
32
|
+
def self.user(permalink)
|
33
|
+
if user_exist?(permalink)
|
34
|
+
user = Client.get('/resolve', url: "https://soundcloud.com/#{permalink}")
|
35
|
+
User.new(user.id)
|
36
|
+
else
|
37
|
+
puts Paint['Invalid permalink. Please enter correct permalink', :red]
|
38
|
+
exit
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
module_function
|
43
|
+
|
44
|
+
def user_exist?(permalink)
|
45
|
+
Client.get('/resolve', url: "https://soundcloud.com/#{permalink}")
|
46
|
+
|
47
|
+
rescue SoundCloud::ResponseError => e
|
48
|
+
if e.message =~ /404/
|
49
|
+
false
|
50
|
+
else
|
51
|
+
raise e
|
52
|
+
end
|
53
|
+
else
|
54
|
+
true
|
55
|
+
end
|
49
56
|
end
|
data/lib/nehm/version.rb
CHANGED
data/nehm.gemspec
CHANGED
@@ -4,20 +4,20 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'nehm/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name
|
8
|
-
spec.version
|
9
|
-
spec.authors
|
10
|
-
spec.email
|
7
|
+
spec.name = 'nehm'
|
8
|
+
spec.version = Nehm::VERSION
|
9
|
+
spec.authors = ['Albert Nigmatzianov']
|
10
|
+
spec.email = ['albertnigma@gmail.com']
|
11
11
|
|
12
|
-
spec.summary
|
13
|
-
spec.description
|
14
|
-
spec.homepage
|
15
|
-
spec.license
|
12
|
+
spec.summary = %q{ Convenient way to get tracks from SoundCloud via terminal }
|
13
|
+
spec.description = %q{ nehm is a console tool, which downloads, sets IDv3 tags and adds to your iTunes library your SoundCloud posts or likes in convenient way. See homepage for instructions }
|
14
|
+
spec.homepage = 'http://www.github.com/bogem/nehm'
|
15
|
+
spec.license = 'MIT'
|
16
16
|
|
17
|
-
spec.files
|
18
|
-
spec.bindir
|
19
|
-
spec.executables
|
20
|
-
spec.require_paths
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = 'bin'
|
19
|
+
spec.executables = 'nehm'
|
20
|
+
spec.require_paths = ['lib']
|
21
21
|
spec.required_ruby_version = '>= 1.9'
|
22
22
|
|
23
23
|
spec.add_development_dependency 'bundler', '>= 1.10.5'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nehm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Albert Nigmatzianov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -117,11 +117,11 @@ files:
|
|
117
117
|
- lib/nehm/client.rb
|
118
118
|
- lib/nehm/config.rb
|
119
119
|
- lib/nehm/configure.rb
|
120
|
+
- lib/nehm/get.rb
|
120
121
|
- lib/nehm/help.rb
|
121
122
|
- lib/nehm/os.rb
|
122
123
|
- lib/nehm/path_control.rb
|
123
124
|
- lib/nehm/track.rb
|
124
|
-
- lib/nehm/track_utils.rb
|
125
125
|
- lib/nehm/user.rb
|
126
126
|
- lib/nehm/user_control.rb
|
127
127
|
- lib/nehm/version.rb
|