Skip to content

Commit

Permalink
Match YouTube User Uploads (#877)
Browse files Browse the repository at this point in the history
  • Loading branch information
webmiraclepro committed May 22, 2020
1 parent f33fd93 commit 56dac69
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/patterns.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const MATCH_URL_YOUTUBE = /(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})|youtube\.com\/playlist\?list=/
export const MATCH_URL_YOUTUBE = /(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})|youtube\.com\/playlist\?list=|youtube\.com\/user\/?/
export const MATCH_URL_SOUNDCLOUD = /(?:soundcloud\.com|snd\.sc)\/[^.]+$/
export const MATCH_URL_VIMEO = /vimeo\.com\/.+/
export const MATCH_URL_FACEBOOK = /^https?:\/\/(www\.)?facebook\.com.*\/(video(s)?|watch|story)(\.php?|\/).+$/
Expand Down
9 changes: 8 additions & 1 deletion src/players/YouTube.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const SDK_URL = 'https://www.youtube.com/iframe_api'
const SDK_GLOBAL = 'YT'
const SDK_GLOBAL_READY = 'onYouTubeIframeAPIReady'
const MATCH_PLAYLIST = /list=([a-zA-Z0-9_-]+)/
const MATCH_USER_UPLOADS = /user\/([a-zA-Z0-9_-]+)\/?/

function parsePlaylist (url) {
if (MATCH_PLAYLIST.test(url)) {
Expand All @@ -15,6 +16,12 @@ function parsePlaylist (url) {
listType: 'playlist',
list: playlistId
}
} else if (MATCH_USER_UPLOADS.test(url)) {
const [, username] = url.match(MATCH_USER_UPLOADS)
return {
listType: 'user_uploads',
list: username
}
}
return {}
}
Expand All @@ -32,7 +39,7 @@ export default class YouTube extends Component {
const { playerVars, embedOptions } = config
const id = url && url.match(MATCH_URL_YOUTUBE)[1]
if (isReady) {
if (MATCH_PLAYLIST.test(url)) {
if (MATCH_PLAYLIST.test(url) || MATCH_USER_UPLOADS.test(url)) {
this.player.loadPlaylist(parsePlaylist(url))
return
}
Expand Down

0 comments on commit 56dac69

Please sign in to comment.