@@ -8,20 +8,21 @@ class Vimeo {
88 this . output = output ;
99 this . options = options ;
1010 this . embeds = embeds ;
11- this . regex = / h t t p s ? : \/ \/ (?: w w w \. ) ? v i m e o .c o m \/ (?: c h a n n e l s \/ (?: \w + \/ ) ? | g r o u p s \/ ( [ ^ \/ ] * ) \/ v i d e o s \/ | a l b u m \/ ( \d + ) \/ v i d e o \/ | ) ( \d + ) (?: $ | \/ | \? ) * / gi;
11+ this . regex = / h t t p s ? : \/ \/ (?: w w w \. ) ? v i m e o .c o m \/ (?: c h a n n e l s \/ (?: \w + \/ ) ? | g r o u p s \/ ( [ ^ \/ ] * ) \/ v i d e o s \/ | a l b u m \/ ( \d + ) \/ v i d e o \/ | ) ( \d + ) (?: $ | \/ | \? ) * / gi;
12+ this . service = 'vimeo'
1213 }
1314
1415 formatData ( data ) {
1516 return {
16- title : data . title ,
17- thumbnail : data . thumbnail_medium ,
18- rawDescription : data . description . replace ( / \n / g, '<br/>' ) . replace ( / & # 1 0 ; / g, '<br/>' ) ,
19- views : data . stats_number_of_plays ,
20- likes : data . stats_number_of_likes ,
21- description : utils . truncate ( data . description . replace ( / ( ( < | & l t ; ) b r \s * \/ * ( > | & g t ; ) \r \n ) / g, ' ' ) , 150 ) ,
22- url : data . url ,
23- id : data . id ,
24- host : 'vimeo'
17+ title : data . title ,
18+ thumbnail : data . thumbnail_medium ,
19+ rawDescription : data . description . replace ( / \n / g, '<br/>' ) . replace ( / & # 1 0 ; / g, '<br/>' ) ,
20+ views : data . stats_number_of_plays ,
21+ likes : data . stats_number_of_likes ,
22+ description : utils . truncate ( data . description . replace ( / ( ( < | & l t ; ) b r \s * \/ * ( > | & g t ; ) \r \n ) / g, ' ' ) , 150 ) ,
23+ url : data . url ,
24+ id : data . id ,
25+ host : 'vimeo'
2526 }
2627 }
2728
@@ -39,22 +40,39 @@ class Vimeo {
3940
4041 async process ( ) {
4142 try {
42- let match ;
43- while ( ( match = utils . matches ( this . regex , this . input ) ) !== null ) {
44- let embedUrl = `https://player.vimeo.com/video/${ match [ 3 ] } ` ;
45- let data , text ;
46- if ( this . options . videoDetails ) {
47- data = await this . data ( match [ 3 ] ) ;
48- text = helper . detailsTemplate ( this . formatData ( data ) , embedUrl )
49- } else {
50- text = helper . template ( embedUrl , this . options ) ;
43+ if ( ! utils . ifInline ( this . options , this . service ) ) {
44+ let regexInline = this . options . link ? new RegExp ( `([^>]*${ this . regex . source } )<\/a>` , 'gi' ) : new RegExp ( `([^\\s]*${ this . regex . source } )` , 'gi' )
45+ let match ;
46+ while ( ( match = utils . matches ( regexInline , this . output ) ) !== null ) {
47+ let id = this . options . link ? match [ 0 ] . slice ( 0 , - 4 ) . split ( '/' ) . slice ( - 1 ) . pop ( ) : match [ 0 ] . split ( '/' ) . slice ( - 1 ) . pop ( )
48+ let embedUrl = `https://player.vimeo.com/video/${ id } `
49+ let data = await this . data ( id )
50+ let text = helper . detailsTemplate ( this . formatData ( data ) , embedUrl )
51+ if ( this . options . link ) {
52+ this . output = ! this . options . inlineText ? this . output . replace ( match [ 0 ] , text + '</a>' ) : this . output . replace ( match [ 0 ] , match [ 0 ] + text )
53+ } else {
54+ this . output = ! this . options . inlineText ? this . output . replace ( match [ 0 ] , text ) : this . output . replace ( match [ 0 ] , match [ 0 ] + text )
55+ }
5156 }
57+ } else {
58+ let match ;
59+ while ( ( match = utils . matches ( this . regex , this . input ) ) !== null ) {
60+ let embedUrl = `https://player.vimeo.com/video/${ match [ 3 ] } ` ;
61+ let data , text ;
62+ if ( this . options . videoDetails ) {
63+ data = await this . data ( match [ 3 ] ) ;
64+ text = helper . detailsTemplate ( this . formatData ( data ) , embedUrl )
65+ } else {
66+ text = helper . template ( embedUrl , this . options ) ;
67+ }
5268
53- this . embeds . push ( {
54- text : text ,
55- index : match . index
56- } )
69+ this . embeds . push ( {
70+ text : text ,
71+ index : match . index
72+ } )
73+ }
5774 }
75+
5876 return [ this . output , this . embeds ] ;
5977 } catch ( error ) {
6078 console . log ( error ) ;
@@ -63,4 +81,3 @@ class Vimeo {
6381}
6482
6583module . exports = Vimeo ;
66-
0 commit comments