Skip to content

Commit 82eac95

Browse files
committed
Use reachable flag to track video status
1 parent ccf2f71 commit 82eac95

File tree

5 files changed

+26
-10
lines changed

5 files changed

+26
-10
lines changed

app/models/library.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ def generate_podcast(current_url, audio_url:, video_url:)
5353
guid = media_item.url
5454
item.link(media_item_link)
5555

56-
reachable_suffix = media_item.reachable ? '' : 'Unreachable'
57-
title = media_item.title + reachable_suffix
56+
title = media_item.title
5857

5958
item.title(title)
6059

app/models/media_item.rb

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,37 +31,48 @@ def article_url
3131
end
3232

3333
def has_all_details?
34-
[title, description, duration_seconds].all?(&:present?)
34+
!reachable.nil? || [title, description, duration_seconds].all?(&:present?)
3535
end
3636

3737
def fill_missing_details
3838
return if has_all_details?
39+
return if reachable == false # nil means unknown
3940

41+
# Tried within the last 30 minutes
42+
return if updated_at && updated_at != created_at && (updated_at - Time.now) < 30.minutes
43+
44+
self.updated_at = Time.now
4045
if guid.nil?
4146
self.guid = url
4247
end
4348

4449
if %r{\Ahttps://(www\.)?(youtube|vimeo)\.com/} =~ url || %r{\Ahttps://youtu\.be/} =~ url
50+
self.mime_type = VIDEO_MIME_TYPE
4551
info = Youtube::Video.new(url).get_information
46-
if info.present? && !info["is_live"]
52+
53+
# Wait for stream to finish
54+
return if info["is_live"]
55+
56+
if info.present?
4757
success = !!info["id"]
58+
self.reachable = success
59+
4860
if success && info['extractor'] == 'youtube'
4961
video = Youtube::Video.from_id(info["id"])
5062
self.guid = video.guid
5163
self.url = video.url
5264
end
65+
5366
if success || (created_at && created_at < 3.days.ago)
54-
self.reachable = success
5567
self.author = info["uploader"] || ''
5668
self.title = [feed&.title, info["title"]].select(&:present?).join(" - ")
5769
self.published_at = info["upload_date"] && Date.parse(info["upload_date"])
5870
self.description = "Original Video: #{url}\nPublished At: #{published_at}\n #{info["description"]}"
5971
self.duration_seconds = info["duration"] || 0
6072
self.thumbnail_url = info["thumbnails"]&.last&.fetch("url", "") || ''
61-
self.mime_type = VIDEO_MIME_TYPE
62-
save!
6373
end
6474
end
75+
save!
6576
end
6677
end
6778

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class ChangeColumnDefaultMediaItems < ActiveRecord::Migration[8.0]
2+
def change
3+
change_column_default :media_items, :reachable, from: true, to: nil
4+
change_column_null :media_items, :reachable, true
5+
end
6+
end

db/schema.rb

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/articles/two.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ <h1>An email</h1>
2929
copy_url:
3030
created_at: 1970-01-01 00:00:00 UTC
3131
updated_at: 1970-01-01 00:00:01 UTC
32-
reachable: true
32+
reachable:
3333
guid: http://localhost.local/media_items/42
3434
sent_to:
3535
-->

0 commit comments

Comments
 (0)