-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add video thumbnails to the reciple display pages (#377)
- Loading branch information
1 parent
1e57666
commit 2f4b331
Showing
9 changed files
with
54 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,34 @@ | ||
|
||
export function isVideoUrlSupported(url: string) { | ||
return !url | ||
|| url.startsWith("https://www.youtube.com/") | ||
|| url.startsWith("https://m.youtube.com/") | ||
|| url.startsWith("https://youtu.be/"); | ||
} | ||
|
||
export function getThumbnail(url: string) { | ||
const id = getVideoId(url); | ||
|
||
return `https://img.youtube.com/vi/${id}/0.jpg`; | ||
} | ||
|
||
export function prepareUrlForEmbed(url: string) { | ||
const id = getVideoId(url); | ||
|
||
return `https://www.youtube.com/embed/${id}`; | ||
} | ||
|
||
function getVideoId(url: string) { | ||
const regexp = /watch\?v=([\w-]*)|embed\/([\w-]*)|youtu\.be\/([\w-]*)/; | ||
|
||
// get the capture group from regexp | ||
const match = regexp.exec(url); | ||
if (!match) { | ||
return ""; | ||
} | ||
|
||
// there are 3 possible matches in the regex | ||
// the code below checks for all of them | ||
// and returns the first one that is not null | ||
const id = match[1] || match[2] || match[3]; | ||
|
||
return `https://www.youtube.com/embed/${id}`; | ||
return match[1] || match[2] || match[3]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters