From b4096f46368c7568c5c8a9e7ce83474c2fc1cff7 Mon Sep 17 00:00:00 2001 From: Jan Cernik <66427541+jancernik@users.noreply.github.com> Date: Mon, 3 Apr 2023 22:49:32 -0300 Subject: [PATCH] FIX: Add lazy-videos support for Vimeo unlisted videos (#20916) --- .../discourse/components/lazy-iframe.js | 4 +- .../lib/lazy-videos/lazy_vimeo.rb | 16 +- .../spec/fixtures/vimeo-unlisted.response | 420 +++ .../spec/fixtures/vimeo.response | 2251 +++++++++++++++++ .../spec/lib/lazy-videos/lazy_vimeo_spec.rb | 107 + 5 files changed, 2794 insertions(+), 4 deletions(-) create mode 100644 plugins/discourse-lazy-videos/spec/fixtures/vimeo-unlisted.response create mode 100644 plugins/discourse-lazy-videos/spec/fixtures/vimeo.response create mode 100644 plugins/discourse-lazy-videos/spec/lib/lazy-videos/lazy_vimeo_spec.rb diff --git a/plugins/discourse-lazy-videos/assets/javascripts/discourse/components/lazy-iframe.js b/plugins/discourse-lazy-videos/assets/javascripts/discourse/components/lazy-iframe.js index 7c81303ea8f..015e0ea521e 100644 --- a/plugins/discourse-lazy-videos/assets/javascripts/discourse/components/lazy-iframe.js +++ b/plugins/discourse-lazy-videos/assets/javascripts/discourse/components/lazy-iframe.js @@ -6,7 +6,9 @@ export default class LazyVideo extends Component { case "youtube": return `https://www.youtube.com/embed/${this.args.videoId}?autoplay=1`; case "vimeo": - return `https://player.vimeo.com/video/${this.args.videoId}?autoplay=1`; + return `https://player.vimeo.com/video/${this.args.videoId}${ + this.args.videoId.includes("?") ? "&" : "?" + }autoplay=1`; case "tiktok": return `https://www.tiktok.com/embed/v2/${this.args.videoId}`; } diff --git a/plugins/discourse-lazy-videos/lib/lazy-videos/lazy_vimeo.rb b/plugins/discourse-lazy-videos/lib/lazy-videos/lazy_vimeo.rb index 5e983dd18ee..3b44760db9c 100644 --- a/plugins/discourse-lazy-videos/lib/lazy-videos/lazy_vimeo.rb +++ b/plugins/discourse-lazy-videos/lib/lazy-videos/lazy_vimeo.rb @@ -8,16 +8,26 @@ class Onebox::Engine::VimeoOnebox def to_html if SiteSetting.lazy_videos_enabled && SiteSetting.lazy_vimeo_enabled - video_id = oembed_data[:video_id] + full_video_id = oembed_data[:uri].sub("/videos/", "").sub(":", "/") + + # This is used to discern public and private video + # Unlisted videos have an adidtional alphanumeric ID in their URI. + if !oembed_data[:uri].match?(%r{videos/\d+:.+}) + iframe_id = full_video_id + else + iframe_src = Nokogiri::HTML5.fragment(oembed_data[:html]).at_css("iframe")&.[]("src") + iframe_id = iframe_src.sub("https://player.vimeo.com/video/", "") + end + thumbnail_url = "https://vumbnail.com/#{oembed_data[:video_id]}.jpg" escaped_title = ERB::Util.html_escape(og_data.title) <<~HTML
- + diff --git a/plugins/discourse-lazy-videos/spec/fixtures/vimeo-unlisted.response b/plugins/discourse-lazy-videos/spec/fixtures/vimeo-unlisted.response new file mode 100644 index 00000000000..784b132374b --- /dev/null +++ b/plugins/discourse-lazy-videos/spec/fixtures/vimeo-unlisted.response @@ -0,0 +1,420 @@ + + +eleonore // michael - middlebury, vt + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
eleonore // michael - middlebury, vt
\ No newline at end of file diff --git a/plugins/discourse-lazy-videos/spec/fixtures/vimeo.response b/plugins/discourse-lazy-videos/spec/fixtures/vimeo.response new file mode 100644 index 00000000000..01c2595cedd --- /dev/null +++ b/plugins/discourse-lazy-videos/spec/fixtures/vimeo.response @@ -0,0 +1,2251 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Dear Rich on Vimeo + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + +
+ +
+ +
+ +
+ + + +
+ +
+ +
+ Watch in our app
+ + + Open in app + + +
+ +
+ + + + + + + + +
+ +

Dear Rich

More

Accomplished endurance athlete, author and podcaster, Rich Roll has been a voice we have become familiar with over the years. In DEAR RICH, we hear the story behind the voice. Rich shares a letter to himself, giving an intimate view into the struggles he's faced with addiction, how running has helped bring him back to the surface and something that he is still learning: that we must overcome our fear of change to find what we are truly capable of.

+

Credits:
+Client: SalomonTV
+Production Company: Stept Studios
+Post Production: Lockt Editorial

+

Director: Brandon Lavoie
+DP: Jared Levy
+EP: Jon Brogan
+Account Executive: Paul Muhlbach
+Producer: Laura Mittelberg
+Supervising Producer: Eric Cook
+1st AC: Jake Coury
+Gaffer: Evan Cox
+Key Grip: David Klassen
+HMU: Luca Buzas
+Audio Mixer: Bobby Vongham
+35mm Photographer: Brian Chorski
+PA: Anthony Cantu, John Maddock

+

Post Production
+Head of Post: Connor Scofield
+Post EP: Eileen Miraglia
+Post Producer: Erin Bates
+Editor: Brandon Lavoie
+Online Editor: Ben Ivers
+Colorist: Sam Zook at Mom & Pop
+Composer: Jon Sigsworth
+Sound Design and Mix: Justin Enoch at Post Mambo

+

SalomonTV
+Senior Marketing Manager – Run & Outdoor: Erin Cooper
+Marketing Specialist: Louis Bertrand

2 Categories

28 Comments

Susan Taylor

Thank you so much :) I am so excited about getting started here :) I'm basically a retired dog groomer, but I am more interested in staying at home and doing all that I can with this new business :) Yea, I'm totally excited

Tracy Corbett

Absolutely beautiful, thank you for sharing

Mark Kutrovski

This was excellent and moving. It seemed like he looked familiar and then it clicked when I saw he was the host of the podcast.
+Very well done!

James Johnson III

Beautifully captured. As a recovering alcoholic trying to find his way post trauma, I find these stories most helpful and uplifting.

Kendra Jo

I love this.

Kendra Jo

Recovering opioid addict & writer.

Mandy Hulbert

Inspirational, moving and honest, what a guy!

Upload, livestream, and create your own videos, all in HD.

Join Free

By joining Vimeo, you agree to the Terms of Service, Privacy Policy and Cookie Policy.

+ + + + + +
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/plugins/discourse-lazy-videos/spec/lib/lazy-videos/lazy_vimeo_spec.rb b/plugins/discourse-lazy-videos/spec/lib/lazy-videos/lazy_vimeo_spec.rb new file mode 100644 index 00000000000..1c5d5697d90 --- /dev/null +++ b/plugins/discourse-lazy-videos/spec/lib/lazy-videos/lazy_vimeo_spec.rb @@ -0,0 +1,107 @@ +# frozen_string_literal: true + +RSpec.describe Onebox::Engine::VimeoOnebox do + def get_response(filename) + file = "#{Rails.root}/plugins/discourse-lazy-videos/spec/fixtures/#{filename}.response" + File.read(file) + end + + before do + stub_request(:get, "https://vimeo.com/786646692").to_return( + status: 200, + body: get_response("vimeo"), + ) + + stub_request(:get, "https://vimeo.com/192207770/0faf1dd09d").to_return( + status: 200, + body: get_response("vimeo-unlisted"), + ) + + stub_request( + :get, + "https://vimeo.com/api/oembed.json?url=https://vimeo.com/786646692", + ).to_return( + status: 200, + body: + JSON.dump( + type: "video", + version: "1.0", + provider_name: "Vimeo", + provider_url: "https://vimeo.com/", + title: "Dear Rich", + author_name: "Stept Studios", + author_url: "https://vimeo.com/steptstudios", + is_plus: "0", + account_type: "business", + html: + "", + width: 426, + height: 240, + duration: 883, + description: + "Accomplished endurance athlete, author and podcaster, Rich Roll has been a voice we have become familiar with over the years. In DEAR RICH, we hear the story behind the voice. Rich shares a letter to himself, giving an intimate view into the struggles he's faced with addiction, how running has helped bring him back to the surface and something that he is still learning: that we must overcome our fear of change to find what we are truly capable of.\n\n\n\n\nCredits: \nClient: SalomonTV\nProduction Company: Stept Studios\nPost Production: Lockt Editorial\n\n\nDirector: Brandon Lavoie\nDP: Jared Levy \nEP: Jon Brogan \nAccount Executive: Paul Muhlbach\nProducer: Laura Mittelberg\nSupervising Producer: Eric Cook \n1st AC: Jake Coury\nGaffer: Evan Cox\nKey Grip: David Klassen \nHMU: Luca Buzas\nAudio Mixer: Bobby Vongham\n35mm Photographer: Brian Chorski\t\nPA: Anthony Cantu, John Maddock\n\nPost Production\nHead of Post: Connor Scofield\nPost EP: Eileen Miraglia\nPost Producer: Erin Bates\nEditor: Brandon Lavoie\nOnline Editor: Ben Ivers\nColorist: Sam Zook at Mom & Pop\nComposer: Jon Sigsworth\nSound Design and Mix: Justin Enoch at Post Mambo\n\n\nSalomonTV\nSenior Marketing Manager – Run & Outdoor: Erin Cooper\nMarketing Specialist: Louis Bertrand", + thumbnail_url: + "https://i.vimeocdn.com/video/1582157011-37115b15c717a168bf86e2f2855b6bbc23b1cbcee54ff99c8d7b808b459365d6-d_295x166", + thumbnail_width: 295, + thumbnail_height: 166, + thumbnail_url_with_play_button: + "https://i.vimeocdn.com/filter/overlay?src0=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F1582157011-37115b15c717a168bf86e2f2855b6bbc23b1cbcee54ff99c8d7b808b459365d6-d_295x166&src1=http%3A%2F%2Ff.vimeocdn.com%2Fp%2Fimages%2Fcrawler_play.png", + upload_date: "2023-01-05 12:01:55", + video_id: 786_646_692, + uri: "/videos/786646692", + ), + ) + + stub_request( + :get, + "https://vimeo.com/api/oembed.json?url=https://vimeo.com/192207770/0faf1dd09d", + ).to_return( + status: 200, + body: + JSON.dump( + type: "video", + version: "1.0", + provider_name: "Vimeo", + provider_url: "https://vimeo.com/", + html: + "", + width: 640, + height: 272, + video_id: 192_207_770, + uri: "/videos/192207770:0faf1dd09d", + ), + ) + end + + context "when public video" do + it "creates a lazy video container" do + expect(Onebox.preview("https://vimeo.com/786646692").to_s).to match(/lazy-video-container/) + end + + it "uses the correct ids" do + expect(Onebox.preview("https://vimeo.com/786646692").to_s).to include( + 'data-video-id="786646692"', + ) + expect(Onebox.preview("https://vimeo.com/786646692").to_s).to include( + 'src="https://vumbnail.com/786646692.jpg"', + ) + end + end + + context "when unlisted video" do + it "creates a lazy video container" do + expect(Onebox.preview("https://vimeo.com/192207770/0faf1dd09d").to_s).to match( + /lazy-video-container/, + ) + end + + it "uses the correct ids" do + expect(Onebox.preview("https://vimeo.com/192207770/0faf1dd09d").to_s).to include( + 'data-video-id="192207770?h=0faf1dd09d&app_id=122963"', + ) + expect(Onebox.preview("https://vimeo.com/192207770/0faf1dd09d").to_s).to include( + 'src="https://vumbnail.com/192207770.jpg"', + ) + end + end +end