@@ -28,6 +28,25 @@ function parseId(url) {
2828 return url . match ( regex ) ? RegExp . $2 : url ;
2929}
3030
31+ // Try to extract a hash for private videos from the URL
32+ function parseHash ( url ) {
33+ /* This regex matches a hexadecimal hash if given in any of these forms:
34+ * - [https://player.]vimeo.com/video/{id}/{hash}[?params]
35+ * - [https://player.]vimeo.com/video/{id}?h={hash}[¶ms]
36+ * - [https://player.]vimeo.com/video/{id}?[params]&h={hash}
37+ * - video/{id}/{hash}
38+ * If matched, the hash is available in the named group `hash`
39+ */
40+ const regex = / ^ .* (?: v i m e o .c o m \/ | v i d e o \/ ) (?: \d + ) (?: \? .* \& * h = | \/ ) + (?< hash > [ \d , a - f ] + ) /
41+ const found = url . match ( regex )
42+
43+ if ( found ) {
44+ return found . groups . hash
45+ }
46+
47+ return null
48+ }
49+
3150// Set playback state and trigger change (only on actual change)
3251function assurePlaybackState ( play ) {
3352 if ( play && ! this . embed . hasPlayed ) {
@@ -72,6 +91,19 @@ const vimeo = {
7291 const config = player . config . vimeo ;
7392 const { premium, referrerPolicy, ...frameParams } = config ;
7493
94+ // Get the source URL or ID
95+ let source = player . media . getAttribute ( 'src' ) ;
96+ let hash = ''
97+ // Get from <div> if needed
98+ if ( is . empty ( source ) ) {
99+ source = player . media . getAttribute ( player . config . attributes . embed . id ) ;
100+ // hash can also be set as attribute on the <div>
101+ hash = player . media . getAttribute ( player . config . attributes . embed . hash ) ;
102+ } else {
103+ hash = parseHash ( source )
104+ }
105+ const hashParam = ( ! ! hash ) ? { h : hash } : { }
106+
75107 // If the owner has a pro or premium account then we can hide controls etc
76108 if ( premium ) {
77109 Object . assign ( frameParams , {
@@ -87,17 +119,11 @@ const vimeo = {
87119 muted : player . muted ,
88120 gesture : 'media' ,
89121 playsinline : ! this . config . fullscreen . iosNative ,
122+ // hash has to be added to iframe-URL
123+ ...hashParam ,
90124 ...frameParams ,
91125 } ) ;
92126
93- // Get the source URL or ID
94- let source = player . media . getAttribute ( 'src' ) ;
95-
96- // Get from <div> if needed
97- if ( is . empty ( source ) ) {
98- source = player . media . getAttribute ( player . config . attributes . embed . id ) ;
99- }
100-
101127 const id = parseId ( source ) ;
102128 // Build an iframe
103129 const iframe = createElement ( 'iframe' ) ;
0 commit comments