Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: save youtube thumbnail info (WIP) #35263

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions xmodule/video_block/video_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,9 @@ def editor_saved(self, user, old_metadata, old_content): # lint-amnesty, pylint
if val_youtube_id and self.youtube_id_1_0 != val_youtube_id:
self.youtube_id_1_0 = val_youtube_id

if not self.edx_video_id and self.youtube_id_1_0:
self.thumbnail = f"https://img.youtube.com/vi/{self.youtube_id_1_0}/sddefault.jpg"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only probably I can see with this is with the edge case in which:

  1. The user explicitly sets the thumbnail to a value in OLX; and...
  2. The user changes some video metadata, but not the actual YouTube video location.

In that case, we would not want to override the explicit thumbnail they set with the YouTube default.

Whatever you end up writing though, please add thorough comments explaining why this is okay to do, since this logic would not be obvious to someone who isn't familiar with some of the weirdness of VideoBlock.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we can also add and not self.thumbnail to the check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then we can also add and not self.thumbnail to the check?

This will prevent the thumbnail from being updated if the YouTube URL changes. Also, we are not cleaning the thumbnail if we change the URL (i.e. from a YouTube video for a stream)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right. Then I think it's better to never save this thumbnail value into the thumbnail field - besides that means that existing videos without thumbnails won't show up unless they are edited and saved. Instead, every time index_dictionary() is called, return self.thumbnail or (autodetect youtube URL if applicable) or None but don't save it into the self.thumbnail field.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The advantage of saving it is that it can be used in other places, like the block editor (which works out of the box).
image

Another option would be to create a new thumbnail_youtube field to store this data and add a getter to the thumbnail property using the thumbnail field as a fallback.

def get_thumbnail(self):
  return self.thumbnail or self.thumbnail_youtube

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we store it and the user change the YouTube URL, will we be able to automatically update the thumbnail_youtube field?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. We already have the logic to handle it with the youtube_id_1_0 field.


manage_video_subtitles_save(
self,
user,
Expand Down Expand Up @@ -1120,6 +1123,7 @@ def index_dictionary(self):
xblock_body = super().index_dictionary()
video_body = {
"display_name": self.display_name,
"thumbnail": self.thumbnail,
}

def _update_transcript_for_index(language=None):
Expand Down
Loading