Add fix for args order and rename videos table

このコミットが含まれているのは:
Omar Roth 2017-12-01 07:07:10 -06:00
コミット 764fdf42ef
2個のファイルの変更17行の追加17行の削除

ファイルの表示

@ -1,8 +1,8 @@
-- Table: public.invidious -- Table: public.videos
-- DROP TABLE public.invidious; -- DROP TABLE public.videos;
CREATE TABLE public.invidious CREATE TABLE public.videos
( (
last_updated timestamp with time zone, last_updated timestamp with time zone,
video_id text COLLATE pg_catalog."default" NOT NULL, video_id text COLLATE pg_catalog."default" NOT NULL,
@ -12,25 +12,25 @@ CREATE TABLE public.invidious
likes integer, likes integer,
dislikes integer, dislikes integer,
rating double precision, rating double precision,
CONSTRAINT invidious_pkey PRIMARY KEY (video_id) CONSTRAINT videos_pkey PRIMARY KEY (video_id)
) )
WITH ( WITH (
OIDS = FALSE OIDS = FALSE
) )
TABLESPACE pg_default; TABLESPACE pg_default;
ALTER TABLE public.invidious ALTER TABLE public.videos
OWNER to omar; OWNER to omar;
GRANT ALL ON TABLE public.invidious TO kemal; GRANT ALL ON TABLE public.videos TO kemal;
GRANT ALL ON TABLE public.invidious TO omar; GRANT ALL ON TABLE public.videos TO omar;
-- Index: invidious_video_id_idx -- Index: videos_video_id_idx
-- DROP INDEX public.invidious_video_id_idx; -- DROP INDEX public.videos_video_id_idx;
CREATE INDEX invidious_video_id_idx CREATE INDEX videos_video_id_idx
ON public.invidious USING btree ON public.videos USING btree
(video_id COLLATE pg_catalog."default") (video_id COLLATE pg_catalog."default")
TABLESPACE pg_default; TABLESPACE pg_default;

ファイルの表示

@ -145,6 +145,7 @@ def get_record(context, video_id)
views = info["view_count"] views = info["view_count"]
rating = info["avg_rating"].to_f64 rating = info["avg_rating"].to_f64
# css query [title = "I like this"] > span
like = html.xpath_node(%q(//button[@title="I like this"]/span)) like = html.xpath_node(%q(//button[@title="I like this"]/span))
if like if like
likes = like.content.delete(",").to_i likes = like.content.delete(",").to_i
@ -152,7 +153,6 @@ def get_record(context, video_id)
likes = 1 likes = 1
end end
# css query [title = "I like this"] > span
# css query [title = "I dislike this"] > span # css query [title = "I dislike this"] > span
dislike = html.xpath_node(%q(//button[@title="I dislike this"]/span)) dislike = html.xpath_node(%q(//button[@title="I dislike this"]/span))
if dislike if dislike
@ -169,22 +169,22 @@ get "/watch/:video_id" do |env|
video_id = env.params.url["video_id"] video_id = env.params.url["video_id"]
# last_updated, video_id, video_info, video_html, views, likes, dislikes, rating # last_updated, video_id, video_info, video_html, views, likes, dislikes, rating
video_record = pg.query_one?("select * from invidious where video_id = $1", video_record = pg.query_one?("select * from videos where video_id = $1",
video_id, video_id,
as: {Time, String, String, String, Int64, Int32, Int32, Float64}) as: {Time, String, String, String, Int64, Int32, Int32, Float64})
# If record was last updated more than 5 minutes ago or doesn't exist, refresh # If record was last updated more than 5 minutes ago or doesn't exist, refresh
if video_record.nil? if video_record.nil?
video_record = get_record(context, video_id) video_record = get_record(context, video_id)
pg.exec("insert into invidious values ($1, $2, $3, $4, $5, $6, $7, $8)", pg.exec("insert into videos values ($1, $2, $3, $4, $5, $6, $7, $8)",
get_record(context, video_id).to_a) video_record.to_a)
elsif Time.now.epoch - video_record[0].epoch > 300 elsif Time.now.epoch - video_record[0].epoch > 300
video_record = get_record(context, video_id) video_record = get_record(context, video_id)
pg.exec("update invidious set last_updated = $1, video_info = $2, video_html = $3,\ pg.exec("update videos set last_updated = $1, video_info = $3, video_html = $4, views = $5, likes = $6, dislikes = $7, rating = $8 where video_id = $2",
views = $4, likes = $5, dislikes = $6, rating = $7 where video_id = $8",
video_record.to_a) video_record.to_a)
end end
# last_updated, video_id, video_info, video_html, views, likes, dislikes, rating
video_info = HTTP::Params.parse(video_record[2]) video_info = HTTP::Params.parse(video_record[2])
video_html = XML.parse(video_record[3]) video_html = XML.parse(video_record[3])
views = video_record[4] views = video_record[4]