rmd 0.1.2 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 067b842cf92f0aa47fd788df9be9ec098ba8ff8c
4
- data.tar.gz: a08076b6ca0964cdeab82cd2d1afa4e4e0cf9cb9
3
+ metadata.gz: f3ddcad37e5cdac99c411e76c0cfb9ce51ef15ad
4
+ data.tar.gz: b59e8e7e27ce5f1e070bbcb23a31a89a9599d026
5
5
  SHA512:
6
- metadata.gz: 8bb42566cae5d64de652e7ecca6b5191e2acc447157e919921fd9e109a855542f9bba0d1477f199ad2c82b5cf410f627ae8f5ba2d2fd5c0f903e94af154398e2
7
- data.tar.gz: af17255fe296d64208947df4a4f183e240286d1940e23fc9a9244b63550ffaef82629638233e06694d448398a1c29df1733ae9d3f77ab55dabd935095489d562
6
+ metadata.gz: a20449ff0ae12d79f9ecf8f88c2a0ab207db78c0cf04fd7775eae332318387b4cb508fe46ec25491525264314a98c949287d126a7b37b945db68856a63c82270
7
+ data.tar.gz: 955d1c8e5191417aca895fdf5003e850649df4a80c5ffb910d1fed308608f83decc396a1fa92c9ecf80abcd0fc24a0214df122299e5576b9f8b83d1cf254cd00
@@ -32,7 +32,7 @@ module RMD
32
32
  end
33
33
 
34
34
  def calculate_progress
35
- if song_elements.count > 0
35
+ if song_elements != []
36
36
  progress_bar = ProgressBar.create(
37
37
  starting_at: 0,
38
38
  total: song_elements.count,
@@ -46,9 +46,9 @@ module RMD
46
46
  private
47
47
 
48
48
  def file_path
49
- if options[:folder]
50
- FileUtils.mkdir_p(options[:folder]) unless File.directory?(options[:folder])
51
- File.join(options[:folder], file_name)
49
+ if folder_path
50
+ FileUtils.mkdir_p(folder_path) unless File.directory?(folder_path)
51
+ File.join(folder_path, file_name)
52
52
  else
53
53
  file_name
54
54
  end
@@ -67,5 +67,9 @@ module RMD
67
67
  File.basename(uri.path)
68
68
  end
69
69
  end
70
+
71
+ def folder_path
72
+ options[:folder]
73
+ end
70
74
  end
71
75
  end
@@ -0,0 +1,37 @@
1
+ require 'rmd/song_playlist_adapter'
2
+
3
+ module RMD
4
+ module Factory
5
+ class Base
6
+ attr_reader :link
7
+
8
+ def initialize(link)
9
+ @link = link
10
+ end
11
+
12
+ def build
13
+ case link
14
+ when song_regex
15
+ RMD::SongPlaylistAdapter.new(base_class::Song.new(link))
16
+ when playlist_regex
17
+ base_class::Playlist.new(link)
18
+ else
19
+ raise 'Your url is not valid. Please check again.'
20
+ end
21
+ end
22
+
23
+ def self.build(link)
24
+ new(link).build
25
+ end
26
+
27
+ private
28
+
29
+ def song_regex
30
+ /bai-hat/
31
+ end
32
+
33
+ def playlist_regex; end
34
+ def base_class; end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,29 @@
1
+ require 'rmd/factory/nct'
2
+ require 'rmd/factory/zing'
3
+
4
+ module RMD
5
+ module Factory
6
+ class Main
7
+ attr_reader :link
8
+
9
+ def initialize(link)
10
+ @link = link
11
+ end
12
+
13
+ def build
14
+ case link
15
+ when /nhaccuatui/
16
+ RMD::Factory::NCT.build(link)
17
+ when /mp3\.zing\.vn/
18
+ RMD::Factory::Zing.build(link)
19
+ else
20
+ raise 'Your url must belong to nhaccuatui/zing.'
21
+ end
22
+ end
23
+
24
+ def self.build(link)
25
+ new(link).build
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,19 @@
1
+ require 'rmd/factory/base'
2
+ require 'rmd/nct/song'
3
+ require 'rmd/nct/playlist'
4
+
5
+ module RMD
6
+ module Factory
7
+ class NCT < RMD::Factory::Base
8
+ private
9
+
10
+ def playlist_regex
11
+ /playlist/
12
+ end
13
+
14
+ def base_class
15
+ RMD::NCT
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require 'rmd/factory/base'
2
+ require 'rmd/zing/song'
3
+ require 'rmd/zing/playlist'
4
+
5
+ module RMD
6
+ module Factory
7
+ class Zing < RMD::Factory::Base
8
+ private
9
+
10
+ def playlist_regex
11
+ /album|playlist/
12
+ end
13
+
14
+ def base_class
15
+ RMD::Zing
16
+ end
17
+ end
18
+ end
19
+ end
data/lib/rmd/main.rb CHANGED
@@ -1,10 +1,13 @@
1
1
  module RMD
2
2
  class Main < Thor
3
+
3
4
  desc 'download [LINK]', "Dowload your music from a specific link"
4
5
  method_option :folder, aliases: '-d', desc: 'Choose specific folder to put the downloaded file'
6
+ method_option :fast, type: :boolean, default: false, desc: 'Use multithread to enable faster download, default: false'
7
+
5
8
  def download(link = nil)
6
9
  if link == nil
7
- invoke :help
10
+ invoke(:help, [:download])
8
11
  else
9
12
  RMD::Processor.process(link, options)
10
13
  end
@@ -0,0 +1,21 @@
1
+ require 'rmd/downloader'
2
+
3
+ module RMD
4
+ module ProcessStrategy
5
+ class Base
6
+ attr_reader :options
7
+
8
+ def initialize(options)
9
+ @options = options
10
+ end
11
+
12
+ def process(playlist); end
13
+
14
+ private
15
+
16
+ def download(link)
17
+ RMD::Downloader.download(link, options)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,16 @@
1
+ require 'rmd/process_strategy/base'
2
+ require 'parallel'
3
+
4
+ module RMD
5
+ module ProcessStrategy
6
+ class MultiThread < RMD::ProcessStrategy::Base
7
+ MAX_PROCESS = 10
8
+
9
+ def process(songs)
10
+ Parallel.each(songs, in_processes: MAX_PROCESS) do |song|
11
+ download(song)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ require 'rmd/process_strategy/base'
2
+
3
+ module RMD
4
+ module ProcessStrategy
5
+ class SingleThread < RMD::ProcessStrategy::Base
6
+ def process(songs)
7
+ songs.each do |song|
8
+ download(song)
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
data/lib/rmd/processor.rb CHANGED
@@ -1,6 +1,6 @@
1
- require 'rmd/downloader'
2
- require 'rmd/factory'
3
- require 'ruby-progressbar'
1
+ require 'rmd/factory/main'
2
+ require 'rmd/process_strategy/single_thread'
3
+ require 'rmd/process_strategy/multi_thread'
4
4
 
5
5
  module RMD
6
6
  class Processor
@@ -13,13 +13,11 @@ module RMD
13
13
 
14
14
  def process
15
15
  puts "Start processing #{link}...".green
16
- playlist = RMD::Factory.build(link)
16
+ playlist = RMD::Factory::Main.build(link)
17
17
  playlist.fetch
18
18
 
19
19
  if playlist.success?
20
- playlist.songs.each do |song|
21
- download(song)
22
- end
20
+ strategy.process(playlist.songs)
23
21
  end
24
22
 
25
23
  playlist.errors.each do |error|
@@ -30,16 +28,20 @@ module RMD
30
28
  def self.process(link, options = {})
31
29
  begin
32
30
  new(link, options).process
33
- rescue => e
34
- puts e.message.red
31
+ rescue => error
32
+ puts error.message.red
35
33
  puts 'Errors! Can not continue!'.red
36
34
  end
37
35
  end
38
36
 
39
37
  private
40
38
 
41
- def download(data_link)
42
- RMD::Downloader.download(data_link, options)
39
+ def strategy
40
+ @strategy ||= if options[:fast]
41
+ RMD::ProcessStrategy::MultiThread.new(options)
42
+ else
43
+ RMD::ProcessStrategy::SingleThread.new(options)
44
+ end
43
45
  end
44
46
  end
45
47
  end
@@ -1,3 +1,5 @@
1
+ require 'forwardable'
2
+
1
3
  module RMD
2
4
  class SongPlaylistAdapter
3
5
  extend Forwardable
data/lib/rmd/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rmd
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rmd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hieu Nguyen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-20 00:00:00.000000000 Z
11
+ date: 2015-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: parallel
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.3'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.3'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: bundler
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -163,13 +177,19 @@ files:
163
177
  - lib/rmd/base/playlist.rb
164
178
  - lib/rmd/base/song.rb
165
179
  - lib/rmd/downloader.rb
166
- - lib/rmd/factory.rb
180
+ - lib/rmd/factory/base.rb
181
+ - lib/rmd/factory/main.rb
182
+ - lib/rmd/factory/nct.rb
183
+ - lib/rmd/factory/zing.rb
167
184
  - lib/rmd/main.rb
168
185
  - lib/rmd/nct/getter/base.rb
169
186
  - lib/rmd/nct/getter/key_from_page.rb
170
187
  - lib/rmd/nct/getter/key_from_url.rb
171
188
  - lib/rmd/nct/playlist.rb
172
189
  - lib/rmd/nct/song.rb
190
+ - lib/rmd/process_strategy/base.rb
191
+ - lib/rmd/process_strategy/multi_thread.rb
192
+ - lib/rmd/process_strategy/single_thread.rb
173
193
  - lib/rmd/processor.rb
174
194
  - lib/rmd/song_playlist_adapter.rb
175
195
  - lib/rmd/version.rb
data/lib/rmd/factory.rb DELETED
@@ -1,40 +0,0 @@
1
- require 'rmd/song_playlist_adapter'
2
- require 'rmd/nct/song'
3
- require 'rmd/nct/playlist'
4
- require 'rmd/zing/song'
5
- require 'rmd/zing/playlist'
6
-
7
- module RMD
8
- class Factory
9
- attr_reader :link
10
-
11
- def initialize(link)
12
- @link = link
13
- end
14
-
15
- def build
16
- case link
17
- when /nhaccuatui/
18
- case link
19
- when /bai-hat/
20
- RMD::SongPlaylistAdapter.new(RMD::NCT::Song.new(link))
21
- when /playlist/
22
- RMD::NCT::Playlist.new(link)
23
- end
24
- when /mp3\.zing\.vn/
25
- case link
26
- when /bai-hat/
27
- RMD::SongPlaylistAdapter.new(RMD::Zing::Song.new(link))
28
- when /album|playlist/
29
- RMD::Zing::Playlist.new(link)
30
- end
31
- else
32
- raise 'Your url is not valid. Please check again.'
33
- end
34
- end
35
-
36
- def self.build(link)
37
- new(link).build
38
- end
39
- end
40
- end