nehm 1.6.1 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0aa2bd91903adaec7cb6b378a83d169944a23e3a
4
- data.tar.gz: 6fcea548ac666b3bef9ea038f0de23f1992d9eb4
3
+ metadata.gz: 642f53e571f554b780f52a641af8fdfe81f0a05c
4
+ data.tar.gz: d7eef194b669c2915a4ee53ddf7e8049b3e46058
5
5
  SHA512:
6
- metadata.gz: c5d5e134ee8b62dcb0ee356e5b4fcca17b64652c1581090f552bdb5f303f9d96e5f8a0c012f4617c2b1efca7973b7de5e2372e8422f955d3d9ca412ec2a72f9c
7
- data.tar.gz: 1de3a085d88651abb6a3a8f16fd6d17116f3ee1ef8c7ba7baf1f4026eeca4203d43fe3cb79908dff1229e409a6ac145902a71c4d84d5c889792de0665083da9c
6
+ metadata.gz: d5926b9ad5deabd35d73a8caff482596e37a2083ad048dc203fc6171c8758e0b3cb769f6a838e919938598cd25f650d97606df580de9764f590600ef232f870e
7
+ data.tar.gz: 8097e9ef27791c75a04fa6841c1fea3d537426fda0551808702aba9fcc0376e4d2791e67aa0cd095462c38c554aef350188147038c99165ca6ddaf46063edfd7
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # nehm change log
2
2
 
3
+ ## 2.0.1
4
+ * Make gem size smaller
5
+
6
+ ## 2.0
7
+ * Add 'select' and 'search' commands *(more info in README and `nehm help`)*
8
+ * Many performance improvements *(changes in application structure)*
9
+ * More stable *(Many bug fixes and error handling)*
10
+ * Less dependencies *(Remove 4 dependencies)*
11
+ * Prettier README
12
+
3
13
  ## 1.6.1
4
14
  * Fix nehm's fails when download tracks from url
5
15
 
data/README.md CHANGED
@@ -1,17 +1,35 @@
1
- # nehm
1
+ <div align="center">
2
+ <img src="https://raw.github.com/bogem/nehm/master/Pictures/logo.png" alt="Logo"></img>
2
3
 
3
- ![ScreenShot](https://raw.github.com/bogem/nehm/master/Screenshots/screenshot.png)
4
4
 
5
- *nehm* is a console tool, which downloads, sets IDv3 tags and adds to your iTunes library your SoundCloud posts or likes in convenient way
5
+ <p><b><i>nehm</i></b> is a console tool, which downloads, sets IDv3 tags and adds to your iTunes library your SoundCloud posts or likes in convenient way</p>
6
6
 
7
- [![Gem Version](https://badge.fury.io/rb/nehm.svg)](http://badge.fury.io/rb/nehm)
8
- [![Dependency Status](https://gemnasium.com/bogem/nehm.svg)](https://gemnasium.com/bogem/nehm)
9
- [![Code Climate](https://codeclimate.com/github/bogem/nehm/badges/gpa.svg)](https://codeclimate.com/github/bogem/nehm)
7
+ <a href="http://badge.fury.io/rb/nehm"><img src="https://badge.fury.io/rb/nehm.svg" alt="Gem Version"></img></a>
8
+ <a href="https://gemnasium.com/bogem/nehm"><img src="https://gemnasium.com/bogem/nehm.svg" alt="Dependency staus"></img></a>
9
+ <a href="https://codeclimate.com/github/bogem/nehm"><img src="https://codeclimate.com/github/bogem/nehm/badges/gpa.svg" alt="Code climate"></img></a>
10
+ </div>
10
11
 
11
- ## DISCLAIMER
12
- ***For personal use only***
12
+ ---
13
+ <div align="center">
14
+ <a href="https://www.dropbox.com/s/m4heiyq7vbpc4qs/1help.png" target="_blank"><img src="https://raw.github.com/bogem/nehm/master/Pictures/1help.png" alt="Help"></img></a>
15
+ <a href="https://www.dropbox.com/s/b68flm7hv5myhk4/2get.png" target="_blank"><img src="https://raw.github.com/bogem/nehm/master/Pictures/2get.png" alt="Select"></img></a>
16
+ <a href="https://www.dropbox.com/s/5gy6c5nzrsvhlv0/3select.png" target="_blank"><img src="https://raw.github.com/bogem/nehm/master/Pictures/3select.png" alt="Select"></img></a>
17
+ <a href="https://www.dropbox.com/s/ynn9kb0ykcdishp/4search.png" target="_blank"><img src="https://raw.github.com/bogem/nehm/master/Pictures/4search.png" alt="Search"></img></a>
18
+
19
+ <p><b>(clickable screenshots)</b></p>
20
+
21
+ </div>
22
+
23
+ ***
24
+
25
+ <div align="center">
26
+ <h2>DISCLAIMER</h2>
27
+
28
+ <b><i><p>For personal use only</p>
29
+
30
+ Nehm developer doesn't responsible for any illegal usage of this program</i></b>
31
+ </div>
13
32
 
14
- ***Nehm developer doesn't responsible for any illegal usage of this program***
15
33
 
16
34
  ## Installation
17
35
 
@@ -48,57 +66,56 @@ Before using the nehm, you should set it up:
48
66
  Enter path to desirable download directory (press enter to set it to ...
49
67
  ```
50
68
 
51
- ## Usage
69
+ ## Usage Examples
52
70
 
53
- **!!nehm doesn't add tracks to iTunes library, if you use Linux!!**
71
+ Type `nehm help` to list of all available commands or `nehm help COMMAND` for specific command
54
72
 
55
- * Get (download to download directory, set tags and add to iTunes library) your last like
73
+ Also commands and arguments (but **NOT** options) may be abbreviated, so long as they are unambiguous.
56
74
 
57
- `nehm get like`
75
+ #### Get (download to default directory, set tags and add to iTunes library) your last like
58
76
 
59
- * Get your last post (last track or repost from your profile)
77
+ `$ nehm get like` = `$ nehm g l`
60
78
 
61
- `nehm get post`
79
+ #### Get your last post (last track or repost from your profile)
62
80
 
63
- ***(nehm doesn't get and download playlists. It just skips them)***
81
+ `$ nehm get post` = `$ nehm g p`
64
82
 
65
- * Get multiple last posts or likes
83
+ #### Get multiple last posts or likes
66
84
 
67
- `nehm get 3 posts` or `nehm get 3 likes`
85
+ `$ nehm get 3 posts` = `$ nehm get 3 ps`
68
86
 
69
- * Just download and set tags any track
87
+ `$ nehm get 5 likes` = `$ nehm get 5 ls`
70
88
 
71
- `nehm dl post` or `nehm dl like` or `nehm dl 3 likes`
89
+ #### Just download and set tags any track
72
90
 
73
- * Get tracks from another user
91
+ `$ nehm dl post` = `$ nehm d p`
74
92
 
75
- `nehm get post from nasa` or `nehm dl like from bogem`
93
+ #### Get tracks from another user
76
94
 
77
- * Get tracks to another directory
95
+ `$ nehm get post from nasa` or `$ nehm d l from bogem`
78
96
 
79
- `nehm get post to ~/Downloads` or `nehm dl like from bogem to .`
97
+ #### Get tracks to another directory
80
98
 
81
- * Get tracks to another iTunes playlist
99
+ `$ nehm g p to ~/Downloads` or `$ nehm d l from bogem to .`
82
100
 
83
- `nehm get post playlist MyPlaylist`
101
+ #### Get tracks to another iTunes playlist
84
102
 
85
- * Get or download track from url
103
+ `$ nehm g p pl MyPlaylist`
86
104
 
87
- `nehm get https://soundcloud.com/nasa/delta-iv-launch`
105
+ #### Get or download track from url
88
106
 
89
- or
107
+ `$ nehm g https://soundcloud.com/nasa/delta-iv-launch`
90
108
 
91
- `nehm dl https://soundcloud.com/nasa/delta-iv-launch`
109
+ #### Select likes or posts and download them
92
110
 
93
- * Configure (change download directory, permalink, playlist)
111
+ `$ nehm select likes` = `$ nehm sel l`
94
112
 
95
- `nehm configure`
113
+ #### Search for tracks and download them
96
114
 
97
- * Help
115
+ `$ nehm search kanye west` = `$ nehm sea kanye west`
98
116
 
99
- `nehm help`
100
117
 
101
- ##FAQ
118
+ ## FAQ
102
119
 
103
120
  **Q: What is permalink?**
104
121
 
data/Rakefile CHANGED
@@ -1,21 +1,71 @@
1
- require_relative 'lib/nehm/version.rb'
2
- task default: %w(build install delete)
1
+ require 'bundler'
2
+ require 'colored'
3
+ require 'nehm/ui'
4
+ require 'rake'
3
5
 
4
- file = 'nehm-' + Nehm::VERSION + '.gem'
6
+ Bundler::GemHelper.install_tasks
7
+ task default: %w(install)
5
8
 
6
- task :build do
7
- system('gem build nehm.gemspec')
8
- end
9
+ file = 'pkg/nehm-' + Nehm::VERSION + '.gem'
9
10
 
10
- task :install do
11
- system('gem install ./' + file)
12
- end
11
+ ##
12
+ # Push to rubygems
13
13
 
14
- task :delete do
14
+ task :push => :build do
15
+ `gem push #{file}`
15
16
  File.delete('./' + file)
16
17
  end
17
18
 
18
- task :push => :build do
19
- system('gem push ' + file)
20
- File.delete('./' + file)
19
+ ##
20
+ # Add command with boilerplate code
21
+ #
22
+ # For example, you want to add 'get' command
23
+ # For that you should input 'rake nc[get]'
24
+
25
+ task :nc, [:cmd] do |_, args|
26
+ cmd = args[:cmd]
27
+ cmd_file = "lib/nehm/commands/#{cmd}_command.rb"
28
+
29
+ puts "Making #{cmd} command..."
30
+
31
+ code = <<-EOF
32
+ module Nehm
33
+
34
+ ##
35
+ # Write here description for command
36
+
37
+ class #{cmd.capitalize}Command < Command
38
+
39
+ ##
40
+ # Add all command's options in 'initialize' method
41
+
42
+ def initialize
43
+ super
44
+ end
45
+
46
+ def execute
47
+ end
48
+
49
+ def arguments
50
+ end
51
+
52
+ def program_name
53
+ 'nehm #{cmd}'
54
+ end
55
+
56
+ def summary
57
+ end
58
+
59
+ def usage
60
+ end
61
+
62
+ end
63
+ end
64
+ EOF
65
+
66
+ # Write to file
67
+ File.open(cmd_file, 'w') { |f| f.write(code) }
68
+
69
+ Nehm::UI.success "Successfully made #{cmd} command!"
70
+ Nehm::UI.warning "Don't forget to add the name of command to CommandManager::COMMANDS"
21
71
  end
data/bin/nehm CHANGED
@@ -8,7 +8,6 @@ $stderr = STDOUT
8
8
  begin
9
9
  Nehm.start(ARGV)
10
10
  rescue Interrupt # SIGINT
11
- puts "\nGoodbye!"
12
11
  Nehm::UI.term
13
12
  rescue StandardError, Timeout::Error => ex
14
13
  Nehm::UI.term "While executing nehm ... (#{ex.class})\n #{ex}"
data/lib/nehm.rb CHANGED
@@ -1,50 +1,72 @@
1
1
  require 'colored'
2
- require 'highline'
3
2
 
4
3
  require 'nehm/client'
5
4
  require 'nehm/cfg'
6
5
  require 'nehm/command_manager'
6
+ require 'nehm/os'
7
7
  require 'nehm/path_manager'
8
8
  require 'nehm/playlist_manager'
9
+ require 'nehm/track_manager'
9
10
  require 'nehm/ui'
10
11
  require 'nehm/user_manager'
11
12
 
12
13
  module Nehm
13
14
 
14
- # TODO: add rake tests
15
- # TODO: add search command
16
- # TODO: add select command
17
-
18
15
  def self.start(args)
16
+ if args.empty?
17
+ UI.say HELP
18
+ UI.term
19
+ end
20
+
19
21
  init unless initialized?
20
22
 
21
23
  CommandManager.run(args)
22
24
  end
23
25
 
26
+ HELP = <<-EOF
27
+ #{'nehm'.green} is a console tool, which downloads, sets IDv3 tags and adds to your iTunes library your SoundCloud posts or likes in convenient way
28
+
29
+ #{'Available nehm commands:'.yellow}
30
+ #{'get'.green} Download, set tags and add to your iTunes library last post or like from your profile
31
+ #{'dl'.green} Download and set tags last post or like from your profile
32
+ #{'configure'.green} Configure application
33
+ #{'help'.green} Show help for specified command
34
+ #{'search'.green} Search tracks, print them nicely and download selected tracks
35
+ #{'select'.green} Get likes or posts from your account, nicely print them and download selected tracks
36
+ #{'version'.green} Show version of installed nehm
37
+
38
+ See #{'nehm help COMMAND'.yellow} to read about a specific command
39
+
40
+ Commands and arguments (but NOT options) may be abbreviated, so long as they are unambiguous.
41
+ e.g. 'nehm g l' is short for 'nehm get like'.
42
+ EOF
43
+
24
44
  module_function
25
45
 
26
46
  def init
27
- UI.success 'Hello!'
47
+ UI.say 'Hello!'.green
28
48
  UI.say 'Before using the nehm, you should set it up:'
29
49
  Cfg.create unless Cfg.exist?
30
50
 
31
51
  PathManager.set_dl_path
32
52
  UI.newline
33
53
 
34
- unless OS.linux?
54
+ UserManager.set_uid
55
+ UI.newline
56
+
57
+ if OS.mac?
35
58
  PlaylistManager.set_playlist
36
59
  UI.newline
37
60
  end
38
61
 
39
- UserManager.set_uid
62
+ UI.success "Now you can use nehm!"
40
63
  UI.newline
41
64
 
42
- UI.success "Now you can use nehm!\n"
43
- sleep(1)
65
+ sleep(UI::SLEEP_PERIOD)
44
66
  end
45
67
 
46
68
  def initialized?
47
- File.exist?(Cfg::FILE_PATH)
69
+ Cfg.exist?
48
70
  end
49
71
 
50
72
  end
data/lib/nehm/cfg.rb CHANGED
@@ -1,4 +1,4 @@
1
- require 'bogy'
1
+ require 'yaml'
2
2
 
3
3
  module Nehm
4
4
 
@@ -8,18 +8,18 @@ module Nehm
8
8
  module Cfg
9
9
 
10
10
  FILE_PATH = File.join(ENV['HOME'], '.nehmconfig')
11
- CONFIG_FILE = Bogy.new(file: FILE_PATH)
12
11
 
13
12
  def self.[](key)
14
- CONFIG_FILE[key.to_s]
13
+ config_hash[key.to_s]
15
14
  end
16
15
 
17
16
  def self.[]=(key, value)
18
- CONFIG_FILE[key.to_s] = value
17
+ config_hash[key.to_s] = value
18
+ write
19
19
  end
20
20
 
21
21
  def self.create
22
- File.open(FILE_PATH, 'w+') { |f| f.write("---\napp: nehm") }
22
+ File.new(FILE_PATH, 'w+')
23
23
  end
24
24
 
25
25
  def self.exist?
@@ -27,7 +27,20 @@ module Nehm
27
27
  end
28
28
 
29
29
  def self.key?(key)
30
- CONFIG_FILE.to_h.key?(key.to_s)
30
+ config_hash.key?(key.to_s)
31
+ end
32
+
33
+ module_function
34
+
35
+ def config_hash
36
+ @config_hash ||= YAML.load_file(FILE_PATH)
37
+ @config_hash ||= {} unless @config_hash
38
+
39
+ @config_hash
40
+ end
41
+
42
+ def write
43
+ IO.write(FILE_PATH, config_hash.to_yaml)
31
44
  end
32
45
 
33
46
  end
data/lib/nehm/client.rb CHANGED
@@ -1,12 +1,11 @@
1
1
  require 'certifi'
2
- require 'faraday'
3
- require 'json'
4
- require 'soundcloud'
2
+ require 'nehm/http_client'
5
3
 
6
4
  module Nehm
7
5
 
8
6
  ##
9
7
  # Client module contains all SC API interaction methods
8
+ # Also it forms urls und send them to HTTPClient
10
9
 
11
10
  module Client
12
11
 
@@ -16,14 +15,9 @@ module Nehm
16
15
  ENV['SSL_CERT_FILE'] = Certifi.where
17
16
 
18
17
  ##
19
- # SoundCloud API client ID
18
+ # HTTP client object
20
19
 
21
- CLIENT_ID = '11a37feb6ccc034d5975f3f803928a32'
22
-
23
- ##
24
- # SoundCloud client object
25
-
26
- SC_CLIENT = Soundcloud.new(client_id: CLIENT_ID)
20
+ HTTP_CLIENT = HTTPClient.new
27
21
 
28
22
  ##
29
23
  # Max limit of tracks for correct SoundCloud requests
@@ -33,7 +27,7 @@ module Nehm
33
27
  ##
34
28
  # Returns raw array of likes or posts (depends on argument 'type')
35
29
 
36
- def self.tracks(count, type, uid)
30
+ def self.tracks(count, offset, type, uid)
37
31
  UI.term "Invalid number of #{type}" if count == 0
38
32
 
39
33
  iterations = count.to_f / TRACKS_LIMIT
@@ -47,48 +41,51 @@ module Nehm
47
41
  tracks +=
48
42
  case type
49
43
  when :likes
50
- likes(limit, i * TRACKS_LIMIT, uid)
44
+ likes(limit, i * TRACKS_LIMIT + offset, uid)
51
45
  when :posts
52
- posts(limit, i * TRACKS_LIMIT, uid)
46
+ posts(limit, i * TRACKS_LIMIT + offset, uid)
53
47
  end
54
48
  end
55
49
  tracks
56
50
  end
57
51
 
52
+ def self.search(query, limit, offset)
53
+ uri = "/tracks?q=#{query}&limit=#{limit}&offset=#{offset}"
54
+ HTTP_CLIENT.get(1, uri)
55
+ end
56
+
58
57
  ##
59
- # Returns user hash from SoundCloud or nil if user doesn't exist
58
+ # Returns track hash from SoundCloud by specified uri
60
59
 
61
- def self.user(permalink)
62
- SC_CLIENT.get('/resolve', url: "https://soundcloud.com/#{permalink}")
63
- rescue SoundCloud::ResponseError => e
64
- return nil if e.message =~ /404/
60
+ def self.track(uri)
61
+ HTTP_CLIENT.resolve(uri)
65
62
  end
66
63
 
67
64
  ##
68
- # Returns track hash from SoundCloud by specified url
65
+ # Returns user hash from SoundCloud or nil if user doesn't exist
69
66
 
70
- def self.track(url)
71
- SC_CLIENT.get('/resolve', url: url)
67
+ def self.user(permalink)
68
+ url = "http://soundcloud.com/#{permalink}"
69
+ begin
70
+ HTTP_CLIENT.resolve(url)
71
+ rescue HTTPClient::Status404
72
+ return nil
73
+ rescue HTTPClient::ConnectionError
74
+ UI.term "Connection error. Check your internet connection\nSoundCloud can also be down"
75
+ end
72
76
  end
73
77
 
74
78
  module_function
75
79
 
76
80
  def likes(limit, offset, uid)
77
- SC_CLIENT.get("/users/#{uid}/favorites?limit=#{limit}&offset=#{offset}")
81
+ uri = "/users/#{uid}/favorites?limit=#{limit}&offset=#{offset}"
82
+ HTTP_CLIENT.get(1, uri)
78
83
  end
79
84
 
80
- ##
81
- # Stantard SoundCloud Ruby wrapper doesn't support reposts if user
82
- # isn't authorized
83
- # But api-v2.soundcloud.com supports it
84
-
85
- # TODO: use net/http instead of Faraday
86
-
87
85
  def posts(limit, offset, uid)
88
- conn = Faraday.new(url: 'https://api-v2.soundcloud.com/')
89
- response = conn.get("/profile/soundcloud:users:#{uid}?limit=#{limit}&offset=#{offset}")
90
- parsed = JSON.parse(response.body)
91
- parsed['collection']
86
+ uri = "/profile/soundcloud:users:#{uid}?limit=#{limit}&offset=#{offset}"
87
+ response = HTTP_CLIENT.get(2, uri)
88
+ response['collection']
92
89
  end
93
90
 
94
91
  end