Class: Myshazam::Track
- Inherits:
-
Struct
- Object
- Struct
- Myshazam::Track
- Defined in:
- lib/myshazam.rb
Instance Attribute Summary collapse
-
#author ⇒ Object
Returns the value of attribute author.
-
#shazam_id ⇒ Object
Returns the value of attribute shazam_id.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#author ⇒ Object
Returns the value of attribute author
5 6 7 |
# File 'lib/myshazam.rb', line 5 def @author end |
#shazam_id ⇒ Object
Returns the value of attribute shazam_id
5 6 7 |
# File 'lib/myshazam.rb', line 5 def shazam_id @shazam_id end |
#title ⇒ Object
Returns the value of attribute title
5 6 7 |
# File 'lib/myshazam.rb', line 5 def title @title end |
Class Method Details
.list_from_file(download_file) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/myshazam.rb', line 8 def list_from_file download_file ids = [] doc = Nokogiri::HTML(File.open(download_file, "r:utf-8")) doc.xpath("//table/tr").map.with_index do |tr, i| next if i == 0 # Skip header # Find shazam id, don't parse return duplicates link = tr.xpath("./td/a").first shazam_id = Regexp.last_match[1].to_i if link.attributes["href"].to_s.strip =~ /t(\d+)$/ if ids.include? shazam_id; next; else ids.push(shazam_id); end Track.new( tr.children.first.content.to_s.strip, # Title tr.xpath("./td[position()=2]").first.content.to_s.strip, # Author shazam_id ) end.compact end |
Instance Method Details
#magnet ⇒ Object
43 44 45 |
# File 'lib/myshazam.rb', line 43 def magnet @magnet ||= magnet_from_piratebay end |
#magnet_from_piratebay ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/myshazam.rb', line 33 def magnet_from_piratebay begin search_url = "http://thepiratebay.se/search/%s" % URI::encode(to_s) doc = Nokogiri::HTML open(search_url) doc.xpath("//a[starts-with(@href,'magnet')]").first.attributes["href"].to_s rescue nil end end |
#to_s ⇒ Object
29 30 31 |
# File 'lib/myshazam.rb', line 29 def to_s [self., self.title].compact.join(" ").strip end |