Skip to content

Commit 2152eb2

Browse files
authored
Merge pull request #136 from imanaspaul/fix/yt-shots-embed-regex
Added Support for YouTube Shorts
2 parents b1bba85 + 6e57008 commit 2152eb2

File tree

2 files changed

+240
-109
lines changed

2 files changed

+240
-109
lines changed

src/services.ts

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ import type { ServicesConfigType } from './serviceConfig';
33

44
const SERVICES: ServicesConfigType = {
55
vimeo: {
6-
regex: /(?:http[s]?:\/\/)?(?:www.)?(?:player.)?vimeo\.co(?:.+\/([^\/]\d+)(?:#t=[\d]+)?s?$)/,
7-
embedUrl: 'https://player.vimeo.com/video/<%= remote_id %>?title=0&byline=0',
6+
regex:
7+
/(?:http[s]?:\/\/)?(?:www.)?(?:player.)?vimeo\.co(?:.+\/([^\/]\d+)(?:#t=[\d]+)?s?$)/,
8+
embedUrl:
9+
'https://player.vimeo.com/video/<%= remote_id %>?title=0&byline=0',
810
html: '<iframe style="width:100%;" height="320" frameborder="0"></iframe>',
911
height: 320,
1012
width: 580,
1113
},
1214
youtube: {
13-
regex: /(?:https?:\/\/)?(?:www\.)?(?:(?:youtu\.be\/)|(?:youtube\.com)\/(?:v\/|u\/\w\/|embed\/|watch))(?:(?:\?v=)?([^#&?=]*))?((?:[?&]\w*=\w*)*)/,
15+
regex:
16+
/(?:https?:\/\/)?(?:www\.)?(?:(?:youtu\.be\/)|(?:youtube\.com)\/(?:v\/|u\/\w\/|embed\/|watch|shorts\/))(?:(?:\?v=)?([^#&?=]*))?((?:[?&]\w*=\w*)*)/,
1417
embedUrl: 'https://www.youtube.com/embed/<%= remote_id %>',
1518
html: '<iframe style="width:100%;" height="320" frameborder="0" allowfullscreen></iframe>',
1619
height: 320,
@@ -29,9 +32,10 @@ const SERVICES: ServicesConfigType = {
2932
list: 'list',
3033
};
3134

32-
let newParams = params.slice(1)
35+
let newParams = params
36+
.slice(1)
3337
.split('&')
34-
.map(param => {
38+
.map((param) => {
3539
const [name, value] = param.split('=');
3640

3741
if (!id && name === 'v') {
@@ -40,19 +44,21 @@ const SERVICES: ServicesConfigType = {
4044
return null;
4145
}
4246

43-
if (!(paramsMap[name])) {
47+
if (!paramsMap[name]) {
4448
return null;
4549
}
4650

47-
if (value === 'LL' ||
51+
if (
52+
value === 'LL' ||
4853
value.startsWith('RDMM') ||
49-
value.startsWith('FL')) {
54+
value.startsWith('FL')
55+
) {
5056
return null;
5157
}
5258

5359
return `${paramsMap[name]}=${value}`;
5460
})
55-
.filter(param => !!param);
61+
.filter((param) => !!param);
5662

5763
return id + '?' + newParams.join('&');
5864
},
@@ -101,30 +107,33 @@ const SERVICES: ServicesConfigType = {
101107
},
102108
'yandex-music-album': {
103109
regex: /https?:\/\/music\.yandex\.ru\/album\/([0-9]*)\/?$/,
104-
embedUrl: 'https://music\.yandex\.ru/iframe/#album/<%= remote_id %>/',
105-
html: '<iframe frameborder=\"0\" style=\"border:none;width:540px;height:400px;\" style=\"width:100%;\" height=\"400\"></iframe>',
110+
embedUrl: 'https://music.yandex.ru/iframe/#album/<%= remote_id %>/',
111+
html: '<iframe frameborder="0" style="border:none;width:540px;height:400px;" style="width:100%;" height="400"></iframe>',
106112
height: 400,
107113
width: 540,
108114
},
109115
'yandex-music-track': {
110116
regex: /https?:\/\/music\.yandex\.ru\/album\/([0-9]*)\/track\/([0-9]*)/,
111-
embedUrl: 'https://music\.yandex\.ru/iframe/#track/<%= remote_id %>/',
117+
embedUrl: 'https://music.yandex.ru/iframe/#track/<%= remote_id %>/',
112118
html: '<iframe frameborder="0" style="border:none;width:540px;height:100px;" style="width:100%;" height="100"></iframe>',
113119
height: 100,
114120
width: 540,
115121
id: (ids) => ids.join('/'),
116122
},
117123
'yandex-music-playlist': {
118-
regex: /https?:\/\/music\.yandex\.ru\/users\/([^\/\?\&]*)\/playlists\/([0-9]*)/,
119-
embedUrl: 'https://music\.yandex\.ru/iframe/#playlist/<%= remote_id %>/show/cover/description/',
124+
regex:
125+
/https?:\/\/music\.yandex\.ru\/users\/([^\/\?\&]*)\/playlists\/([0-9]*)/,
126+
embedUrl:
127+
'https://music.yandex.ru/iframe/#playlist/<%= remote_id %>/show/cover/description/',
120128
html: '<iframe frameborder="0" style="border:none;width:540px;height:400px;" width="540" height="400"></iframe>',
121129
height: 400,
122130
width: 540,
123131
id: (ids) => ids.join('/'),
124132
},
125133
codepen: {
126134
regex: /https?:\/\/codepen\.io\/([^\/\?\&]*)\/pen\/([^\/\?\&]*)/,
127-
embedUrl: 'https://codepen.io/<%= remote_id %>?height=300&theme-id=0&default-tab=css,result&embed-version=2',
135+
embedUrl:
136+
'https://codepen.io/<%= remote_id %>?height=300&theme-id=0&default-tab=css,result&embed-version=2',
128137
html: "<iframe height='300' scrolling='no' frameborder='no' allowtransparency='true' allowfullscreen='true' style='width: 100%;'></iframe>",
129138
height: 300,
130139
width: 600,
@@ -137,15 +146,16 @@ const SERVICES: ServicesConfigType = {
137146
html: '<iframe width="400" height="505" style="margin: 0 auto;" frameborder="0" scrolling="no" allowtransparency="true"></iframe>',
138147
height: 505,
139148
width: 400,
140-
id: (groups: string[]) => groups?.[0]?.split("/")[0],
149+
id: (groups: string[]) => groups?.[0]?.split('/')[0],
141150
},
142151
twitter: {
143152
regex: /^https?:\/\/(www\.)?(?:twitter\.com|x\.com)\/.+\/status\/(\d+)/,
144-
embedUrl: 'https://platform.twitter.com/embed/Tweet.html?id=<%= remote_id %>',
153+
embedUrl:
154+
'https://platform.twitter.com/embed/Tweet.html?id=<%= remote_id %>',
145155
html: '<iframe width="600" height="600" style="margin: 0 auto;" frameborder="0" scrolling="no" allowtransparency="true"></iframe>',
146156
height: 300,
147157
width: 600,
148-
id: ids => ids[1],
158+
id: (ids) => ids[1],
149159
},
150160
reddit: {
151161
regex: /https:\/\/www\.reddit\.com\/(.*)/,
@@ -166,15 +176,17 @@ const SERVICES: ServicesConfigType = {
166176
},
167177
facebook: {
168178
regex: /https?:\/\/www.facebook.com\/([^\/\?\&]*)\/(.*)/,
169-
embedUrl: 'https://www.facebook.com/plugins/post.php?href=https://www.facebook.com/<%= remote_id %>&width=500',
179+
embedUrl:
180+
'https://www.facebook.com/plugins/post.php?href=https://www.facebook.com/<%= remote_id %>&width=500',
170181
html: "<iframe scrolling='no' frameborder='no' allowtransparency='true' allowfullscreen='true' style='width: 100%; min-height: 500px; max-height: 1000px;'></iframe>",
171182
id: (ids) => {
172183
return ids.join('/');
173184
},
174185
},
175186
aparat: {
176187
regex: /(?:http[s]?:\/\/)?(?:www.)?aparat\.com\/v\/([^\/\?\&]+)\/?/,
177-
embedUrl: 'https://www.aparat.com/video/video/embed/videohash/<%= remote_id %>/vt/frame',
188+
embedUrl:
189+
'https://www.aparat.com/video/video/embed/videohash/<%= remote_id %>/vt/frame',
178190
html: '<iframe width="600" height="300" style="margin: 0 auto;" frameborder="0" scrolling="no" allowtransparency="true"></iframe>',
179191
height: 300,
180192
width: 600,
@@ -186,7 +198,8 @@ const SERVICES: ServicesConfigType = {
186198
},
187199
github: {
188200
regex: /https?:\/\/gist.github.com\/([^\/\?\&]*)\/([^\/\?\&]*)/,
189-
embedUrl: 'data:text/html;charset=utf-8,<head><base target="_blank" /></head><body><script src="https://gist.github.com/<%= remote_id %>" ></script></body>',
201+
embedUrl:
202+
'data:text/html;charset=utf-8,<head><base target="_blank" /></head><body><script src="https://gist.github.com/<%= remote_id %>" ></script></body>',
190203
html: '<iframe width="100%" height="350" frameborder="0" style="margin: 0 auto;"></iframe>',
191204
height: 300,
192205
width: 600,

0 commit comments

Comments
 (0)