Compare commits

..

30 Commits
0.1.0 ... 0.2.0

Author SHA1 Message Date
76d3abb5f9 Make view extractor more robust 2018-08-20 19:25:12 -05:00
deb4b06ea0 Fix playlist view extractor 2018-08-20 10:25:05 -05:00
4725f7222b Fix description in video API endpoint 2018-08-20 10:07:50 -05:00
16c7d99dd8 Fix channel feeds 2018-08-18 18:38:33 -05:00
55f8fd0b58 Add note for livestreams that haven't started 2018-08-18 11:47:16 -05:00
1611ee83a6 Remove preload directive 2018-08-18 10:05:04 -05:00
567b9f31f3 Add fix for livestreams in search results 2018-08-17 16:08:07 -05:00
6bb747b579 Fix comment replies 2018-08-17 13:03:25 -05:00
9a15438c71 Minor formatting changes 2018-08-17 11:04:38 -05:00
4760b3c6e7 Merge pull request #116 from omarroth/add-playlists
Add playlist page and endpoint
2018-08-17 11:01:36 -05:00
9e68df965b Add 'view channel on Youtube' link 2018-08-17 10:57:08 -05:00
3ba2a7d921 Fix referers 2018-08-17 10:19:20 -05:00
71aa4d0347 Replace duplicate link to YouTube 2018-08-17 09:25:47 -05:00
bb0b60e575 Add playlist page and endpoint 2018-08-16 14:26:16 -05:00
fa2ba807a3 Remove 'engage types' 2018-08-16 13:11:38 -05:00
bce01cba32 Add fix for videos without metadata 2018-08-16 09:05:48 -05:00
ec399f5f7b Properly filter movies, playlists, channels from search results 2018-08-16 08:47:51 -05:00
7c63c759f4 Add donation links to footer 2018-08-15 20:36:21 -05:00
b72f3c2274 Rename 'layout' to 'template' 2018-08-15 20:31:47 -05:00
74cf3d18d0 Remove ID constrant for users 2018-08-15 19:30:13 -05:00
8adb4650a0 Add support for multiple sessions 2018-08-15 12:40:42 -05:00
45ce301bd2 Fix reply count extraction 2018-08-15 11:47:37 -05:00
d9ea8e413e Bump size of comment author thumbnail 2018-08-14 19:48:53 -05:00
2cedac8c58 Don't show 'next page' or 'previous page' where not applicable 2018-08-14 19:15:33 -05:00
c5bd5e6c6d Fix produce_playlist_url 2018-08-14 17:00:35 -05:00
7dfb301858 Sort engage types 2018-08-14 14:04:43 -05:00
f26e9313ff Add ability to decrypt port numbers for proxy list 2018-08-14 13:22:39 -05:00
1409160ee6 Fix typo in shard.yml 2018-08-14 12:29:27 -05:00
6e434409a0 Update to Crystal 0.26.0 2018-08-14 09:41:03 -05:00
3833366756 Change options to provide more proxies 2018-08-14 09:40:52 -05:00
24 changed files with 578 additions and 186 deletions

View File

@ -4,7 +4,7 @@
CREATE TABLE public.users CREATE TABLE public.users
( (
id text COLLATE pg_catalog."default" NOT NULL, id text[] COLLATE pg_catalog."default" NOT NULL,
updated timestamp with time zone, updated timestamp with time zone,
notifications text[] COLLATE pg_catalog."default", notifications text[] COLLATE pg_catalog."default",
subscriptions text[] COLLATE pg_catalog."default", subscriptions text[] COLLATE pg_catalog."default",
@ -13,8 +13,7 @@ CREATE TABLE public.users
password text COLLATE pg_catalog."default", password text COLLATE pg_catalog."default",
token text COLLATE pg_catalog."default", token text COLLATE pg_catalog."default",
watched text[] COLLATE pg_catalog."default", watched text[] COLLATE pg_catalog."default",
CONSTRAINT users_email_key UNIQUE (email), CONSTRAINT users_email_key UNIQUE (email)
CONSTRAINT users_id_key UNIQUE (id)
) )
WITH ( WITH (
OIDS = FALSE OIDS = FALSE

View File

@ -11,14 +11,11 @@ targets:
dependencies: dependencies:
kemal: kemal:
github: kemalcr/kemal github: kemalcr/kemal
branch: rework-param-parser
pg: pg:
github: will/crystal-pg github: will/crystal-pg
branch: master
detect_language: detect_language:
github: detectlanguage/detectlanguage-crystal github: detectlanguage/detectlanguage-crystal
branch: master
crystal: 0.25.1 crystal: 0.26.0
license: AGPLv3 license: AGPLv3

View File

@ -114,10 +114,11 @@ before_all do |env|
# Invidious users only have SID # Invidious users only have SID
if !env.request.cookies.has_key? "SSID" if !env.request.cookies.has_key? "SSID"
user = PG_DB.query_one?("SELECT * FROM users WHERE id = $1", sid, as: User) user = PG_DB.query_one?("SELECT * FROM users WHERE $1 = ANY(id)", sid, as: User)
if user if user
env.set "user", user env.set "user", user
env.set "sid", sid
end end
else else
begin begin
@ -125,10 +126,24 @@ before_all do |env|
user = get_user(sid, client, headers, PG_DB, false) user = get_user(sid, client, headers, PG_DB, false)
env.set "user", user env.set "user", user
env.set "sid", sid
rescue ex rescue ex
end end
end end
end end
current_page = env.request.path
if env.request.query
query = HTTP::Params.parse(env.request.query.not_nil!)
if query["referer"]?
query["referer"] = get_referer(env, "/")
end
current_page += "?#{query}"
end
env.set "current_page", URI.escape(current_page)
end end
get "/" do |env| get "/" do |env|
@ -264,10 +279,11 @@ get "/watch" do |env|
rating = video.info["avg_rating"].to_f64 rating = video.info["avg_rating"].to_f64
engagement = ((video.dislikes.to_f + video.likes.to_f)/video.views * 100) engagement = ((video.dislikes.to_f + video.likes.to_f)/video.views * 100)
if video.info["enabled_engage_types"]? playability_status = video.player_response["playabilityStatus"]?
engage_types = video.info["enabled_engage_types"].split(",") if playability_status && playability_status["status"] == "LIVE_STREAM_OFFLINE"
engage_types = engage_types.join(", ") reason = playability_status["reason"]?.try &.as_s
end end
reason ||= ""
templated "watch" templated "watch"
end end
@ -358,6 +374,31 @@ get "/embed/:id" do |env|
rendered "embed" rendered "embed"
end end
# Playlists
get "/playlist" do |env|
plid = env.params.query["list"]?
if !plid
next env.redirect "/"
end
page = env.params.query["page"]?.try &.to_i?
page ||= 1
if plid
begin
videos = extract_playlist(plid, page)
rescue ex
error_message = ex.message
next templated "error"
end
playlist = fetch_playlist(plid)
else
next env.redirect "/"
end
templated "playlist"
end
# Search # Search
get "/results" do |env| get "/results" do |env|
@ -414,8 +455,7 @@ end
# See https://github.com/rg3/youtube-dl/blob/master/youtube_dl/extractor/youtube.py#L79 # See https://github.com/rg3/youtube-dl/blob/master/youtube_dl/extractor/youtube.py#L79
post "/login" do |env| post "/login" do |env|
referer = env.params.query["referer"]? referer = get_referer(env, "/feed/subscriptions")
referer ||= get_referer(env, "/feed/subscriptions")
email = env.params.body["email"]? email = env.params.body["email"]?
password = env.params.body["password"]? password = env.params.body["password"]?
@ -509,7 +549,7 @@ post "/login" do |env|
end end
if !tfa_code if !tfa_code
next env.redirect "/login?tfa=true&type=google" next env.redirect "/login?tfa=true&type=google&referer=#{URI.escape(referer)}"
end end
tl = challenge_results[1][2] tl = challenge_results[1][2]
@ -621,8 +661,8 @@ post "/login" do |env|
end end
if Crypto::Bcrypt::Password.new(user.password.not_nil!) == password if Crypto::Bcrypt::Password.new(user.password.not_nil!) == password
sid = Base64.encode(Random::Secure.random_bytes(50)) sid = Base64.urlsafe_encode(Random::Secure.random_bytes(32))
PG_DB.exec("UPDATE users SET id = $1 WHERE email = $2", sid, email) PG_DB.exec("UPDATE users SET id = id || $1 WHERE email = $2", [sid], email)
if Kemal.config.ssl || CONFIG.https_only if Kemal.config.ssl || CONFIG.https_only
secure = true secure = true
@ -643,7 +683,7 @@ post "/login" do |env|
next templated "error" next templated "error"
end end
sid = Base64.encode(Random::Secure.random_bytes(50)) sid = Base64.urlsafe_encode(Random::Secure.random_bytes(32))
user = create_user(sid, email, password) user = create_user(sid, email, password)
user_array = user.to_a user_array = user.to_a
@ -673,8 +713,14 @@ get "/signout" do |env|
cookie.expires = Time.new(1990, 1, 1) cookie.expires = Time.new(1990, 1, 1)
end end
if env.get? "user"
user = env.get("user").as(User)
sid = env.get("sid").as(String)
PG_DB.exec("UPDATE users SET id = array_remove(id, $1) WHERE email = $2", sid, user.email)
end
env.request.cookies.add_response_headers(env.response.headers) env.request.cookies.add_response_headers(env.response.headers)
env.redirect referer env.redirect URI.unescape(referer)
end end
get "/preferences" do |env| get "/preferences" do |env|
@ -865,7 +911,7 @@ get "/subscription_manager" do |env|
headers["Cookie"] = env.request.headers["Cookie"] headers["Cookie"] = env.request.headers["Cookie"]
client = make_client(YT_URL) client = make_client(YT_URL)
user = get_user(user.id, client, headers, PG_DB) user = get_user(user.id[0], client, headers, PG_DB)
end end
action_takeout = env.params.query["action_takeout"]?.try &.to_i? action_takeout = env.params.query["action_takeout"]?.try &.to_i?
@ -1173,7 +1219,7 @@ get "/feed/subscriptions" do |env|
if !user.password if !user.password
client = make_client(YT_URL) client = make_client(YT_URL)
user = get_user(user.id, client, headers, PG_DB) user = get_user(user.id[0], client, headers, PG_DB)
end end
max_results = preferences.max_results max_results = preferences.max_results
@ -1340,7 +1386,7 @@ get "/feed/channel/:ucid" do |env|
end end
nodeset = document.xpath_nodes(%q(//li[contains(@class, "feed-item-container")])) nodeset = document.xpath_nodes(%q(//li[contains(@class, "feed-item-container")]))
extract_videos(nodeset).each do |video| extract_videos(nodeset, ucid).each do |video|
xml.element("entry") do xml.element("entry") do
xml.element("id") { xml.text "yt:video:#{video.id}" } xml.element("id") { xml.text "yt:video:#{video.id}" }
xml.element("yt:videoId") { xml.text video.id } xml.element("yt:videoId") { xml.text video.id }
@ -1519,31 +1565,13 @@ get "/channel/:ucid" do |env|
rss = XML.parse_html(rss.body) rss = XML.parse_html(rss.body)
author = rss.xpath_node("//feed/author/name").not_nil!.content author = rss.xpath_node("//feed/author/name").not_nil!.content
url = produce_playlist_url(ucid, (page - 1) * 100) begin
response = client.get(url) videos = extract_playlist(ucid, page)
response = JSON.parse(response.body) rescue ex
error_message = ex.message
if !response["content_html"]?
error_message = "This channel does not exist."
next templated "error" next templated "error"
end end
document = XML.parse_html(response["content_html"].as_s)
anchor = document.xpath_node(%q(//div[@class="pl-video-owner"]/a))
if !anchor
videos = [] of ChannelVideo
next templated "channel"
end
videos = [] of ChannelVideo
document.xpath_nodes(%q(//a[contains(@class,"pl-video-title-link")])).each do |node|
href = URI.parse(node["href"])
id = HTTP::Params.parse(href.query.not_nil!)["v"]
title = node.content
videos << ChannelVideo.new(id, title, Time.now, Time.now, "", "")
end
templated "channel" templated "channel"
end end
@ -1682,7 +1710,7 @@ get "/api/v1/comments/:id" do |env|
if format == "json" if format == "json"
next {"comments" => [] of String}.to_json next {"comments" => [] of String}.to_json
else else
next {"content_html" => ""}.to_json next {"contentHtml" => ""}.to_json
end end
end end
ctoken = ctoken["ctoken"] ctoken = ctoken["ctoken"]
@ -1720,7 +1748,7 @@ get "/api/v1/comments/:id" do |env|
if format == "json" if format == "json"
next {"comments" => [] of String}.to_json next {"comments" => [] of String}.to_json
else else
next {"content_html" => ""}.to_json next {"contentHtml" => ""}.to_json
end end
end end
@ -1785,9 +1813,13 @@ get "/api/v1/comments/:id" do |env|
json.field "commentId", node_comment["commentId"] json.field "commentId", node_comment["commentId"]
if node_replies && !response["commentRepliesContinuation"]? if node_replies && !response["commentRepliesContinuation"]?
reply_count = node_replies["moreText"]["simpleText"].as_s.match(/View all (?<count>\d+) replies/) reply_count = node_replies["moreText"]["simpleText"].as_s.delete("View all reply replies,")
.try &.["count"].to_i? if reply_count.empty?
reply_count = 1
else
reply_count = reply_count.try &.to_i?
reply_count ||= 1 reply_count ||= 1
end
continuation = node_replies["continuations"].as_a[0]["nextContinuationData"]["continuation"].as_s continuation = node_replies["continuations"].as_a[0]["nextContinuationData"]["continuation"].as_s
@ -1816,7 +1848,17 @@ get "/api/v1/comments/:id" do |env|
comments = JSON.parse(comments) comments = JSON.parse(comments)
content_html = template_youtube_comments(comments) content_html = template_youtube_comments(comments)
next {"content_html" => content_html}.to_json response = JSON.build do |json|
json.object do
json.field "contentHtml", content_html
if comments["commentCount"]?
json.field "commentCount", comments["commentCount"]
end
end
end
next response
end end
elsif source == "reddit" elsif source == "reddit"
client = make_client(REDDIT_URL) client = make_client(REDDIT_URL)
@ -1839,7 +1881,8 @@ get "/api/v1/comments/:id" do |env|
env.response.content_type = "application/json" env.response.content_type = "application/json"
next {"title" => reddit_thread.title, next {"title" => reddit_thread.title,
"permalink" => reddit_thread.permalink, "permalink" => reddit_thread.permalink,
"content_html" => content_html}.to_json "contentHtml" => content_html,
}.to_json
end end
end end
@ -1868,7 +1911,7 @@ get "/api/v1/videos/:id" do |env|
generate_thumbnails(json, video.id) generate_thumbnails(json, video.id)
end end
description = html_to_description(video.description) description, video.description = html_to_description(video.description)
json.field "description", description json.field "description", description
json.field "descriptionHtml", video.description json.field "descriptionHtml", video.description
@ -2343,6 +2386,65 @@ get "/api/v1/search" do |env|
response response
end end
get "/api/v1/playlists/:plid" do |env|
plid = env.params.url["plid"]
page = env.params.query["page"]?.try &.to_i?
page ||= 1
begin
videos = extract_playlist(plid, page)
rescue ex
env.response.content_type = "application/json"
response = {"error" => "Playlist is empty"}.to_json
halt env, status_code: 404, response: response
end
playlist = fetch_playlist(plid)
response = JSON.build do |json|
json.object do
json.field "title", playlist.title
json.field "id", playlist.id
json.field "author", playlist.author
json.field "authorId", playlist.ucid
json.field "authorUrl", "/channel/#{playlist.ucid}"
json.field "description", playlist.description
json.field "videoCount", playlist.video_count
json.field "viewCount", playlist.views
json.field "updated", playlist.updated.epoch
json.field "videos" do
json.array do
videos.each do |video|
json.object do
json.field "title", video.title
json.field "id", video.id
json.field "author", video.author
json.field "authorId", video.ucid
json.field "authorUrl", "/channel/#{video.ucid}"
json.field "videoThumbnails" do
generate_thumbnails(json, video.id)
end
json.field "index", video.index
json.field "lengthSeconds", video.length_seconds
end
end
end
end
end
end
env.response.content_type = "application/json"
response
end
get "/api/manifest/dash/id/videoplayback" do |env| get "/api/manifest/dash/id/videoplayback" do |env|
env.response.headers["Access-Control-Allow-Origin"] = "*" env.response.headers["Access-Control-Allow-Origin"] = "*"
env.redirect "/videoplayback?#{env.params.query}" env.redirect "/videoplayback?#{env.params.query}"
@ -2611,10 +2713,6 @@ if Kemal.config.ssl
server.bind_tcp "0.0.0.0", 80 server.bind_tcp "0.0.0.0", 80
server.listen server.listen
end end
before_all do |env|
env.response.headers.add("Strict-Transport-Security", "max-age=31536000; includeSubDomains; preload")
end
end end
static_headers do |response, filepath, filestat| static_headers do |response, filepath, filestat|

View File

@ -103,7 +103,7 @@ def template_youtube_comments(comments)
html += <<-END_HTML html += <<-END_HTML
<div class="pure-g"> <div class="pure-g">
<div class="pure-u-2-24"> <div class="pure-u-2-24">
<img style="width:90%; padding-right:1em; padding-top:1em;" src="#{child["authorThumbnails"][0]["url"]}"> <img style="width:90%; padding-right:1em; padding-top:1em;" src="#{child["authorThumbnails"][-1]["url"]}">
</div> </div>
<div class="pure-u-22-24"> <div class="pure-u-22-24">
<p> <p>
@ -262,7 +262,7 @@ def fill_links(html, scheme, host)
end end
if host == "www.youtube.com" if host == "www.youtube.com"
html = html.xpath_node(%q(//p[@id="eow-description"])).not_nil!.to_xml html = html.xpath_node(%q(//body)).not_nil!.to_xml
else else
html = html.to_xml(options: XML::SaveOptions::NO_DECL) html = html.to_xml(options: XML::SaveOptions::NO_DECL)
end end

View File

@ -116,39 +116,6 @@ def login_req(login_form, f_req)
return HTTP::Params.encode(data) return HTTP::Params.encode(data)
end end
def produce_playlist_url(ucid, index)
ucid = ucid.lchop("UC")
ucid = "VLUU" + ucid
continuation = write_var_int(index)
continuation.unshift(0x08_u8)
slice = continuation.to_unsafe.to_slice(continuation.size)
continuation = Base64.urlsafe_encode(slice, false)
continuation = "PT:" + continuation
continuation = continuation.bytes
continuation.unshift(0x7a_u8, continuation.size.to_u8)
slice = continuation.to_unsafe.to_slice(continuation.size)
continuation = Base64.urlsafe_encode(slice)
continuation = URI.escape(continuation)
continuation = continuation.bytes
continuation.unshift(continuation.size.to_u8)
continuation.unshift(ucid.size.to_u8)
continuation = ucid.bytes + continuation
continuation.unshift(0x12.to_u8, ucid.size.to_u8)
continuation.unshift(0xe2_u8, 0xa9_u8, 0x85_u8, 0xb2_u8, 2_u8, continuation.size.to_u8)
slice = continuation.to_unsafe.to_slice(continuation.size)
continuation = Base64.urlsafe_encode(slice)
continuation = URI.escape(continuation)
url = "/browse_ajax?action_continuation=1&continuation=#{continuation}"
return url
end
def produce_videos_url(ucid, page = 1) def produce_videos_url(ucid, page = 1)
page = "#{page}" page = "#{page}"
@ -268,7 +235,7 @@ def generate_captcha(key)
answer = "#{hour}:#{minute.to_s.rjust(2, '0')}" answer = "#{hour}:#{minute.to_s.rjust(2, '0')}"
token = OpenSSL::HMAC.digest(:sha256, key, answer) token = OpenSSL::HMAC.digest(:sha256, key, answer)
token = Base64.encode(token) token = Base64.urlsafe_encode(token)
return {challenge: challenge, token: token} return {challenge: challenge, token: token}
end end
@ -301,6 +268,15 @@ def extract_videos(nodeset, ucid = nil)
next next
end end
case node.xpath_node(%q(.//div)).not_nil!["class"]
when .includes? "yt-lockup-movie-vertical-poster"
next
when .includes? "yt-lockup-playlist"
next
when .includes? "yt-lockup-channel"
next
end
title = anchor.content.strip title = anchor.content.strip
id = anchor["href"].lchop("/watch?v=") id = anchor["href"].lchop("/watch?v=")
@ -317,37 +293,30 @@ def extract_videos(nodeset, ucid = nil)
author_id = anchor["href"].split("/")[-1] author_id = anchor["href"].split("/")[-1]
end end
# Skip playlists
if node.xpath_node(%q(.//div[contains(@class, "yt-playlist-renderer")]))
next
end
# Skip movies
if node.xpath_node(%q(.//div[contains(@class, "yt-lockup-movie-top-content")]))
next
end
metadata = node.xpath_nodes(%q(.//div[contains(@class,"yt-lockup-meta")]/ul/li)) metadata = node.xpath_nodes(%q(.//div[contains(@class,"yt-lockup-meta")]/ul/li))
if metadata.size == 0 if metadata.empty?
next next
elsif metadata.size == 1
if metadata[0].content.starts_with? "Starts"
view_count = 0_i64
published = Time.epoch(metadata[0].xpath_node(%q(.//span)).not_nil!["data-timestamp"].to_i64)
else
view_count = metadata[0].content.lchop("Streamed ").split(" ")[0].delete(",").to_i64
published = Time.now
end end
else
published = decode_date(metadata[0].content)
view_count = metadata[1].content.split(" ")[0] begin
if view_count == "No" published = decode_date(metadata[0].content.lchop("Streamed ").lchop("Starts "))
view_count = 0_i64 rescue ex
else
view_count = view_count.delete(",").to_i64
end end
begin
published ||= Time.epoch(metadata[0].xpath_node(%q(.//span)).not_nil!["data-timestamp"].to_i64)
rescue ex
end end
published ||= Time.now
begin
view_count = metadata[0].content.rchop(" watching").delete(",").try &.to_i64?
rescue ex
end
begin
view_count ||= metadata.try &.[1].content.delete("No views,").try &.to_i64?
rescue ex
end
view_count ||= 0_i64
description_html = node.xpath_node(%q(.//div[contains(@class, "yt-lockup-description")])) description_html = node.xpath_node(%q(.//div[contains(@class, "yt-lockup-description")]))
description, description_html = html_to_description(description_html) description, description_html = html_to_description(description_html)

View File

@ -9,7 +9,7 @@ macro add_mapping(mapping)
DB.mapping({{mapping}}) DB.mapping({{mapping}})
end end
macro templated(filename, template = "layout") macro templated(filename, template = "template")
render "src/invidious/views/#{{{filename}}}.ecr", "src/invidious/views/#{{{template}}}.ecr" render "src/invidious/views/#{{{filename}}}.ecr", "src/invidious/views/#{{{template}}}.ecr"
end end

View File

@ -98,26 +98,44 @@ def get_proxies(country_code = "US")
headers["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8" headers["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"
headers["Accept-Language"] = "Accept-Language: en-US,en;q=0.9" headers["Accept-Language"] = "Accept-Language: en-US,en;q=0.9"
headers["Host"] = "spys.one" headers["Host"] = "spys.one"
headers["Origin"] = "http://spys.one"
headers["Referer"] = "http://spys.one/free-proxy-list/#{country_code}/"
headers["Content-Type"] = "application/x-www-form-urlencoded" headers["Content-Type"] = "application/x-www-form-urlencoded"
body = { body = {
"xpp" => "2", "xpp" => "5",
"xf1" => "0", "xf1" => "0",
"xf2" => "2", "xf2" => "0",
"xf4" => "1", "xf4" => "0",
"xf5" => "1", "xf5" => "1",
} }
response = client.post("/free-proxy-list/#{country_code}/", headers, form: body) response = client.post("/free-proxy-list/#{country_code}/", headers, form: body)
response = XML.parse_html(response.body) response = XML.parse_html(response.body)
mapping = response.xpath_node(%q(.//body/script)).not_nil!.content
mapping = mapping.match(/\}\('(?<p>[^']+)',\d+,\d+,'(?<x>[^']+)'/).not_nil!
p = mapping["p"].not_nil!
x = mapping["x"].not_nil!
mapping = decrypt_port(p, x)
proxies = [] of {ip: String, port: Int32, score: Float64} proxies = [] of {ip: String, port: Int32, score: Float64}
response = response.xpath_nodes(%q(//table))[1] response = response.xpath_node(%q(//tr/td/table)).not_nil!
response.xpath_nodes(%q(.//tr)).each do |node| response.xpath_nodes(%q(.//tr)).each do |node|
if !node["onmouseover"]? if !node["onmouseover"]?
next next
end end
ip = node.xpath_node(%q(.//td[1]/font[2])).to_s.match(/<font class="spy14">(?<address>[^<]+)</).not_nil!["address"] ip = node.xpath_node(%q(.//td[1]/font[2])).to_s.match(/<font class="spy14">(?<address>[^<]+)</).not_nil!["address"]
port = 3128 encrypted_port = node.xpath_node(%q(.//td[1]/font[2]/script)).not_nil!.content
encrypted_port = encrypted_port.match(/<\\\/font>"\+(?<encrypted_port>[\d\D]+)\)$/).not_nil!["encrypted_port"]
port = ""
encrypted_port.split("+").each do |number|
number = number.delete("()")
left_side, right_side = number.split("^")
result = mapping[left_side] ^ mapping[right_side]
port = "#{port}#{result}"
end
port = port.to_i
latency = node.xpath_node(%q(.//td[6])).not_nil!.content.to_f latency = node.xpath_node(%q(.//td[6])).not_nil!.content.to_f
speed = node.xpath_node(%q(.//td[7]/font/table)).not_nil!["width"].to_f speed = node.xpath_node(%q(.//td[7]/font/table)).not_nil!["width"].to_f
@ -141,3 +159,52 @@ def get_proxies(country_code = "US")
return proxies return proxies
end end
def decrypt_port(p, x)
x = x.split("^")
s = {} of String => String
60.times do |i|
if x[i]?.try &.empty?
s[y_func(i)] = y_func(i)
else
s[y_func(i)] = x[i]
end
end
x = s
p = p.gsub(/\b\w+\b/, x)
p = p.split(";")
p = p.map { |item| item.split("=") }
mapping = {} of String => Int32
p.each do |item|
if item == [""]
next
end
key = item[0]
value = item[1]
value = value.split("^")
if value.size == 1
value = value[0].to_i
else
left_side = value[0].to_i?
left_side ||= mapping[value[0]]
right_side = value[1].to_i?
right_side ||= mapping[value[1]]
value = left_side ^ right_side
end
mapping[key] = value
end
return mapping
end
def y_func(c)
return (c < 60 ? "" : y_func((c/60).to_i)) + ((c = c % 60) > 35 ? ((c.to_u8 + 29).unsafe_chr) : c.to_s(36))
end

View File

@ -64,10 +64,23 @@ end
def decode_date(string : String) def decode_date(string : String)
# String matches 'YYYY' # String matches 'YYYY'
if string.match(/\d{4}/) if string.match(/^\d{4}/)
return Time.new(string.to_i, 1, 1) return Time.new(string.to_i, 1, 1)
end end
# Try to parse as format Jul 10, 2000
begin
return Time.parse(string, "%b %-d, %Y", Time::Location.local)
rescue ex
end
case string
when "today"
return Time.now
when "yesterday"
return Time.now - 1.day
end
# String matches format "20 hours ago", "4 months ago"... # String matches format "20 hours ago", "4 months ago"...
date = string.split(" ")[-3, 3] date = string.split(" ")[-3, 3]
delta = date[0].to_i delta = date[0].to_i
@ -150,10 +163,27 @@ def make_host_url(ssl, host)
end end
def get_referer(env, fallback = "/") def get_referer(env, fallback = "/")
referer = env.request.headers["referer"]? referer = env.params.query["referer"]?
referer ||= env.request.headers["referer"]?
referer ||= fallback referer ||= fallback
referer = URI.parse(referer).full_path referer = URI.parse(referer)
# "Unroll" nested referers
loop do
if referer.query
params = HTTP::Params.parse(referer.query.not_nil!)
if params["referer"]?
referer = URI.parse(URI.unescape(params["referer"]))
else
break
end
else
break
end
end
referer = referer.full_path
if referer == env.request.path if referer == env.request.path
referer = fallback referer = fallback

160
src/invidious/playlists.cr Normal file
View File

@ -0,0 +1,160 @@
class Playlist
add_mapping({
title: String,
id: String,
author: String,
ucid: String,
description: String,
video_count: Int32,
views: Int64,
updated: Time,
})
end
class PlaylistVideo
add_mapping({
title: String,
id: String,
author: String,
ucid: String,
length_seconds: Int32,
published: Time,
playlists: Array(String),
index: Int32,
})
end
def extract_playlist(plid, page)
index = (page - 1) * 100
url = produce_playlist_url(plid, index)
client = make_client(YT_URL)
response = client.get(url)
response = JSON.parse(response.body)
if !response["content_html"]? || response["content_html"].as_s.empty?
raise "Playlist does not exist"
end
videos = [] of PlaylistVideo
document = XML.parse_html(response["content_html"].as_s)
anchor = document.xpath_node(%q(//div[@class="pl-video-owner"]/a))
if anchor
document.xpath_nodes(%q(.//tr[contains(@class, "pl-video")])).each_with_index do |video, offset|
anchor = video.xpath_node(%q(.//td[@class="pl-video-title"]))
if !anchor
next
end
title = anchor.xpath_node(%q(.//a)).not_nil!.content.strip(" \n")
id = anchor.xpath_node(%q(.//a)).not_nil!["href"].lchop("/watch?v=")[0, 11]
anchor = anchor.xpath_node(%q(.//div[@class="pl-video-owner"]/a))
if anchor
author = anchor.content
ucid = anchor["href"].split("/")[2]
else
author = ""
ucid = ""
end
anchor = video.xpath_node(%q(.//td[@class="pl-video-time"]/div/div[1]))
if anchor && !anchor.content.empty?
length_seconds = decode_length_seconds(anchor.content)
else
length_seconds = 0
end
videos << PlaylistVideo.new(
title,
id,
author,
ucid,
length_seconds,
Time.now,
[plid],
index + offset,
)
end
end
return videos
end
def produce_playlist_url(id, index)
if id.starts_with? "UC"
id = "UU" + id.lchop("UC")
end
ucid = "VL" + id
continuation = [0x08_u8] + write_var_int(index)
slice = continuation.to_unsafe.to_slice(continuation.size)
slice = Base64.urlsafe_encode(slice, false)
# Inner Base64
continuation = "PT:" + slice
continuation = [0x7a_u8, continuation.bytes.size.to_u8] + continuation.bytes
slice = continuation.to_unsafe.to_slice(continuation.size)
slice = Base64.urlsafe_encode(slice)
slice = URI.escape(slice)
# Outer Base64
continuation = [0x1a.to_u8, slice.bytes.size.to_u8] + slice.bytes
continuation = ucid.bytes + continuation
continuation = [0x12_u8, ucid.size.to_u8] + continuation
continuation = [0xe2_u8, 0xa9_u8, 0x85_u8, 0xb2_u8, 2_u8, continuation.size.to_u8] + continuation
# Wrap bytes
slice = continuation.to_unsafe.to_slice(continuation.size)
slice = Base64.urlsafe_encode(slice)
slice = URI.escape(slice)
continuation = slice
url = "/browse_ajax?action_continuation=1&continuation=#{continuation}"
return url
end
def fetch_playlist(plid)
client = make_client(YT_URL)
response = client.get("/playlist?list=#{plid}&disable_polymer=1")
document = XML.parse_html(response.body)
title = document.xpath_node(%q(//h1[@class="pl-header-title"])).not_nil!.content
title = title.strip(" \n")
description = document.xpath_node(%q(//span[@class="pl-header-description-text"]/div/div[1]))
description ||= document.xpath_node(%q(//span[@class="pl-header-description-text"]))
if description
description = description.to_xml.strip(" \n")
description = description.split("<button ")[0]
description = fill_links(description, "https", "www.youtube.com")
description = add_alt_links(description)
else
description = ""
end
anchor = document.xpath_node(%q(//ul[@class="pl-header-details"])).not_nil!
author = anchor.xpath_node(%q(.//li[1]/a)).not_nil!.content
ucid = anchor.xpath_node(%q(.//li[1]/a)).not_nil!["href"].split("/")[2]
video_count = anchor.xpath_node(%q(.//li[2])).not_nil!.content.delete("videos, ").to_i
views = anchor.xpath_node(%q(.//li[3])).not_nil!.content.delete("views, ").to_i64
updated = anchor.xpath_node(%q(.//li[4])).not_nil!.content.lchop("Last updated on ").lchop("Updated ")
updated = decode_date(updated)
playlist = Playlist.new(
title,
plid,
author,
ucid,
description,
video_count,
views,
updated
)
return playlist
end

View File

@ -10,7 +10,7 @@ class User
end end
add_mapping({ add_mapping({
id: String, id: Array(String),
updated: Time, updated: Time,
notifications: Array(String), notifications: Array(String),
subscriptions: Array(String), subscriptions: Array(String),
@ -78,8 +78,8 @@ class Preferences
end end
def get_user(sid, client, headers, db, refresh = true) def get_user(sid, client, headers, db, refresh = true)
if db.query_one?("SELECT EXISTS (SELECT true FROM users WHERE id = $1)", sid, as: Bool) if db.query_one?("SELECT EXISTS (SELECT true FROM users WHERE $1 = ANY(id))", sid, as: Bool)
user = db.query_one("SELECT * FROM users WHERE id = $1", sid, as: User) user = db.query_one("SELECT * FROM users WHERE $1 = ANY(id)", sid, as: User)
if refresh && Time.now - user.updated > 1.minute if refresh && Time.now - user.updated > 1.minute
user = fetch_user(sid, client, headers, db) user = fetch_user(sid, client, headers, db)
@ -89,7 +89,7 @@ def get_user(sid, client, headers, db, refresh = true)
args = arg_array(user_array) args = arg_array(user_array)
db.exec("INSERT INTO users VALUES (#{args}) \ db.exec("INSERT INTO users VALUES (#{args}) \
ON CONFLICT (email) DO UPDATE SET id = $1, updated = $2, subscriptions = $4", user_array) ON CONFLICT (email) DO UPDATE SET id = users.id || $1, updated = $2, subscriptions = $4", user_array)
end end
else else
user = fetch_user(sid, client, headers, db) user = fetch_user(sid, client, headers, db)
@ -99,7 +99,7 @@ def get_user(sid, client, headers, db, refresh = true)
args = arg_array(user.to_a) args = arg_array(user.to_a)
db.exec("INSERT INTO users VALUES (#{args}) \ db.exec("INSERT INTO users VALUES (#{args}) \
ON CONFLICT (email) DO UPDATE SET id = $1, updated = $2, subscriptions = $4", user_array) ON CONFLICT (email) DO UPDATE SET id = users.id || $1, updated = $2, subscriptions = $4", user_array)
end end
return user return user
@ -132,7 +132,7 @@ def fetch_user(sid, client, headers, db)
token = Base64.urlsafe_encode(Random::Secure.random_bytes(32)) token = Base64.urlsafe_encode(Random::Secure.random_bytes(32))
user = User.new(sid, Time.now, [] of String, channels, email, DEFAULT_USER_PREFERENCES, nil, token, [] of String) user = User.new([sid], Time.now, [] of String, channels, email, DEFAULT_USER_PREFERENCES, nil, token, [] of String)
return user return user
end end
@ -140,7 +140,7 @@ def create_user(sid, email, password)
password = Crypto::Bcrypt::Password.create(password, cost: 10) password = Crypto::Bcrypt::Password.create(password, cost: 10)
token = Base64.urlsafe_encode(Random::Secure.random_bytes(32)) token = Base64.urlsafe_encode(Random::Secure.random_bytes(32))
user = User.new(sid, Time.now, [] of String, [] of String, email, DEFAULT_USER_PREFERENCES, password.to_s, token, [] of String) user = User.new([sid], Time.now, [] of String, [] of String, email, DEFAULT_USER_PREFERENCES, password.to_s, token, [] of String)
return user return user
end end

View File

@ -228,6 +228,8 @@ VIDEO_FORMATS = {
} }
class Video class Video
property player_json : JSON::Any?
module HTTPParamConverter module HTTPParamConverter
def self.from_rs(rs) def self.from_rs(rs)
HTTP::Params.parse(rs.read(String)) HTTP::Params.parse(rs.read(String))
@ -287,9 +289,15 @@ class Video
return audio_streams return audio_streams
end end
def captions def player_response
player_response = JSON.parse(self.info["player_response"]) if !@player_json
@player_json = JSON.parse(@info["player_response"])
end
return @player_json.not_nil!
end
def captions
captions = [] of Caption captions = [] of Caption
if player_response["captions"]? if player_response["captions"]?
caption_list = player_response["captions"]["playerCaptionsTracklistRenderer"]["captionTracks"]?.try &.as_a caption_list = player_response["captions"]["playerCaptionsTracklistRenderer"]["captionTracks"]?.try &.as_a

View File

@ -16,21 +16,25 @@
<p class="h-box"> <p class="h-box">
<% if user %> <% if user %>
<% if subscriptions.includes? ucid %> <% if subscriptions.includes? ucid %>
<a href="/subscription_ajax?action_remove_subscriptions=1&c=<%= ucid %>"> <a href="/subscription_ajax?action_remove_subscriptions=1&c=<%= ucid %>&referer=<%= env.get("current_page") %>">
<b>Unsubscribe from <%= author %></b> <b>Unsubscribe from <%= author %></b>
</a> </a>
<% else %> <% else %>
<a href="/subscription_ajax?action_create_subscription_to_channel=1&c=<%= ucid %>"> <a href="/subscription_ajax?action_create_subscription_to_channel=1&c=<%= ucid %>&referer=<%= env.get("current_page") %>">
<b>Subscribe to <%= author %></b> <b>Subscribe to <%= author %></b>
</a> </a>
<% end %> <% end %>
<% else %> <% else %>
<a href="/login"> <a href="/login?referer=<%= env.get("current_page") %>">
<b>Login to subscribe to <%= author %></b> <b>Login to subscribe to <%= author %></b>
</a> </a>
<% end %> <% end %>
</p> </p>
<p class="h-box">
<a href="https://www.youtube.com/channel/<%= ucid %>">View channel on YouTube</a>
</p>
<% videos.each_slice(4) do |slice| %> <% videos.each_slice(4) do |slice| %>
<div class="pure-g"> <div class="pure-g">
<% slice.each do |video| %> <% slice.each do |video| %>
@ -41,14 +45,14 @@
<div class="pure-g h-box"> <div class="pure-g h-box">
<div class="pure-u-1 pure-u-md-1-5"> <div class="pure-u-1 pure-u-md-1-5">
<% if page > 2 %> <% if page >= 2 %>
<a href="/channel/<%= ucid %>?page=<%= page - 1 %>">Previous page</a> <a href="/channel/<%= ucid %>?page=<%= page - 1 %>">Previous page</a>
<% else %>
<a href="/channel/<%= ucid %>">Previous page</a>
<% end %> <% end %>
</div> </div>
<div class="pure-u-1 pure-u-md-3-5"></div> <div class="pure-u-1 pure-u-md-3-5"></div>
<div style="text-align:right;" class="pure-u-1 pure-u-md-1-5"> <div style="text-align:right;" class="pure-u-1 pure-u-md-1-5">
<% if videos.size == 100 %>
<a href="/channel/<%= ucid %>?page=<%= page + 1 %>">Next page</a> <a href="/channel/<%= ucid %>?page=<%= page + 1 %>">Next page</a>
<% end %>
</div> </div>
</div> </div>

View File

@ -1,6 +1,11 @@
<div class="pure-u-1 pure-u-md-1-4"> <div class="pure-u-1 pure-u-md-1-4">
<div class="h-box"> <div class="h-box">
<a style="width:100%;" href="/watch?v=<%= video.id %>"> <% if video.responds_to?(:playlists) %>
<% params = "&list=#{video.playlists[0]}" %>
<% else %>
<% params = nil %>
<% end %>
<a style="width:100%;" href="/watch?v=<%= video.id %><%= params %>">
<% if env.get?("user") && env.get("user").as(User).preferences.thin_mode %> <% if env.get?("user") && env.get("user").as(User).preferences.thin_mode %>
<% else %> <% else %>
<img style="width:100%;" src="https://i.ytimg.com/vi/<%= video.id %>/mqdefault.jpg"/> <img style="width:100%;" src="https://i.ytimg.com/vi/<%= video.id %>/mqdefault.jpg"/>

View File

@ -16,7 +16,7 @@
</div> </div>
<hr> <hr>
<% if account_type == "invidious" %> <% if account_type == "invidious" %>
<form class="pure-form pure-form-stacked" action="/login?referer=<%= referer %>&type=invidious" method="post"> <form class="pure-form pure-form-stacked" action="/login?referer=<%= URI.escape(referer) %>&type=invidious" method="post">
<fieldset> <fieldset>
<label for="email">User ID:</label> <label for="email">User ID:</label>
<input required class="pure-input-1" name="email" type="text" placeholder="User ID"> <input required class="pure-input-1" name="email" type="text" placeholder="User ID">
@ -34,7 +34,7 @@
</fieldset> </fieldset>
</form> </form>
<% elsif account_type == "google" %> <% elsif account_type == "google" %>
<form class="pure-form pure-form-stacked" action="/login?referer=<%= referer %>" method="post"> <form class="pure-form pure-form-stacked" action="/login?referer=<%= URI.escape(referer) %>" method="post">
<fieldset> <fieldset>
<label for="email">Email:</label> <label for="email">Email:</label>
<input required class="pure-input-1" name="email" type="email" placeholder="Email"> <input required class="pure-input-1" name="email" type="email" placeholder="Email">

View File

@ -0,0 +1,42 @@
<% content_for "header" do %>
<title><%= playlist.title %> - Invidious</title>
<% end %>
<div class="pure-g h-box">
<div class="pure-u-2-3">
<h3><%= playlist.title %></h3>
</div>
</div>
<div class="pure-g h-box">
<div class="pure-u-1 pure-u-md-1-4">
<a href="/channel/<%= playlist.ucid %>">
<b><%= playlist.author %></b>
</a>
</div>
</div>
<div class="h-box">
<p><%= playlist.description %></p>
</div>
<% videos.each_slice(4) do |slice| %>
<div class="pure-g">
<% slice.each do |video| %>
<%= rendered "components/video" %>
<% end %>
</div>
<% end %>
<div class="pure-g h-box">
<div class="pure-u-1 pure-u-md-1-5">
<% if page >= 2 %>
<a href="/playlist?list=<%= playlist.id %>&page=<%= page - 1 %>">Next page</a>
<% end %>
</div>
<div class="pure-u-1 pure-u-md-3-5"></div>
<div style="text-align:right;" class="pure-u-1 pure-u-md-1-5">
<% if videos.size == 100 %>
<a href="/playlist?list=<%= playlist.id %>&page=<%= page + 1 %>">Next page</a>
<% end %>
</div>
</div>

View File

@ -12,10 +12,8 @@
<div class="pure-g h-box"> <div class="pure-g h-box">
<div class="pure-u-1 pure-u-md-1-5"> <div class="pure-u-1 pure-u-md-1-5">
<% if page > 2 %> <% if page >= 2 %>
<a href="/search?q=<%= query %>&page=<%= page - 1 %>">Previous page</a> <a href="/search?q=<%= query %>&page=<%= page - 1 %>">Previous page</a>
<% else %>
<a href="/search?q=<%= query %>">Previous page</a>
<% end %> <% end %>
</div> </div>
<div class="pure-u-1 pure-u-md-3-5"></div> <div class="pure-u-1 pure-u-md-3-5"></div>

View File

@ -38,14 +38,14 @@
<div class="pure-g"> <div class="pure-g">
<div class="pure-u-1 pure-u-md-1-5"> <div class="pure-u-1 pure-u-md-1-5">
<% if page > 2 %> <% if page >= 2 %>
<a href="/feed/subscriptions?max_results=<%= max_results %>&page=<%= page - 1 %>">Previous page</a> <a href="/feed/subscriptions?max_results=<%= max_results %>&page=<%= page - 1 %>">Previous page</a>
<% else %>
<a href="/feed/subscriptions?max_results=<%= max_results %>">Previous page</a>
<% end %> <% end %>
</div> </div>
<div class="pure-u-1 pure-u-md-3-5"></div> <div class="pure-u-1 pure-u-md-3-5"></div>
<div style="text-align:right;" class="pure-u-1 pure-u-md-1-5"> <div style="text-align:right;" class="pure-u-1 pure-u-md-1-5">
<% if (videos.size + notifications.size) == max_results %>
<a href="/feed/subscriptions?max_results=<%= max_results %>&page=<%= page + 1 %>">Next page</a> <a href="/feed/subscriptions?max_results=<%= max_results %>&page=<%= page + 1 %>">Next page</a>
<% end %>
</div> </div>
</div> </div>

View File

@ -34,7 +34,7 @@
<div class="pure-u-1 pure-u-md-8-24 user-field"> <div class="pure-u-1 pure-u-md-8-24 user-field">
<% if env.get? "user" %> <% if env.get? "user" %>
<div class="pure-u-1-4"> <div class="pure-u-1-4">
<a href="/toggle_theme" class="pure-menu-heading"> <a href="/toggle_theme?referer=<%= env.get("current_page") %>" class="pure-menu-heading">
<% preferences = env.get("user").as(User).preferences %> <% preferences = env.get("user").as(User).preferences %>
<% if preferences.dark_mode %> <% if preferences.dark_mode %>
<i class="icon ion-ios-sunny"></i> <i class="icon ion-ios-sunny"></i>
@ -54,15 +54,15 @@
</a> </a>
</div> </div>
<div class="pure-u-1-4"> <div class="pure-u-1-4">
<a href="/preferences" class="pure-menu-heading"> <a href="/preferences?referer=<%= env.get("current_page") %>" class="pure-menu-heading">
<i class="icon ion-ios-cog"></i> <i class="icon ion-ios-cog"></i>
</a> </a>
</div> </div>
<div class="pure-u-1-4"> <div class="pure-u-1-4">
<a href="/signout" class="pure-menu-heading">Sign out</a> <a href="/signout?referer=<%= env.get("current_page") %>" class="pure-menu-heading">Sign out</a>
</div> </div>
<% else %> <% else %>
<a href="/login" class="pure-menu-heading">Login</a> <a href="/login?referer=<%= env.get("current_page") %>" class="pure-menu-heading">Login</a>
<% end %> <% end %>
</div> </div>
</div> </div>
@ -72,6 +72,13 @@
Roth</a>. Roth</a>.
Source available <a Source available <a
href="https://github.com/omarroth/invidious">here</a>. href="https://github.com/omarroth/invidious">here</a>.
<p>Patreon:
<a href="https://patreon.com/omarroth">
https://patreon.com/omarroth
</a>
</p>
<p>BTC: 356DpZyMXu6rYd55Yqzjs29n79kGKWcYrY</p>
<p>BCH: qq4ptclkzej5eza6a50et5ggc58hxsq5aylqut2npk</p>
</div> </div>
</div> </div>
<div class="pure-u-1 pure-u-md-4-24"></div> <div class="pure-u-1 pure-u-md-4-24"></div>

View File

@ -72,7 +72,7 @@ function load_comments(target) {
xhr.onreadystatechange = function() { xhr.onreadystatechange = function() {
if (xhr.readyState == 4) { if (xhr.readyState == 4) {
if (xhr.status == 200) { if (xhr.status == 200) {
body.innerHTML = xhr.response.content_html; body.innerHTML = xhr.response.contentHtml;
} else { } else {
body.innerHTML = fallback; body.innerHTML = fallback;
} }
@ -106,12 +106,12 @@ function get_reddit_comments() {
<a target="_blank" href="https://reddit.com{permalink}">View more comments on Reddit</a> <a target="_blank" href="https://reddit.com{permalink}">View more comments on Reddit</a>
</b> </b>
</div> </div>
<div>{content_html}</div> <div>{contentHtml}</div>
<hr>`.supplant({ <hr>`.supplant({
title: xhr.response.title, title: xhr.response.title,
permalink: xhr.response.permalink, permalink: xhr.response.permalink,
content_html: xhr.response.content_html contentHtml: xhr.response.contentHtml
}); });
} else { } else {
get_youtube_comments(); get_youtube_comments();
@ -139,12 +139,13 @@ function get_youtube_comments() {
<div> <div>
<h3> <h3>
<a href="javascript:void(0)" onclick="toggle_comments(this)">[ - ]</a> <a href="javascript:void(0)" onclick="toggle_comments(this)">[ - ]</a>
<a target="_blank" href="https://www.youtube.com/watch?v=<%= video.id %>">View more comments on YouTube</a> View {commentCount} comments
</h3> </h3>
</div> </div>
<div>{content_html}</div> <div>{contentHtml}</div>
<hr>`.supplant({ <hr>`.supplant({
content_html: xhr.response.content_html contentHtml: xhr.response.contentHtml,
commentCount: commaSeparateNumber(xhr.response.commentCount)
}); });
} else { } else {
comments = document.getElementById("comments"); comments = document.getElementById("comments");
@ -160,6 +161,13 @@ function get_youtube_comments() {
}; };
} }
function commaSeparateNumber(val){
while (/(\d+)(\d{3})/.test(val.toString())){
val = val.toString().replace(/(\d+)(\d{3})/, '$1'+','+'$2');
}
return val;
}
String.prototype.supplant = function(o) { String.prototype.supplant = function(o) {
return this.replace(/{([^{}]*)}/g, function(a, b) { return this.replace(/{([^{}]*)}/g, function(a, b) {
var r = o[b]; var r = o[b];
@ -188,6 +196,9 @@ get_youtube_comments();
</a> </a>
<% end %> <% end %>
</h1> </h1>
<% if !reason.empty? %>
<h3><%= reason %></h3>
<% end %>
</div> </div>
<div class="pure-g"> <div class="pure-g">
@ -211,9 +222,6 @@ get_youtube_comments();
<% end %> <% end %>
</p> </p>
<% end %> <% end %>
<% if engage_types %>
<p id="Engage">Engage Types: <%= engage_types %></p>
<% end %>
</div> </div>
</div> </div>
@ -227,20 +235,20 @@ get_youtube_comments();
<% if user %> <% if user %>
<% if subscriptions.includes? video.ucid %> <% if subscriptions.includes? video.ucid %>
<p> <p>
<a href="/subscription_ajax?action_remove_subscriptions=1&c=<%= video.ucid %>"> <a href="/subscription_ajax?action_remove_subscriptions=1&c=<%= video.ucid %>&referer=<%= env.get("current_page") %>">
<b>Unsubscribe from <%= video.author %></b> <b>Unsubscribe from <%= video.author %></b>
</a> </a>
</p> </p>
<% else %> <% else %>
<p> <p>
<a href="/subscription_ajax?action_create_subscription_to_channel=1&c=<%= video.ucid %>"> <a href="/subscription_ajax?action_create_subscription_to_channel=1&c=<%= video.ucid %>&referer=<%= env.get("current_page") %>">
<b>Subscribe to <%= video.author %></b> <b>Subscribe to <%= video.author %></b>
</a> </a>
</p> </p>
<% end %> <% end %>
<% else %> <% else %>
<p> <p>
<a href="/login"> <a href="/login?referer=<%= env.get("current_page") %>">
<b>Login to subscribe to <%= video.author %></b> <b>Login to subscribe to <%= video.author %></b>
</a> </a>
</p> </p>