Go Back   vb.org Archive > vBulletin Article Depository > Read An Article > vBulletin 3 Articles
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
How to create definitions for AME 2.5
BirdOPrey5's Avatar
BirdOPrey5
Join Date: Jun 2008
Posts: 10,610

The details of my life are quite inconsequential.

New York
Show Printable Version Email this Page Subscription
BirdOPrey5 BirdOPrey5 is offline 05-15-2011, 10:00 PM

If you use the Automatic Media Embedder mod for vBulletin 3.8 and you want to learn how to make your own definitions this is a lesson.

AME 2.5 Mod: https://vborg.vbsupport.ru/showthread.php?t=202476
Digital Jedi's Definitions: https://vborg.vbsupport.ru/showthread.php?t=195884

You will need some knowledge of "regular expressions" to do this. I suggest reading over the introduction and some of the pages on this site: http://www.regular-expressions.info/tutorial.html.

The more you know the easier it will be of course.

Also I strongly strongly urge you to download RegexBuddy. There is a free trial but you will need to buy it if you continue to use it.

This lesson will assume you have RegexBuddy.

We will create a custom video definition, it will introduce you to the basics on which you can build.

One of the simplest video sites out there is TwitVid.

A sample TwitVid URL is: http://www.twitvid.com/38UOE however http://twitvid.com/38UOE is also a valid link.

The "38UOE" is the unique ID of each video.

Before we start making a definition we need to make sure the site allowed their media to be embedded, not all do. Make sure they give you the option to have embed code on the video, which TwitVid does.

Step 1: Copy and paste the URL of the video into the two main boxes of RegexBuddy. You should also make sure the "case insensitive" button is pressed because AME is not case sensitive.



The top box is going to be the actual regular expression, we will edit it. The lower box will remain the original URL. The goal will be to have the URL in the bottom box completely highlighted in yellow by the time we are done.

"But it's already yellow." That is true, but as is it would only work for this 1 video. We need to edit it so it works for all TwitVid videos.

The next step is we must "escape" all special characters in the regular expression (top box.) RegexBuddy will highlight special characters in light blue, and as you can see periods (.) are special characters in regular expressions. So are question marks (?). There are more but these are the most common.

To "escape" a special character you simply put a backslash (\) in front of it. Go ahead and escape all the special characters in the top box:



As you can see all the blue highlighting has been removed now that all special characters are escaped.

Now comes the "hard" part. We need to do something with that unique id. (38UOE). When we come to an ID theres really only one decision to make.

\d - This will match any digit, 0 to 9
\w - This will match any "word" character which for regex can be any letter or number or underscore character.

Since TwitVid uses both letters AND numbers in their IDs we must use \w.

We now need to "build" on \w... Ultimately we will end up with: ([\w]+)

Let me explain the why...

First the parentheses ( and ). These tell the program you want to use the data matched inside them later in the program. In our case this means we want to use the data inside them in our embed code. You can have multiple sets of parentheses in a regular expression. You can access them in the embed code as $p1, $p2, $p3... etc... $p1 being the left most set of parentheses and incrementing from left to right.

The square brackets [ and ]. Inside of these you put all the possible characters you need to match. Remember \w is a short-cut to say "match ANY letter or ANY number or an underscore. In TwitVid's case this is all you need. However if another site maybe had dashes (-) in their ID you would need to add that here. ([\w-]+) for example. If it had dashes and number signs and ampersands we'd use ([\w-#&]+).

But back tot he case at hand, for TwitVid it's just ([\w]+).

Last but least is the plus sign (+). The plus sign tells us that we can match 1 OR MORE of the characters specified in the square brackets. In our case that means it can match 1 or more letters OR numbers (or underscores.)

To better illustrate the + sign edit the regex in RegexBuddy. Replace 38UOE with ([\w]).



You'll see only the "3" is highlighted in the bottom box. This is because without the plus sign our regex will only match the 1st character in our ID. Go ahead and put that + back in now: ([\w]+).



Now you will see the whole line is highlighted. Remember the + means to match 1 OR MORE characters in the square brackets. If you used an asterisks (*) instead that would mean ZERO OR MORE of the characters in the square brackets.

Well it looks like we're done, right? At least with the regex, right?

Sorry... not yet. Remember there is a second URL possibility for TwitVid, the one without the "www" in the URL: http://twitvid.com/38UOE

Go paste that URL in the bottom box of regex buddy above or below the current URL:



As you can see none of that second URL is highlighted. How can we get 1 regex to match both URLs? The answer here lies in the * I just told you about. We can put the "www" inside square brackets and follow it by an * and that will tell the regex it can match either with or without the www. Actually we need to put the period after www in the brackets as well, and that period is escaped so all in all we need to put www\. into brackets.

Replace www\. with [www\.]*



Now you can see both URLs are highlighted. (RegexBuddy alternates highlight colors.)

So now we are finally done with the "hard part" of this exercise- but we're not done. Now we have to put this info into the AME Settings and edit the embed code.

In your Admin CP go to AME CP and then "Add a New Definition."



Title and Description are up to you but I'd suggest something like: TwitVid and "TwitVid Video."

The Unique Key is again up to you- just make sure you don't use one already in use on your forum. I'd go simple again like: twitvid.

Display Order: Totally up to you

Active: Yes

Contain: Yes

Regular Expression: Here we copy the regex from the top box of RegexBuddy.

Replacement: For now paste in the Embed code provided by TwitVid for this video:
Code:
<iframe title="Twitvid video player" class="twitvid-player" type="text/html" width="480" height="360" src="http://www.twitvid.com/embed.php?guid=38UOE&autoplay=0" frameborder="0"></iframe>
We must edit the above code since it is only for the video in the example. We need to look for the ID of the video and replace it with $p1 which is the first (and only) parameter we created by using parentheses in our regular expression.

Turn the above code into:

Code:
<iframe title="Twitvid video player" class="twitvid-player" type="text/html" width="480" height="360" src="http://www.twitvid.com/embed.php?guid=$p1&autoplay=0" frameborder="0"></iframe>
There's a couple more changes we can make at this point. Instead of using the default height and width supplied by TwitVid we can replace them with height and width settings we made in the AME settings. Not all sites will allow you to do custom sizes but it doesn't hurt to try. You will need to change the specified width of 480 to $ameinfo[width] and the height of 360 to $ameinfo[height]. The final replacement code should then be:

Code:
<iframe title="Twitvid video player" class="twitvid-player" type="text/html" width="$ameinfo[width]" height="$ameinfo[height]" src="http://www.twitvid.com/embed.php?guid=$p1&autoplay=0" frameborder="0"></iframe>
Now paste the above code into the Replacement box of the AME Definition.

The Extraction Information options can remain blank, those are only needed for advanced definitions which are rarely needed.



Now hit SAVE and you should have made your first working custom AME definition!

Let's check it out in action: Link to Embedded Video

:up:
Attached Images
File Type: jpg regex2.jpg (64.5 KB, 0 views)
File Type: jpg regex3.jpg (64.2 KB, 0 views)
File Type: jpg regex4.jpg (64.0 KB, 0 views)
File Type: jpg regex5.jpg (66.0 KB, 0 views)
File Type: jpg regex6.jpg (66.3 KB, 0 views)
File Type: jpg ame1.jpg (117.2 KB, 0 views)
File Type: jpg ame2.jpg (104.6 KB, 0 views)
File Type: jpg regex1.jpg (64.8 KB, 0 views)
Reply With Quote
  #2  
Old 05-16-2011, 11:02 AM
MagicThemeParks's Avatar
MagicThemeParks MagicThemeParks is offline
 
Join Date: Sep 2009
Posts: 850
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Nice work, this should definitely help folks get some definitions going :up:
Reply With Quote
  #3  
Old 06-07-2011, 09:28 AM
kNeeLy's Avatar
kNeeLy kNeeLy is offline
 
Join Date: Nov 2008
Location: ohio
Posts: 244
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

wow!! Nice!!
Reply With Quote
  #4  
Old 10-14-2011, 02:54 PM
SamirDarji SamirDarji is offline
 
Join Date: Apr 2004
Posts: 645
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Noting this for future reference.
Reply With Quote
  #5  
Old 02-07-2015, 11:32 PM
Brandon Sheley's Avatar
Brandon Sheley Brandon Sheley is offline
 
Join Date: Mar 2005
Location: Google Kansas
Posts: 4,678
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Great article Joe
Reply With Quote
  #6  
Old 04-14-2021, 06:03 PM
ccr1969 ccr1969 is offline
 
Join Date: Nov 2006
Posts: 3
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hello i got a quick ? regarding cnn how can i get any video to play
i have this and it only works with some
Code:
https://[www\.]*cnn\.com/videos/([\w]+)/([\w]+)/([\w]+)/([\w]+)/([\w-]+)\.([\w]+)/([\w]+)/([\w]+)/([\w-]+)/
and
Code:
<iframe width="$ameinfo[width]" height="$ameinfo[height]" src="https://fave.api.cnn.io/v1/fav/?customer=cnn&amp;env=prod&amp;video=$p1/$p2/$p3/$p4/$p5.cnn" frameborder="0" allowfullscreen></iframe>
any help be appreciated
https://runner.ga/showthread.php?p=739#post739
for refrence
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 05:07 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04348 seconds
  • Memory Usage 2,293KB
  • Queries Executed 22 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (5)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_article
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (6)post_thanks_box
  • (6)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (6)post_thanks_postbit_info
  • (5)postbit
  • (8)postbit_attachment
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_attachment
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete