重排美丽照片Vimeo播放器嵌入表达式

huangapple go评论59阅读模式
英文:

Reformat prettyphoto Vimeo Player embed expression

问题

I'm having trouble with prettyphoto outputting the video embed links in the wrong order for unlisted videos, resulting in the video player stating that the video does not exist.

Background: the video link will be something like this:

https://vimeo.com/12345/abcde

The output becomes:

https://player.vimeo.com/video/12345?title=0&byline=0&portrait=0&autoplay=1&allowFullScreen=1;h=abcde;

As you can see, the unlisted video hash gets appended to the end of the link. It SHOULD look like this:

https://player.vimeo.com/video/12345?h=abcde&title=0&byline=0&portrait=0&autoplay=1&allowFullScreen=1;

Note the hash "h=abcde" comes after the video id "12345".

Prettyphoto uses the code below to output the video player:

case 'vimeo':
pp_dimensions = _fitToViewport(movie_width,movie_height); // Fit item to viewport

movie_id = pp_images[set_position];
var regExp = /http(s?):\/\/(www\.)?vimeo.com\/(\d+)/;
var match = movie_id.match(regExp);
                        
movie = 'http://player.vimeo.com/video/'+ match[3] +'?title=0&byline=0&portrait=0';
if(settings.autoplay) movie += "&autoplay=1;";
            
vimeo_width = pp_dimensions['width'] + '/embed/?moog_width='+ pp_dimensions['width'];
            
toInject = settings.iframe_markup.replace(/{width}/g,vimeo_width).replace(/{height}/g,pp_dimensions['height']).replace(/{path}/g,movie);

break;

How can I edit this match expression so that the player link outputs correctly? I feel like this should be easy, but I can't figure it out.

英文:

I'm having trouble with prettyphoto outputting the video embed links in the wrong order for unlisted videos, resulting in the video player stating that the video does not exist.

Background: the video link will be something like this:

https://vimeo.com/12345/abcde

The output becomes:

https://player.vimeo.com/video/12345?title=0&byline=0&portrait=0&autoplay=1&allowFullScreen=1;h=abcde;

As you can see, the unlisted video hash gets appended to the end of the link. It SHOULD look like this:

https://player.vimeo.com/video/12345?h=abcde&title=0&byline=0&portrait=0&autoplay=1&allowFullScreen=1;

Note the hash "h=abcde" comes after the video id "12345".

Prettyphoto uses the code below to output the video player:

case 'vimeo':
	pp_dimensions = _fitToViewport(movie_width,movie_height); // Fit item to viewport
				
	movie_id = pp_images[set_position];
	var regExp = /http(s?):\/\/(www\.)?vimeo.com\/(\d+)/;
	var match = movie_id.match(regExp);
					
	movie = 'http://player.vimeo.com/video/'+ match[3] +'?title=0&byline=0&portrait=0';
	if(settings.autoplay) movie += "&autoplay=1;";
			
	vimeo_width = pp_dimensions['width'] + '/embed/?moog_width='+ pp_dimensions['width'];
			
	toInject = settings.iframe_markup.replace(/{width}/g,vimeo_width).replace(/{height}/g,pp_dimensions['height']).replace(/{path}/g,movie);
break;

How can I edit this match expression so that the player link outputs correctly? I feel like this should be easy, but I can't figure it out.

答案1

得分: 0

以下是翻译好的代码部分:

case 'vimeo':
    pp_dimensions = _fitToViewport(movie_width, movie_height); // 将项目适应视窗

    movie_id = pp_images[set_position];
    var regExp = /^https?:\/\/(?:www\.)?vimeo\.com\/(\d+)\/(\w+)/;
    var match = movie_id.match(regExp);
    var videoId = match[1];
    var videoHash = match[2];

    movie = 'https://player.vimeo.com/video/' + videoId + '?h=' + videoHash + '&title=0&byline=0&portrait=0';
    if (settings.autoplay) movie += "&autoplay=1&";
    else movie += "&autoplay=0&";

    vimeo_width = pp_dimensions['width'] + '/embed/?moog_width=' + pp_dimensions['width'];

    toInject = settings.iframe_markup.replace(/{width}/g, vimeo_width).replace(/{height}/g, pp_dimensions['height']).replace(/{path}/g, movie);
break;

希望这有所帮助。如果有任何其他问题,请随时提出。

英文:

In case it's any use to anyone. I've figured out part of the solution to this.

I updated the Vimeo portion of the prettyphoto code to this:

case 'vimeo':
    pp_dimensions = _fitToViewport(movie_width,movie_height); // Fit item to viewport
                
    movie_id = pp_images[set_position];
    var regExp = /^https?:\/\/(?:www\.)?vimeo\.com\/(\d+)\/(\w+)/;
    var match = movie_id.match(regExp);
    var videoId = match[1];
    var videoHash = match[2];
                    
    movie = 'https://player.vimeo.com/video/'+ videoId +'?h=' + videoHash +'&title=0&byline=0&portrait=0';
    if(settings.autoplay) movie += "&autoplay=1&";
    else movie += "&autoplay=0&";

    vimeo_width = pp_dimensions['width'] + '/embed/?moog_width='+ pp_dimensions['width'];
            
    toInject = settings.iframe_markup.replace(/{width}/g,vimeo_width).replace(/{height}/g,pp_dimensions['height']).replace(/{path}/g,movie);
break;

The only thing I couldn't get around is that somehow someway, it's still appending the hash string to the end of the output URL. I couldn't figure out how to stop that from happening, so I just added the "&" after the autoplay parameter, and Vimeo seems to allow that.

Working for now, but a bit hacky.

huangapple
  • 本文由 发表于 2023年2月24日 02:03:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/75548643.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定