VRFS-3007 : Fix faulty logic when extracting recording data. Addresses a few test failures.
This commit is contained in:
parent
86c483a0d5
commit
d4d8489ef1
|
|
@ -18,9 +18,8 @@ class Utils
|
|||
case site
|
||||
when 'rec_youtube'
|
||||
# regex derived from: https://gist.github.com/afeld/1254889
|
||||
if recording_url =~ /(youtu.be\/|youtube.com\/(watch\?(.*&)?v=|(embed|v)\/))([^\?&\"\'>]+)/
|
||||
rec_data["id"] = $5
|
||||
end
|
||||
watch = (recording_url =~ /(youtu.be\/|youtube.com\/(watch\?(.*&)?v=|(embed|v)\/))([^\?&\"\'>]+)/)
|
||||
rec_data["id"] = $5 if watch
|
||||
|
||||
uri = URI.parse("https://gdata.youtube.com/feeds/api/videos/#{$5}?v=2&alt=json")
|
||||
|
||||
|
|
@ -28,9 +27,14 @@ class Utils
|
|||
http.use_ssl = true if uri.scheme == 'https'
|
||||
req = Net::HTTP::Get.new(uri)
|
||||
response = http.request(req)
|
||||
json = JSON.parse(response.body) if response
|
||||
rec_data["title"] = json["entry"]["title"]["$t"]
|
||||
return rec_data unless rec_data.empty?
|
||||
if response && response.body.length > 2
|
||||
json = response.body.force_encoding("UTF-8")# .encode('UTF-8', :invalid => :replace, :replace => '')
|
||||
json_hash = JSON.parse(json)
|
||||
|
||||
if watch && json_hash["entry"] && json_hash["entry"]["title"]
|
||||
rec_data["title"] = json_hash["entry"]["title"]["$t"]
|
||||
end
|
||||
end
|
||||
|
||||
when 'rec_soundcloud'
|
||||
if recording_url =~ /^https?:\/\/.*soundcloud.com\/.+/
|
||||
|
|
@ -46,11 +50,10 @@ class Utils
|
|||
|
||||
if result =~ /property=\"og:title\" content=\"([\w\W]+)\"><meta property=\"og:image\"/
|
||||
rec_data["title"] = $1
|
||||
end
|
||||
return rec_data unless rec_data.empty?
|
||||
end
|
||||
end
|
||||
end
|
||||
nil
|
||||
rec_data.empty? ? nil : rec_data
|
||||
end
|
||||
|
||||
def self.username_url(username, site)
|
||||
|
|
|
|||
Loading…
Reference in New Issue