summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOmar Roth <omarroth@hotmail.com>2017-11-28 19:59:51 -0600
committerOmar Roth <omarroth@hotmail.com>2017-11-28 19:59:51 -0600
commit7feec0c00dff72378fd80723c16d52803c6d882c (patch)
tree83167ab541d75623ad5df4dd36a3be4fb6258d26 /src
parentf9f20f4af02aa06fe307b955ce2c8c496580bd8a (diff)
downloadinvidious-7feec0c00dff72378fd80723c16d52803c6d882c.tar.gz
invidious-7feec0c00dff72378fd80723c16d52803c6d882c.tar.bz2
invidious-7feec0c00dff72378fd80723c16d52803c6d882c.zip
Add engagement rating, rating, likes, dislikes, and form of logging (primitive but in the hope of reverse-engineering requests)
Diffstat (limited to 'src')
-rw-r--r--src/visor.cr90
1 files changed, 30 insertions, 60 deletions
diff --git a/src/visor.cr b/src/visor.cr
index 77e7e170..1b9a9b2d 100644
--- a/src/visor.cr
+++ b/src/visor.cr
@@ -3,93 +3,63 @@ require "json"
require "kemal"
require "pg"
require "xml"
+require "./url_encoded"
macro templated(filename)
render "views/#{{{filename}}}.ecr", "views/layout.ecr"
end
-# pg = DB.open("postgres://kemal@visor/dev")
-
-alias Type = String | Hash(String, Type)
-
-def object_to_hash(value)
- object = {} of String => Type
- items = value.split("&")
- items.each do |item|
- key, value = item.split("=")
- value = URI.unescape(value)
- object[key] = parse_uri(value)
- end
- return object
-end
-
-def array_to_hash(value)
- array = {} of String => Type
- items = value.split(",")
- count = 0
- items.each do |item|
- array[count.to_s] = parse_uri(item)
- count += 1
- end
- return array
-end
-
-def parse_uri(value)
- if value.starts_with?("http") || value.starts_with?("[")
- return value
- else
- if value.includes?(",")
- return array_to_hash(value)
- elsif value.includes?("&")
- return object_to_hash(value)
- else
- return value
- end
- end
-end
-
context = OpenSSL::SSL::Context::Client.insecure
-client = HTTP::Client.new("www.youtube.com", 443, context)
+fmt_file = File.open("temp/fmt_stream")
get "/" do |env|
templated "index"
end
+
get "/watch/:video_id" do |env|
video_id = env.params.url["video_id"]
- video_info_encoded = HTTP::Client.get("https://www.youtube.com/get_video_info?video_id=#{video_id}&el=info&ps=default&eurl=&gl=US&hl=en", nil, nil, tls = context).body
- video_info = object_to_hash(video_info_encoded)
- body = client.get("/watch?v=#{video_id}").body
- doc = XML.parse(body)
+ client = HTTP::Client.new("www.youtube.com", 443, context)
+ video_info = client.get("/get_video_info?video_id=#{video_id}&el=info&ps=default&eurl=&gl=US&hl=en").body
+ video_info = HTTP::Params.parse(video_info)
+ pageContent = client.get("/watch?v=#{video_id}").body
+ doc = XML.parse(pageContent)
+
+ fmt_stream = [] of HTTP::Params
+ video_info["url_encoded_fmt_stream_map"].split(",") do |string|
+ fmt_stream << HTTP::Params.parse(string)
+ end
+ File.write("temp/#{video_id}", video_info)
+ File.write("temp/#{video_id}_manifest", video_info["dashmpd"])
+ File.open("temp/#{video_id}_fmt_stream_0", "a+").puts fmt_stream[0]["url"]
+ File.open("temp/#{video_id}_fmt_stream_1", "a+").puts fmt_stream[1]["url"]
+ File.open("temp/#{video_id}_fmt_stream_2", "a+").puts fmt_stream[2]["url"]
+ File.open("temp/#{video_id}_fmt_stream_3", "a+").puts fmt_stream[3]["url"]
+ fmt_stream.reverse! # We want lowest quality first
+ # css query [title="I like this"] > span
likes = doc.xpath_node(%q(//button[@title="I like this"]/span))
if likes
- likes = likes.content
+ likes = likes.content.delete(",").to_i
else
- likes = "n/a"
+ likes = 1
end
-
+
+ # css query [title="I dislike this"] > span
dislikes = doc.xpath_node(%q(//button[@title="I dislike this"]/span))
if dislikes
- dislikes.content
+ dislikes = dislikes.content.delete(",").to_i
else
- dislikes = "n/a"
+ dislikes = 1
end
- File.write("video_info/#{video_id}", video_info.to_json)
+ engagement = ((dislikes.to_f32 + likes.to_f32)*100 / video_info["view_count"].to_i).to_i
+ calculated_rating = likes.to_f32/(likes.to_f32 + dislikes.to_f32)*4 + 1
+
templated "watch"
end
-# get "/listen/:video_id" do |env|
-# video_id = env.params.url["video_id"]
-
-# video_info_encoded = HTTP::Client.get("https://www.youtube.com/get_video_info?video_id=#{video_id}&el=info&ps=default&eurl=&gl=US&hl=en", nil, nil, tls = context).body
-# video_info = object_to_hash(video_info_encoded)
-# File.write("video_info/#{video_id}", video_info.to_json)
-# templated "listen"
-# end
-
public_folder "assets"
Kemal.run