kgmusic 0.1.0pre20160524 → 0.1.0pre20160525

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: 7fd045bd3f769580e8326eb6fe3a67a2b4c6f572
4
- data.tar.gz: 2b248d9cd21dbb25b7a27401b3fa7ca73022aec6
3
+ metadata.gz: 026be473c388de1d6d9e78abf7725d84aa78ec2c
4
+ data.tar.gz: 99d337aa7061c503f362a7917c3a28b3b633b7d8
5
5
  SHA512:
6
- metadata.gz: a33f6172cedf98f79424caf865a1dac55ef4e3c06498e37ce3d09ce06f03b83f8810eef217823c742b6a86f45dbb5611e9b5859afee2211ee05df89836b73a12
7
- data.tar.gz: 4766d4f001cc045d985d8f65b5c0820803e1e324226f2fb727f8b031050d8eca3ded8611beedec174bcbc5282a551b39da389ca42e6d83099aa6ac98605956f5
6
+ metadata.gz: 3a8a3c1069986898c5fb5931304afef52c6704dcd0d3fac23b66925025fae44c10767010d62aef7b8002aec197f4baef86f550aef8fe1a4c02cb992ea9f787c0
7
+ data.tar.gz: 85f128695eab5ae5416821b0a5f05f778773b415c3ef6f8e974b145e7a7979e1b9934fa312f71742588d72b9c46173ce8f96ac94bd7a95f7b90f81a16f3cf131
data/kgmusic.gemspec CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["vitvegl"]
10
10
  spec.email = ["vitvelg@gmail.com"]
11
11
 
12
- spec.summary = "Find music albums on kibergrad.fm"
13
- spec.description = "find music albums on kibergrad.fm"
12
+ spec.summary = "find and download music albums on kibergrad.fm"
13
+ spec.description = "find and download music albums on kibergrad.fm"
14
14
  spec.license = "GPL-3.0"
15
15
  spec.homepage = "https://github.com/vitvegl/kgmusic.git"
16
16
 
data/lib/kgmusic.rb CHANGED
@@ -10,37 +10,30 @@ module KgMusic
10
10
  include BaseMod
11
11
 
12
12
  attr_reader :artist, :album
13
- attr_reader :result, :download_page, :direct_link
13
+ attr_reader :direct_link
14
14
 
15
- def initialize(args)
16
- keys = [:artist, :album]
17
- keys.each do |k|
18
- if args.keys === keys and args[k].is_a? String
19
- self.instance_variable_set "@#{k}", validate(args[k])
20
- else
21
- raise ArgumentError
22
- end
23
- end
15
+ def initialize(artist:, album:)
16
+ @artist = validate(artist)
17
+ @album = validate(album)
24
18
  end
25
19
 
26
20
  protected
27
21
 
28
22
  def run
29
-
30
23
  url = 'kibergrad.fm/search'
31
- params = { :q => "#{@artist} - #{@album}", :p => "albums" }
24
+ params = { :q => "#{self.artist} - #{self.album}", :p => "albums" }
32
25
  album_info = get_album_info url, params
33
26
 
34
27
  unless album_info.nil?
35
28
  begin
36
29
  if album_info.size == 1
37
- @download_page = album_info.css('h3').at('a').attr('href')
30
+ download_page = album_info.css('h3').at('a').attr('href')
38
31
  elsif album_info.size > 1
39
32
  full_match_index = album_info.css('h3').find_index { |e| e.at('a').children.to_s === @album }
40
- @result = album_info.css('h3')[full_match_index]
41
- @download_page = @result.at('a').attr('href')
33
+ result = album_info.css('h3')[full_match_index]
34
+ download_page = result.at('a').attr('href')
42
35
  end
43
- get_direct_link @download_page
36
+ get_direct_link download_page
44
37
  rescue
45
38
  end
46
39
  end
@@ -48,23 +41,26 @@ module KgMusic
48
41
 
49
42
  def get_album
50
43
 
44
+ app_root = File.join(ENV['HOME'], 'kgmusic')
51
45
  url = obtain_final_url @direct_link
52
- outfile = File.join(ENV['HOME'], "#{@artist} - #{@album}.zip")
46
+ Dir.mkdir(app_root, 0700) unless Dir.exist?(app_root)
47
+ outfile = File.join(app_root, "#{self.artist} - #{self.album}.zip")
53
48
  content_length = get_content_length url
54
49
 
55
50
  begin
56
- f = File.open(outfile, 'ab+')
57
- fsize = File.size outfile
58
- c = Curl::Easy.new url do |curl|
59
- curl.set(:resume_from, fsize) if fsize > 0
60
- curl.on_body { |body| f.write body }
51
+ File.open(outfile, 'ab+') do |f|
52
+ fsize = File.size(outfile)
53
+ c = Curl::Easy.new url do |curl|
54
+ curl.set(:resume_from, fsize) if fsize > 0
55
+ curl.on_body { |body| f.write body }
56
+ end
57
+ puts "Please, wait ..."
58
+ c.perform if content_length > fsize
61
59
  end
62
- puts "Please, wait ..."
63
- c.perform if content_length > fsize
64
- rescue IOError
65
- ensure
66
- f.close
60
+ rescue => ex
61
+ puts ex.message
67
62
  end
63
+ return File.size(outfile)
68
64
  end
69
65
 
70
66
  public
@@ -28,7 +28,7 @@ module KgMusic
28
28
  end
29
29
 
30
30
  def strip_unallowed_symbols!(key)
31
- UNALLOWED_SYMBOLS.map! {|s| key.delete(s)}
31
+ UNALLOWED_SYMBOLS.map {|s| key.delete!(s)}
32
32
  end
33
33
 
34
34
  def parse_html doc
@@ -36,14 +36,18 @@ module KgMusic
36
36
  end
37
37
 
38
38
  def validate(key)
39
- strip_unallowed_symbols!(key) if has_unallowed_symbols?(key)
40
- key
41
- #words = key.split
42
- #if words.size == 1
43
- # key[0] =~ /^[[:lower:]]$/ ? titlecase(key) : key
44
- #elsif words.size > 1
45
- # words.map {|w| titlecase(w) unless (w[0].ord === w[0])}.join(" ")
46
- #end
39
+ if key.is_a? String
40
+ strip_unallowed_symbols!(key) if has_unallowed_symbols?(key)
41
+ key
42
+ #words = key.split
43
+ #if words.size == 1
44
+ # key[0] =~ /^[[:lower:]]$/ ? titlecase(key) : key
45
+ #elsif words.size > 1
46
+ # words.map {|w| titlecase(w) unless (w[0].ord === w[0])}.join(" ")
47
+ #end
48
+ else
49
+ raise KeyError
50
+ end
47
51
  end
48
52
 
49
53
  def parse_http_header str
@@ -1,3 +1,3 @@
1
1
  module KgMusic
2
- VERSION = "0.1.0pre20160524"
2
+ VERSION = "0.1.0pre20160525"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kgmusic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0pre20160524
4
+ version: 0.1.0pre20160525
5
5
  platform: ruby
6
6
  authors:
7
7
  - vitvegl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-24 00:00:00.000000000 Z
11
+ date: 2016-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: curb
@@ -92,7 +92,7 @@ dependencies:
92
92
  - - "~>"
93
93
  - !ruby/object:Gem::Version
94
94
  version: '3.0'
95
- description: find music albums on kibergrad.fm
95
+ description: find and download music albums on kibergrad.fm
96
96
  email:
97
97
  - vitvelg@gmail.com
98
98
  executables: []
@@ -137,5 +137,5 @@ rubyforge_project:
137
137
  rubygems_version: 2.5.1
138
138
  signing_key:
139
139
  specification_version: 4
140
- summary: Find music albums on kibergrad.fm
140
+ summary: find and download music albums on kibergrad.fm
141
141
  test_files: []