Problems with thumbnails from Soundcloud and YouTube oneboxes

We are using Topic List Previews with tiles in our main page. Yesterday we had to rebuild our instance for reasons unrelated to TPL. We were aware of the change of thumbnailing backend in Discourse core and we knew that upgrading could cause problems with thumbnails. Still, it had to be done. :slight_smile:

Anyway, after rebuilding (including the Postgres upgrade), all thumbnails coming from oneboxes were gone. No problem, we rebaked all posts and then most thumbnails reappeared (good) but not all (intriguing and bad). We rebaked a couple more times just in case, but there are some remaining posts that won’t get their thumbnail in the main page even if the oneboxes render without problems in their topic page.

Two patterns detected so far:

  • Soundcloud oneboxes render without problems, but the thumbnail is missing systematically ("Select Thumbnail will show no thumbnails), and no rebuild HTML will solve this. For instance, check Female:pressure podcast episode 60 Inverno - female:pressure podcast - EQlzr.
  • Some thumbnails of YouTube oneboxes were missing in the main page (only some) and then, after visiting the topic page, they would magically appear in the main page. However…

There is one (and only one, the last one) topic with a YouTube onebox that won’t generate a thumbnail, no idea why: Look Mom No Computer (DIY Synths) - Listen / Watch - EQlzr.

2 Likes

As discussed, thumbnailing production logic is now built into core.

What TLP used to have to do is no longer necessary, largely.

For reference, the core criteria for inclusion are the following:

  def extract_images_for_post
    # all images with a src attribute
    @doc.css("img[src]") -
    # minus emojis
    @doc.css("img.emoji") -
    # minus images inside quotes
    @doc.css(".quote img") -
    # minus onebox site icons
    @doc.css("img.site-icon") -
    # minus onebox avatars
    @doc.css("img.onebox-avatar") -
    # minus small onebox images (large images are .aspect-image-full-size)
    @doc.css(".onebox .aspect-image img")
  end

from https://github.com/discourse/discourse/blob/master/lib/cooked_post_processor.rb

TLP modifies this slightly, but only to loosen it up. I’d like to drop this override completely if possible:

  def extract_images_for_post
    # all images with a src attribute
    @doc.css("img[src]") -
    # minus emojis
    @doc.css("img.emoji") -
    # minus images inside quotes
    @doc.css(".quote img") -
    # minus onebox site icons
    @doc.css("img.site-icon") -
    # minus onebox avatars
    @doc.css("img.onebox-avatar") #Broader criteria than Discourse Core
  end

from https://github.com/paviliondev/discourse-topic-previews/blob/master/lib/cooked_post_processor_edits.rb

As you can see I am reducing the amount of exclusions by allowing small onebox images as defined by core.

Rather than maintaining this in TLP, it would be good to get consensus and parity across the use cases, so I don’t have to maintain this in the plugin at all.

This is also relevant to you @Arkshine

3 Likes

Thank you @merefield, this is very informative.

I just want to say that the previous thumbnailing of Soundcloud oneboxes provided great results, and this regression is really bothering for a site focusing on music like ours. :slight_smile:

I don’t mind if we miss a YouTube thumbnail here and there.

Curious about how this will evolve. I agree that the goal is to fine tune thumbnailing in Discourse core to find the best common ground between the many requirements and wishes. Thank you to everyone working on this.

1 Like

At a glance, I don’t think that’s a YouTube onebox. I suspect someone has used raw YouTube embedding code in the post. If you turn it into a onebox, the thumbnail should work.

Did this used to work with the old TLP plugin? Soundcloud oneboxes are iframes, so I struggle to see how we could pull a thumbnail image from them, even my updating our selection criteria. @merefield did TLP have some soundcloud-specific logic somewhere?

4 Likes

Yes, there was some custom logic around oneboxes, though this was not exclusively for SoundCloud:

    if @has_oneboxes
      cooked = PrettyText.cook(@post.raw)

      if img
        ## We need something more specific to identify the image with
        img_id = img
        src = img.attribute("src").to_s
        img_id = src.split('/').last.split('.').first if src
      end

      prior_oneboxes = []
      Oneboxer.each_onebox_link(cooked) do |url, element|
        if !img || (img && cooked.index(element).to_i < cooked.index(img_id).to_i)
          html = Nokogiri::HTML::fragment(Oneboxer.cached_preview(url))
          prior_oneboxes = html.css('img')
        end
      end

      if prior_oneboxes.any?
        prior_oneboxes = prior_oneboxes.reject do |html|
          class_str = html.attribute('class').to_s
          class_str.include?('site-icon') || class_str.include?('avatar')
        end

        if prior_oneboxes.any? && validate_image_for_previews(prior_oneboxes.first)
          img = prior_oneboxes.first
        end
      end
   end

This has been stripped out to defer to the core logic.

3 Likes

Ah, it didn’t occur to me to check the source. :slight_smile:

It was a onebox, but the URL had an extra argument:

https://www.youtube.com/watch?v=4T6J-K8_yk4&list=PLluPQLh1xzlL2agiCCQFClcsutli90Qnz

I changed it to the plain URL:

https://www.youtube.com/watch?v=4T6J-K8_yk4

There wasn’t an immediate change. After rebuilding HTML there wasn’t an immediate change either, but then I went to check Sidekiq and I saw one related job scheduled. After waiting 4 minutes patiently, the thumbnail is now available and it is displayed in the main page. Thank you @david for such quick reply, and on a Sunday!

Absolutely. Sadly, I didn’t take any screenshot. The main page would show the image at the left of the onebox.

2 Likes

Interesting, I’ll take a look at this next week. I think it should still work, even with an extra argument

Ah I see, so you pulled the Onebox preview html, and extract thumbnails from that. For soundcloud, that gives a thumbnail :+1:

5 Likes

Yes, this is based on @angus’ marvellous hack :smiley: I take no responsibility! Works well though.

UPDATE Actually, I lie, my finger prints are also all over it too! I wrote some of this code so long ago I’d forgotten about it, 2015!

https://github.com/paviliondev/discourse-topic-previews/commit/d2bdde786506acd4de9ccfde8bd4ef2dc68a1022

5 Likes

These are both tricky problems, and I think for now we will be leaving the behavior as-is. We may be able to add some improvements in future. I created a couple of feature topics to track progress

For the YouTube difference, see:

For the soundcloud issue, see:

5 Likes

I had the same problem with https://youtu.be/ style youtube links. After changing them to https://www.youtube.com/watch?v= style it worked again.

That’s odd, can you share those specific youtube links here? Either form should work.

Maybe a re-render would have done the job as well.
But it seems to live on in the versions:

I did reset the link to the old one, but now everything renders nicely. I guess that this was due to a rendering error after the beta6 update.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.