mirror of
https://gitea.invidious.io/iv-org/invidious-copy-2022-08-14.git
synced 2024-08-15 00:53:20 +00:00
Add 'published' to video component
This commit is contained in:
parent
2fe3d308f9
commit
3dcb6766fc
2 changed files with 38 additions and 17 deletions
|
@ -354,31 +354,24 @@ def search(query, page = 1)
|
|||
|
||||
html.xpath_nodes(%q(//ol[@class="item-section"]/li)).each do |item|
|
||||
root = item.xpath_node(%q(div[contains(@class,"yt-lockup-video")]/div))
|
||||
if root
|
||||
id = root.xpath_node(%q(div[contains(@class,"yt-lockup-thumbnail")]/a/@href))
|
||||
if id
|
||||
id = id.content.lchop("/watch?v=")
|
||||
if !root
|
||||
next
|
||||
end
|
||||
id ||= ""
|
||||
|
||||
title = root.xpath_node(%q(div[@class="yt-lockup-content"]/h3/a))
|
||||
if title
|
||||
title = title.content
|
||||
end
|
||||
title ||= ""
|
||||
id = root.xpath_node(%q(.//div[contains(@class,"yt-lockup-thumbnail")]/a/@href)).not_nil!.content.lchop("/watch?v=")
|
||||
|
||||
author = root.xpath_node(%q(div[@class="yt-lockup-content"]/div/a))
|
||||
if author
|
||||
title = root.xpath_node(%q(.//div[@class="yt-lockup-content"]/h3/a)).not_nil!.content
|
||||
|
||||
author = root.xpath_node(%q(.//div[@class="yt-lockup-content"]/div/a)).not_nil!
|
||||
ucid = author["href"].rpartition("/")[-1]
|
||||
author = author.content
|
||||
end
|
||||
author ||= ""
|
||||
ucid ||= ""
|
||||
|
||||
video = ChannelVideo.new(id, title, Time.now, Time.now, ucid, author)
|
||||
published = root.xpath_node(%q(.//ul[@class="yt-lockup-meta-info"]/li[1])).not_nil!.content
|
||||
published = decode_date(published)
|
||||
|
||||
video = ChannelVideo.new(id, title, published, Time.now, ucid, author)
|
||||
videos << video
|
||||
end
|
||||
end
|
||||
|
||||
return videos
|
||||
end
|
||||
|
@ -986,6 +979,31 @@ def decode_date(string : String)
|
|||
return Time.now - delta
|
||||
end
|
||||
|
||||
def recode_date(time : Time)
|
||||
span = Time.now - time
|
||||
|
||||
if span.total_days > 365.0
|
||||
span = {span.total_days / 365, "year"}
|
||||
elsif span.total_days > 30.0
|
||||
span = {span.total_days / 30, "month"}
|
||||
elsif span.total_days > 7.0
|
||||
span = {span.total_days / 7, "week"}
|
||||
elsif span.total_hours > 24.0
|
||||
span = {span.total_days, "day"}
|
||||
elsif span.total_minutes > 60.0
|
||||
span = {span.total_hours, "hour"}
|
||||
else
|
||||
span = {0, "units"}
|
||||
end
|
||||
|
||||
span = {span[0].to_i, span[1]}
|
||||
if span[0] > 1
|
||||
span = {span[0], span[1] + "s"}
|
||||
end
|
||||
|
||||
return span.join(" ")
|
||||
end
|
||||
|
||||
def produce_playlist_url(ucid, index)
|
||||
ucid = ucid.lchop("UC")
|
||||
ucid = "VLUU" + ucid
|
||||
|
|
|
@ -10,5 +10,8 @@
|
|||
<p>
|
||||
<b><a style="width:100%;" href="/channel/<%= video.ucid %>"><%= video.author %></a></b>
|
||||
</p>
|
||||
<p>
|
||||
<h5>Shared <%= recode_date(video.published) %> ago</h5>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
Loading…
Reference in a new issue