getLinkMp3Zing 0.0.1 → 0.0.3

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: dbf754a3ccd08cfd6d2085e409a9a9f3eec87bf5
4
- data.tar.gz: cdfb17ae13f005cbcedc37fd2fe3a08904f86fca
3
+ metadata.gz: e61d759c07d4b426c7c40c65ce3b45cda5dea660
4
+ data.tar.gz: 0c6f930216c5eddfdd09a16e7ec13c982db686b3
5
5
  SHA512:
6
- metadata.gz: 2dad3cc6f953724318ff511233cb228b7b7db712d2d456d4dd7e74d0274c5a15083fa9881fd0786c060ef02e613b90d096f565a0188abf562b529a42085655c0
7
- data.tar.gz: e15f78bfa7453959a0287183b9f2aadf994f680160118050afd8007a8e1db67c101a2ba4b1c696e897d2fbc3e047b494cc88f09b9ea71c096325ef0e790ea82c
6
+ metadata.gz: 30ffa4a4a93a106ba1e2288b5d978a9e1324fb85ff5f3b4015687c4b9c944b453dbc2641e693ba6f447d4877e1b90e197140c381bd6808b34aa8ca0e629b00b6
7
+ data.tar.gz: c024181f00fbefdbed588b3397aa82f6c9363e86c0812f1e5eb2cb7206b92ce04773945ed33b2b1c16c8bb344af05a1522e8d10ef03241f35d791ddd259fdfb6
@@ -3,16 +3,48 @@ require 'nokogiri'
3
3
 
4
4
  class ToolGetLink
5
5
  def initialize(link)
6
- @link = link
6
+ if (checkLink(link) == true)
7
+ @link = link
8
+ end
9
+ end
10
+
11
+ def checkLink(link)
12
+ if (link.empty?)
13
+ return false
14
+ elsif(link.slice(0..26) != "http://mp3.zing.vn/bai-hat/")
15
+ return false
16
+ elsif (!link.end_with?(".html"))
17
+ return false
18
+ end
19
+ return true
20
+ end
21
+
22
+ def getLink
23
+ @link
7
24
  end
8
25
 
9
26
  def getLinkToXMLPage
10
- content = Nokogiri::XML(open(@link))
11
- return content.css("#html5player @data-xml").text
27
+ if (@link != nil)
28
+ content = Nokogiri::XML(open(@link))
29
+ return content.css("#html5player @data-xml").text
30
+ else
31
+ return nil
32
+ end
12
33
  end
13
34
 
14
35
  def getLinkDownload
15
- contentXML = Nokogiri::XML(open(getLinkToXMLPage()))
16
- return contentXML.css("source").text
36
+ if(@link != nil)
37
+ contentXML = Nokogiri::XML(open(getLinkToXMLPage()))
38
+ return contentXML.css("source").text
39
+ else
40
+ return nil
41
+ end
17
42
  end
18
43
  end
44
+
45
+ # tool = ToolGetLink.new("http://mp3.zing.vn/bai-hat/Tam-Su-Voi-Nguoi-La-Tien-Cookie/ZW7O6UDW.html")
46
+ # tool = ToolGetLink.new("http://mp3.zing.vn/bai-hatTam-Su-Voi-Nguoi-La-Tien-Cookie/ZW7O6UDW.html")
47
+ # tool.checkLink("http://mp3.zing.vn/bai-hatTam-Su-Voi-Nguoi-La-Tien-Cookie/ZW7O6UDW.html")
48
+ # puts tool.getLink
49
+ tool = ToolGetLink.new("http://mp3.zing.vn/bai-hat/Tam-Su-Voi-Nguoi-La-Tien-Cookie/ZW7O6UDW.html")
50
+ puts tool.getLinkDownload
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: getLinkMp3Zing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bui Thanh Tung
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-04 00:00:00.000000000 Z
11
+ date: 2016-04-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: get link download song form url of mp3.zing.vn
14
14
  email: tungbt94@gmail.com
@@ -16,7 +16,6 @@ executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
- - lib/getLink/ToolGetLink.rb
20
19
  - lib/getLinkMp3Zing.rb
21
20
  homepage: http://rubygems.org/gems/getLinkMp3Zing
22
21
  licenses:
@@ -1,33 +0,0 @@
1
- require 'json'
2
- require 'net/http'
3
-
4
- class Tool
5
- def initialize (link)
6
- @link = link
7
- end
8
-
9
- def getID
10
- idStart = @link.rindex('/') + 1
11
- idEnd = @link.rindex('.html')
12
- id = @link[idStart..idEnd-1]
13
- return id
14
- end
15
-
16
- def getUrl
17
- id = getID
18
- apiUrl = "http://api.mp3.zing.vn/api/mobile/song/getsonginfo?requestdata={\"id\":\"#{id}\"}"
19
- return apiUrl
20
- end
21
-
22
- def getJson
23
- uri = URI(getUrl())
24
- content = Net::HTTP.get(uri)
25
- json = JSON.parse(content)
26
- return json
27
- end
28
-
29
- def getLinkDownload
30
- hash = getJson()['link_download']
31
- hash.each {|key, value| puts "#{key}: #{value}"}
32
- end
33
- end