rmd 0.1.0 → 0.1.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: b3a06f950294746b97a61c9cd89382ee52a90bcf
4
- data.tar.gz: c1d5ff028c1480db5c37998666ce78ca7bb77386
3
+ metadata.gz: ee9ef6386d7b8b4552364b62a8a4d5447093b7d5
4
+ data.tar.gz: 3539ded5f60b1625ecbcd5ece0fb2d49cd2eb175
5
5
  SHA512:
6
- metadata.gz: 8bcb213f2843052cf62cff598d8d9a846df7de6dc6971d0328465915a8f368244ccb3010cfac1246b51c5130c19117a8e62e1d35c8684165865ae10e8bcaa014
7
- data.tar.gz: 85584e5347e6c454e88f3dd28bc3cfa21a72ecc7cc806d5dd4a8593b0b452ce71f7d718ff67b14463dda43b25baaec83bf1d49c119291d14f1531f2af6b81ced
6
+ metadata.gz: efc900f0ef1ca1357d97957573a2ce0dea7f621063c79a5323ff16e8d159d3ae2f58bc20740a6ea055d607ebcb4feb5c06f9282fba971f857bf80b4f136a5455
7
+ data.tar.gz: 14afd577c9d6dbed874374d8d7c606e9c94426112dde1e1d896bc94958b948732b53c4e1dc61baf732baa4e3c5c5fb13522280bae99db0a3ff629a35bf8b49d5
data/README.md CHANGED
@@ -48,10 +48,11 @@ Time: 00:00:03 =================================================================
48
48
 
49
49
  - [x] Download songs/playlists from NCT
50
50
  - [x] Download songs/playlist from Zing MP3
51
- - [ ] Read a file to get list of links to download
52
51
  - [x] Visual progress bar for download
53
- - [ ] Specify download folder
52
+ - [x] Specify download folder
53
+ - [ ] Multi-thread
54
54
  - [ ] Cache data
55
+ - [ ] Read a file to get list of links to download
55
56
 
56
57
  ## Contributing
57
58
 
@@ -1,12 +1,14 @@
1
1
  require 'open-uri'
2
+ require 'fileutils'
2
3
  require 'ruby-progressbar'
3
4
 
4
5
  module RMD
5
6
  class Downloader
6
- attr_reader :link
7
+ attr_reader :link, :options
7
8
 
8
- def initialize(link)
9
+ def initialize(link, options = {})
9
10
  @link = link
11
+ @options = options
10
12
  end
11
13
 
12
14
  def download
@@ -31,18 +33,27 @@ module RMD
31
33
  }
32
34
 
33
35
  open(link, "rb", content_length_proc: content_length_proc, progress_proc: progress_proc) do |page|
34
- File.open(file_name, "wb") do |file|
36
+ File.open(file_path, "wb") do |file|
35
37
  file.write(page.read)
36
38
  end
37
39
  end
38
40
  end
39
41
 
40
- def self.download(link)
41
- new(link).download
42
+ def self.download(link, options = {})
43
+ new(link, options).download
42
44
  end
43
45
 
44
46
  private
45
47
 
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)
52
+ else
53
+ file_name
54
+ end
55
+ end
56
+
46
57
  def file_name
47
58
  @file_name ||= uncached_file_name
48
59
  end
data/lib/rmd/main.rb CHANGED
@@ -1,11 +1,12 @@
1
1
  module RMD
2
2
  class Main < Thor
3
3
  desc 'download [LINK]', "Dowload your music from a specific link"
4
+ method_option :folder, aliases: '-d', desc: 'Choose specific folder to put the downloaded file'
4
5
  def download(link = nil)
5
6
  if link == nil
6
7
  invoke :help
7
8
  else
8
- RMD::Processor.process(link)
9
+ RMD::Processor.process(link, options)
9
10
  end
10
11
  end
11
12
  end
data/lib/rmd/processor.rb CHANGED
@@ -4,10 +4,11 @@ require 'ruby-progressbar'
4
4
 
5
5
  module RMD
6
6
  class Processor
7
- attr_reader :link
7
+ attr_reader :link, :options
8
8
 
9
- def initialize(link)
9
+ def initialize(link, options = {})
10
10
  @link = link
11
+ @options = options
11
12
  end
12
13
 
13
14
  def process
@@ -26,9 +27,9 @@ module RMD
26
27
  end
27
28
  end
28
29
 
29
- def self.process(link)
30
+ def self.process(link, options = {})
30
31
  begin
31
- new(link).process
32
+ new(link, options).process
32
33
  rescue => e
33
34
  puts e.message.red
34
35
  puts 'Errors! Can not continue!'.red
@@ -38,7 +39,7 @@ module RMD
38
39
  private
39
40
 
40
41
  def download(data_link)
41
- RMD::Downloader.download(data_link)
42
+ RMD::Downloader.download(data_link, options)
42
43
  end
43
44
  end
44
45
  end
data/lib/rmd/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Rmd
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -2,7 +2,8 @@ require 'spec_helper'
2
2
 
3
3
  describe RMD::Main do
4
4
  describe '#download' do
5
- let(:run_method) { RMD::Processor.process(link) }
5
+ let(:options) { {} }
6
+ let(:run_method) { RMD::Processor.process(link, options) }
6
7
  let(:file_path) { File.expand_path("../../../#{file_name}", __FILE__) }
7
8
 
8
9
  context 'when downloads song from nhaccuatui' do
@@ -33,5 +34,21 @@ describe RMD::Main do
33
34
  let(:scenario) { 'zing playlist' }
34
35
  it_behaves_like 'download'
35
36
  end
37
+
38
+ context 'when downloads song with options' do
39
+ let(:link) { 'http://mp3.zing.vn/bai-hat/Bird-TV-Size-Yuya-Matsushita/ZWZCO98B.html' }
40
+ let(:file_name) { 'Bird TV Size - Yuya Matsushita.mp3' }
41
+ let(:scenario) { 'zing song' }
42
+ let(:options) { { folder: 'tmp' } }
43
+ let(:file_path) { File.expand_path("../../../tmp/#{file_name}", __FILE__) }
44
+
45
+ it 'downloads and put to correct folder' do
46
+ VCR.use_cassette(scenario) do
47
+ capture_io { run_method }
48
+ expect(File.exists?(file_path)).to eq true
49
+ end
50
+ File.delete(file_path)
51
+ end
52
+ end
36
53
  end
37
54
  end
@@ -6,7 +6,7 @@ describe RMD::Downloader do
6
6
  let(:downloader) { instance_double('RMD::Downloader') }
7
7
 
8
8
  it 'downloads' do
9
- expect(described_class).to receive(:new).with(link).and_return(downloader)
9
+ expect(described_class).to receive(:new).with(link, {}).and_return(downloader)
10
10
  expect(downloader).to receive(:download)
11
11
  described_class.download(link)
12
12
  end
@@ -36,4 +36,26 @@ describe RMD::Downloader do
36
36
  it { is_expected.to eq 'abc xyz.mp3' }
37
37
  end
38
38
  end
39
+
40
+ describe '#file_path' do
41
+ let(:link) { 'link' }
42
+ let(:downloader) { described_class.new(link, options) }
43
+ let(:options) { { folder: folder } }
44
+ let(:file_name) { 'file_name' }
45
+ subject { downloader.send(:file_path) }
46
+
47
+ before do
48
+ expect(downloader).to receive(:file_name).and_return(file_name).at_least(:once)
49
+ end
50
+
51
+ context 'when option folder exists' do
52
+ let(:folder) { 'folder' }
53
+ it { is_expected.to eq 'folder/file_name' }
54
+ end
55
+
56
+ context 'when option folder does not exist' do
57
+ let(:folder) { nil }
58
+ it { is_expected.to eq file_name }
59
+ end
60
+ end
39
61
  end
@@ -9,7 +9,7 @@ describe RMD::Processor do
9
9
  let(:processor) { double('RMD::processor') }
10
10
 
11
11
  it 'processes' do
12
- expect(described_class).to receive(:new).with(link).and_return(processor)
12
+ expect(described_class).to receive(:new).with(link, {}).and_return(processor)
13
13
  expect(processor).to receive(:process)
14
14
  described_class.process(link)
15
15
  end
@@ -55,7 +55,7 @@ describe RMD::Processor do
55
55
  let(:data_link) { 'data_link' }
56
56
 
57
57
  it 'downloads data' do
58
- expect(RMD::Downloader).to receive(:download).with(data_link)
58
+ expect(RMD::Downloader).to receive(:download).with(data_link, {})
59
59
  processor.send(:download, data_link)
60
60
  end
61
61
  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.0
4
+ version: 0.1.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-18 00:00:00.000000000 Z
11
+ date: 2015-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor