File weight calculator
This commit is contained in:
parent
1494e81fa7
commit
135f10d73a
|
@ -8,7 +8,8 @@ module Vkontakte
|
||||||
def self.get artist, track, length
|
def self.get artist, track, length
|
||||||
#html = self.getHtml artist +' - '+ track
|
#html = self.getHtml artist +' - '+ track
|
||||||
files = self.parseHtml 1 #html
|
files = self.parseHtml 1 #html
|
||||||
files = self.calcWeight files
|
files = self.calcWeight files, artist, track, length
|
||||||
|
self.stream files.first['url']
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,13 +59,37 @@ module Vkontakte
|
||||||
'url' => item[0],
|
'url' => item[0],
|
||||||
'length' => (t[0].to_i * 60) + t[1].to_i,
|
'length' => (t[0].to_i * 60) + t[1].to_i,
|
||||||
'artist' => item[2],
|
'artist' => item[2],
|
||||||
'title' => item[3].gsub(/<\/?span>/, '')
|
'track' => item[3].gsub(/<\/?.*?>/, '')
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
files
|
files
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.calcWeight files
|
def self.calcWeight files, artist, track, length
|
||||||
pp files
|
files.each do |file|
|
||||||
|
weight = 0
|
||||||
|
|
||||||
|
if file['artist'] == artist then weight += 10 else
|
||||||
|
if file['artist'].include? artist then weight += 5 else
|
||||||
|
if file['track'].include? artist then weight += 4
|
||||||
|
end end end
|
||||||
|
|
||||||
|
if file['track'] == track then weight += 10 else
|
||||||
|
if file['track'].include? track then weight += 5
|
||||||
|
end end
|
||||||
|
|
||||||
|
if file['length'] == length then weight +=10 else
|
||||||
|
delta = (length - file['length']).abs
|
||||||
|
if delta < 5 then weight += (5 - delta) end
|
||||||
|
end
|
||||||
|
|
||||||
|
file['weight'] = weight
|
||||||
|
end
|
||||||
|
|
||||||
|
files.sort_by{|file| file['weight']}.reverse
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.stream url
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
Reference in New Issue