Youtube Playlist Syntax Change

Hello,

I’m putting together a playlist sharing script and I’m having difficulty adding new arrays for Youtube’s new url variations with playlists. For example…

[code]https://www.youtube.com/watch?v=h82o28mZ1c0&list=PLFECE7FC63DE15EA3 <<<<<THIS WORKS!

http://www.youtube.com/playlist?list=PLFECE7FC63DE15EA3 <<<<<Displays link text
http://youtu.be/h82o28mZ1c0?list=PLFECE7FC63DE15EA3 <<<<<Displays single video
http://www.youtube.com/embed/h82o28mZ1c0?list=PLFECE7FC63DE15EA3 <<<<<Displays the link text[/code]

Here’s the code. How do I add new arrays for the other youtube url variations?

[code]$types = array(
‘youtube’=>array(
array(
‘https{0,1}://w{0,3}.youtube.com/watch?\Sv=([A-Za-z0-9_-]+)&list=([A-Za-z0-9_-]+)[^< ]*’,
‘’
),
array(
‘https{0,1}://w{0,3}.youtu.be/([A-Za-z0-9_-]+)[^< ]’,
‘’
)
),

			'soundcloud'=>array(
				array(
					'https{0,1}:\/\/w{0,3}\.*soundcloud\.com\/([-\%_\/.a-zA-Z0-9]+\/[-\%_\/.a-zA-Z0-9]+)[^< ]*',
					'<iframe width="100%" height="450" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=https://soundcloud.com/$1&amp;auto_play=false&amp;hide_related=false&amp;show_comments=true&amp;show_user=true&amp;show_reposts=false&amp;visual=true"></iframe>'
				)
			),		

		);[/code]

https
http

Different links. You are arraying https only.

https?:\/\/(www\.)?youtube\.com\/watch\?v=([A-Za-z0-9]+)&list=([A-Za-z0-9])+ https?:\/\/(www\.)?youtube\.com\/playlist\?list=([A-Za-z0-9]+) https?:\/\/(www\.)?youtube\.com\/embed\/([A-Za-z0-9]+)\?list=([A-Za-z0-9]+) https?:\/\/(www\.)?youtu\.be\/([A-Za-z0-9]+)\?list=([A-Za-z0-9]+)

These are the regex’s I would use.
Note in your replacements, you would look in the regex pattern and count he paren pairs. $1, in my pattern is the www. (ignore it) So the tokens would be $2 and $3.

Final Note: the patterns you had DO check for http and https but the size parameter isnt needed when working with 1 character. {min,max} all is needed is the ? for an optional.
The one you posted took 0-3 w (,w,ww,www) all would be acceptable, howver the dot is mandatory so youtube.com would always fail, as the pattern is expecting .youtube.com

Sponsor our Newsletter | Privacy Policy | Terms of Service