Register - Login
Views: 99328810
Main - Memberlist - Active users - Calendar - Wiki - IRC Chat - Online users
Ranks - Rules/FAQ - Stats - Latest Posts - Color Chart - Smilies
04-21-22 10:07:19 AM
Jul - General Chat - New YouTube BBCode tag New poll - New thread - New reply
Next newer thread | Next older thread
Xkeeper

Level: 263


Posts: 21885/25343
EXP: 296639706
For next: 2320747

Since: 07-03-07

Pronouns: they/them/????????

Since last post: 6 days
Last activity: 7 hours

Posted on 12-22-16 10:55:22 PM (last edited by Xkeeper at 12-22-16 11:14:15 PM) Link | Quote
Courtesy forums user RanAwaySuccessfully and me I guess, I had to fix it.


https://youtu.be/kYKsFrpH1rk






Alternatively, the part after the ?v=, but before any &s, in a YouTube URL.

Fake edit: Hmm, this reveals another bug when previewing a new thread. (Specifically, the preview's YouTube embed is mangled.) Hopefully this doesn't carry over to the actual post...

Actual edit: welp. This is what I get for not testing it before merging it.

Actual edit Ⅱ: It is fixed now.

____________________
(Lv 232 with 190458590 EXP)
Xkeeper

Level: 263


Posts: 21886/25343
EXP: 296639706
For next: 2320747

Since: 07-03-07

Pronouns: they/them/????????

Since last post: 6 days
Last activity: 7 hours

Posted on 12-22-16 11:06:39 PM Link | Quote
Just bumping to say that it's fixed and working now.

____________________
(Lv 232 with 190471860 EXP)
Cuber456

Fuzzy
Don't mind me. Just passing through.
Level: 56


Posts: 705/776
EXP: 1317402
For next: 80774

Since: 02-19-12

From: Everywhere at once.

Since last post: 4.2 years
Last activity: 119 days

Posted on 12-22-16 11:12:16 PM Link | Quote
Thank you Xkeeper!



____________________
Zero Time Dilemma is Out!!!
Yushe
10
Level: 10


Posts: 16/18
EXP: 3589
For next: 825

Since: 04-02-16


Since last post: 5.2 years
Last activity: 4.6 years

Posted on 12-23-16 01:37:05 AM Link | Quote
Always nice to have youtube tags.

____________________
King Of Honking!
divingkataetheweirdo

Bandit
TCRF Super Editor
Level: 57


Posts: 663/822
EXP: 1479155
For next: 6773

Since: 07-09-11


Since last post: 1.6 years
Last activity: 250 days

Posted on 12-23-16 01:39:01 AM Link | Quote
Sweet. Especially since YT removed the old embed code completely and anything using said code no longer works, AFAIK.

Thank you for finally getting around to this.

____________________
Lunaria

Moon Bunny! :3
Level: 139


Posts: 5258/5751
EXP: 31991784
For next: 475661

Since: 07-28-07

Pronouns: she/her
From: pile of fluff

Since last post: 65 days
Last activity: 5 days

Posted on 12-23-16 01:40:58 AM Link | Quote


____________________
Start 9

Q
風のノータム
Level: 105


Posts: 2736/2986
EXP: 11962935
For next: 299325

Since: 08-03-07

Pronouns: she/her
From: Nowhere

Since last post: 38 days
Last activity: 1 day

Posted on 12-23-16 02:51:16 AM Link | Quote


____________________
layout by Sofi.
RanAS
Member
Level: 55


Posts: 227/842
EXP: 1281200
For next: 32989

Since: 10-10-14

From: São Paulo, Brazil

Since last post: 21 days
Last activity: 14 hours

Posted on 12-23-16 10:47:11 AM Link | Quote
Sorry it didn't work well the first time. (like always, maybe I'm just doomed to fail)

The width="" and height="" are weird, they're actually discontinued on most tags in HTML5 which prefers you to use CSS instead, except for some "embedding" tags (canvas, embed, iframe, img, input (?), object, video) which still use these, so I thought the CSS was going to work similarly. The rest was just me being derpy with regexs.

Originally posted by Xkeeper
"Embedifying" youtube links (e.g. [youtube]youtu.be/xxxxxxxxxx[/youtube])


'\[youtube\](https://youtu\.be/)?([a-zA-Z0-9_-]{11})\[/youtube\]'si


I tested it this time, I swear. Both the share link YouTube provides and the raw video ID can be used with this. I think the backreference would need to be changed to \2 since it refers to the second group but at this point I'm not even.

?t=* isn't supported (so you can't start a video at n minutes/seconds). I was thinking about how to implement it but at this point I'm not even sure I want to mess with it again.

____________________
"If you're still young, still young, still young
Tomorrow you'll be old, you'll be old, you'll be old!
Unless your heart, your heart resists
Youth is something that never dies!"♫
Happy christmas everyone!
Arisotura
Member
Level: 49


Posts: 389/614
EXP: 879615
For next: 4268

Since: 02-24-13

From: your dreams

Since last post: 90 days
Last activity: 48 days

Posted on 12-23-16 11:08:11 AM Link | Quote
weird, I figured CSS width/height would work on iframes as well.

I think some of the deprecations are dumb though. oldstyle width/height attributes could as well be a shortcut for setting the CSS width/height, for elements that don't handle those in a special way. I'm sure browsers do that kind of thing internally anyway.

____________________
Kuribo64 -- NSMB2 hacking and other crap
einstein95
Member
Level: 37


Posts: 279/318
EXP: 325623
For next: 12630

Since: 04-11-13


Since last post: 3.3 years
Last activity: 3.2 years

Posted on 12-23-16 11:17:08 AM Link | Quote
Originally posted by RanAS
Sorry it didn't work well the first time. (like always, maybe I'm just doomed to fail)

The width="" and height="" are weird, they're actually discontinued on most tags in HTML5 which prefers you to use CSS instead, except for some "embedding" tags (canvas, embed, iframe, img, input (?), object, video) which still use these, so I thought the CSS was going to work similarly. The rest was just me being derpy with regexs.

Originally posted by Xkeeper
"Embedifying" youtube links (e.g. [youtube]youtu.be/xxxxxxxxxx[/youtube])


'\[youtube\](https://youtu\.be/)?([a-zA-Z0-9_-]{11})\[/youtube\]'si


I tested it this time, I swear. Both the share link YouTube provides and the raw video ID can be used with this. I think the backreference would need to be changed to \2 since it refers to the second group but at this point I'm not even.

?t=* isn't supported (so you can't start a video at n minutes/seconds). I was thinking about how to implement it but at this point I'm not even sure I want to mess with it again.


Using

'\[youtube\](?:https://youtu\.be/)?([a-zA-Z0-9_-]{11})\[/youtube\]'si


means it doesn't catch the first group for backreference, so you can keep the \1

____________________
Sometimes I English very well but sometimes no.
dotUser
From the Grave
Level: 91


Posts: 2195/2357
EXP: 7417138
For next: 51774

Since: 10-20-10

Pronouns: she/her
From: a particularly peculiar tiny store's back shelf

Since last post: 22 days
Last activity: 6 days

Posted on 12-23-16 11:17:17 AM Link | Quote
GNU dotUser 2.1.2-git        File: ~/.user/makepost.py

So is this basically the new youtube thread now because...

____________________
^W Web^B Tumblr^^^^
^T Twitter^P ~town^^^^
Xkeeper

Level: 263


Posts: 21896/25343
EXP: 296639706
For next: 2320747

Since: 07-03-07

Pronouns: they/them/????????

Since last post: 6 days
Last activity: 7 hours

Posted on 12-23-16 04:51:03 PM (last edited by Xkeeper at 12-23-16 04:51:27 PM) Link | Quote
Originally posted by Somebody
?t=* isn't supported (so you can't start a video at n minutes/seconds). I was thinking about how to implement it but at this point I'm not even sure I want to mess with it again.

A solution might be to do a awkward match on something like this:
youtu(\.be|be\.com)/(?:watch?v=)(a-zA-Z0-9_-]{11}(?:&.*)(#t=[0-9hms:]+)

But that is getting to be rather complicated, I think. I don't have a way to test it easily at the moment.
Technically, supporting "width=" and "height=" in the youtube tag could be done, too. There are lots of options.


Originally posted by StapleButter
weird, I figured CSS width/height would work on iframes as well.

I think some of the deprecations are dumb though. oldstyle width/height attributes could as well be a shortcut for setting the CSS width/height, for elements that don't handle those in a special way. I'm sure browsers do that kind of thing internally anyway.


It does work, but I wanted to keep it consistent with the "official" behavior. As for why the official one uses width/height and not CSS, you would have to ask them. I wonder if it has something to do with possibly overzealous content platforms going "Inline styles! Zounds!" and externalizing it? (Surely not, but it's fun to think about.)


Originally posted by dotUser
So is this basically the new youtube thread now because...

I mean, technically, you're not wrong.

____________________
(Lv 232 with 190622772 EXP)
Zero One
5170
And as we fall the spirit carries on,
That a hero'll come and save us all,
As we call the ones we left below,
We all dream of the day we rise above
Level: 129


Posts: 5016/5173
EXP: 24538260
For next: 511394

Since: 05-24-10

From: Delta Quadrant

Since last post: 1.5 years
Last activity: 118 days

Posted on 12-28-16 05:54:17 PM Link | Quote
I'm gonna test this out with some awesome music:



____________________
This is a Heisenberg post. I know I posted this really fast, but I don't know where...

My games development portfolio and my MonoTroid engine

My YouTube Channel
My Twitch. Check it! 3DS Code: 2879-0110-5138
RanAS
Member
Level: 55


Posts: 232/842
EXP: 1281200
For next: 32989

Since: 10-10-14

From: São Paulo, Brazil

Since last post: 21 days
Last activity: 14 hours

Posted on 12-28-16 09:58:00 PM Link | Quote

youtu(\.be|be\.com)/(?:watch?v=)(a-zA-Z0-9_-]{11}(?:&.*)(#t=[0-9hms:]+) 


Nope, that code won't work without a few adjustments.

Easiest way I have to test things is RegExr, and even then it has a bunch of technicalities to it.


'\[youtube\](?:https://(?:www\.)?youtu(?:\.be/|be\.com/watch\?v=))?([\w-]{11})(?:(?:\?|\&)t=\w{1,})?\[/youtube\]'si


I know there might be more escaped characters than needed, it's just that normally either RegExr or JS (or both) will complain if you don't escape a few extra characters, even though they seem valid in PHP. This will catch either the YouTube video URL, the YouTube share link or the video ID and supports the t=4s variable too. I didn't bother to make it check specifically for the right syntax, so if someone wrote t=potato it will accept it, but it won't accept it if someone tries to write t=4s&autoplay=1 because it'll look at the & and "autoplay=" and realize that it isn't equal to "t=" and reject it (you can't even put multiple "t=" because it only looks for one).

Originally posted by Xkeeper
Technically, supporting "width=" and "height=" in the youtube tag could be done, too. There are lots of options.

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA. That is all.

More variables = higher chances of me derping up something, and hell if I know how to implement both height and width in BBcode and backreference it properly. You also need to have a minimum/maximum height/width too to make sure it doesn't get abused. It can be done, though. I guess [youtube width="600" height="400"]https://www.youtube.com/watch?v=FZBnxoKl3tY[/youtube] could work.


'\[youtube( width=\d{3})?( height=\d{3})?\](?:https://(?:www\.)?youtu(?:\.be/|be\.com/watch\?v=))?([\w-]{11})(?:(?:\?|\&)t=\w{1,})?\[/youtube\]'si


You cannot put them in reverse order because derp (width first, then height). Minimum width/height would be 100px, maximum would be 999px. Feel free to suggest lower/higher values, reminder that regexs only check the amount of digits not the values themselves so I can only check if the amount of digits is n or higher/lower (or exactly n). There's no escaping this one, the backreference will need to be changed to \3 and there needs to be default values added to some prior variable in the case height and width are not specified.

Second regex value (the output) would be:

'<iframe src="https://www.youtube.com/embed/\3"\1\2 frameborder="0" allowfullscreen="allowfullscreen"></iframe>'



In this case, there needs to be something that will specify a value for \1 and \2 in case there's none. I would know how to do this in JavaScript (store in variable previously to replacement, check if variable is valid, if it isn't then generate a default one, insert it on the full regex code, replace). Something like:

var msg = "[youtube height=999 width=500]"; //This is the post message to be decoded.


widthVar = msg.match(/width=\d{3}/i)
heightVar = msg.match(/height=\d{3}/i)

if (!widthVar) {widthVar = " width=560";}
if (!heightVar) {heightVar = " width=315";}


But in PHP instead of JS. Then it would just be matter of calling those values into the regex instead of \1 and \2. I guess if we're going this route somehow then you could also check the values to see if they're <minimum or >maximum properly instead of relying on regexs.

I'm making myself confused. Is this complicated enough? Should I make it more complicated?

____________________
"I cannot remember the books I've read
any more than the meals I have eaten;
even so, they have made me." --Ralph Waldo Emerson
You have just entered the realm of awesome music.
Xkeeper

Level: 263


Posts: 21937/25343
EXP: 296639706
For next: 2320747

Since: 07-03-07

Pronouns: they/them/????????

Since last post: 6 days
Last activity: 7 hours

Posted on 12-29-16 11:23:44 PM Link | Quote
It would probably be easier to do something like this via a callback function. Though to be honest the entire concept of filtering, pseudo-BBCode, and so on probably needs rewritten.

____________________
(Lv 232 with 191331559 EXP)
Arisotura
Member
Level: 49


Posts: 395/614
EXP: 879615
For next: 4268

Since: 02-24-13

From: your dreams

Since last post: 90 days
Last activity: 48 days

Posted on 12-29-16 11:29:10 PM Link | Quote
PHP has a bbcode extension, but it requires manually installing shit. Might have changed with PHP7, but no idea.


Other than that, I have seen (and written) different, more 'proper' approaches to BBCode and HTML parsing. But in the end I think it's barely worth the trouble.

____________________
Kuribo64 -- NSMB2 hacking and other crap
Xkeeper

Level: 263


Posts: 21940/25343
EXP: 296639706
For next: 2320747

Since: 07-03-07

Pronouns: they/them/????????

Since last post: 6 days
Last activity: 7 hours

Posted on 12-29-16 11:32:13 PM Link | Quote
Originally posted by StapleButter
PHP has a bbcode extension, but it requires manually installing shit. Might have changed with PHP7, but no idea.


Other than that, I have seen (and written) different, more 'proper' approaches to BBCode and HTML parsing. But in the end I think it's barely worth the trouble.

I am sure better alternatives are available. Honestly, the best way might just be to have something that operates on the BBCode first, then iterates over the post like a mini-DOM and works on filtering out certain disallowed attributes and things. (But it gets really complicated.)

I would agree that it is not really worth the trouble.

____________________
(Lv 232 with 191370971 EXP)
Next newer thread | Next older thread
Jul - General Chat - New YouTube BBCode tag New poll - New thread - New reply


Rusted Logic

Acmlmboard - commit 47be4dc [2021-08-23]
©2000-2022 Acmlm, Xkeeper, Kaito Sinclaire, et al.

33 database queries, 2 query cache hits.
Query execution time: 0.088586 seconds
Script execution time: 0.035386 seconds
Total render time: 0.123972 seconds