Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: [MOD] Video Button for Youtube, Google Video etc. (sNews 1.5RC1-2)  (Read 8735 times)

Smoothie

  • Newbie
  • *
  • Karma: 0
  • Posts: 18
    • http://rob3rt.net

mod for sNews 1.5

At my site ( http://rob3rt.net/ ), I frequently post videos from the popular sites Google Video and Youtube.

Unfortunately, this becomes quite an arduous task considering that both sites provide terrible code for embedding.  Terrible, in that it is nowhere near standards compliant (which I need the sites to be, as a web developer - although I stick with backends).

So, I created a handy dandy button for the same area as Link, Image, etc.  This button, when clicked, prompts for the user to enter the page on which the video is shown such as http://youtube.com/watch?v=dYJOF8drAkw , then it creates standards-compliant and widely-compatible code to display the video.  Easy!

It currently works with YouTube and Google Video, since these are the sites I use to obtain videos.  If you're after support for any more, reply.

Anyway, here's how you do it:

To add the button:
Code: [Select]
[FIND]
html_input('button', '', '', 'Include', '', 'button', 'onclick="tags(\'include\')"', '', '', '', '', '', '', '', '');

[ADD AFTER]
html_input('button', '', '', 'Video', '', 'button', 'onclick="tags(\'video\')"', '', '', '', '', '', '', '', '');
To add the corresponding Javascript:
Code: [Select]
[FIND]
if(url != null) { start = "[include]" + url + "[/include]"; end = ""; } else { start = ""; end = ""; }

[ADD AFTER]
}else if(tag == 'video'){

var url = prompt("Please enter the video page URL", "");
 
if(url.indexOf("google") != -1){
var videoRegex = new RegExp("docid=([^&]+)");
var videoMatch = videoRegex.exec(url);
var videoID = videoMatch[1];
var start = "";
var end = "";

}else if(url.indexOf("youtube") != -1){
var videoRegex = new RegExp("v=([^&]+)");
var videoMatch = videoRegex.exec(url);
var videoID = videoMatch[1];
var start = "";
var end = "";
}
...And you should be done :)

Any comments / questions / suggestions, please let me know.

4Sandrix

  • Hero Member
  • *****
  • Karma: -13
  • Posts: 599
    • http://fedrick.deviantart.com
[MOD] Video Button for Youtube, Google Video etc. (sNews 1.5RC1-2)
« Reply #1 on: October 06, 2006, 08:52:20 PM »

hehe very exotic mod :) Thanks Smoothie
Logged
I'm kind of like Han Solo always strokin' my own Wookiee
I'm the root of all that's evil yeah but you can call me Cookie

Smoothie

  • Newbie
  • *
  • Karma: 0
  • Posts: 18
    • http://rob3rt.net
[MOD] Video Button for Youtube, Google Video etc. (sNews 1.5RC1-2)
« Reply #2 on: October 06, 2006, 11:15:27 PM »

There are plenty more where that came from :) I often dabble in creating bits and bobs of generally useful PHP snippets.

By the way, please reply if anyone uses this - I'd be interested in linking to places using it and / or confirming that it works 100%.

Cheers,
Rob

// EDIT: My Javascript is rusty, so if anyone knows of a better / more efficient way of writing the javascript, please let me know.  Thanks!

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca
[MOD] Video Button for Youtube, Google Video etc. (sNews 1.5RC1-2)
« Reply #3 on: October 07, 2006, 04:38:05 AM »

Fabulous Smoothie - a generous contribution. Good to see you adding to our PHP "Gene Pool"... the more the merrier! :)
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

iatbm

  • Sr. Member
  • ****
  • Karma: 0
  • Posts: 251
    • Public domain photos
[MOD] Video Button for Youtube, Google Video etc. (sNews 1.5RC1-2)
« Reply #4 on: October 07, 2006, 10:47:17 AM »

Hey This is very nice :D I just got idea for my new site and using this hehe

Smoothie

  • Newbie
  • *
  • Karma: 0
  • Posts: 18
    • http://rob3rt.net
[MOD] Video Button for Youtube, Google Video etc. (sNews 1.5RC1-2)
« Reply #5 on: October 07, 2006, 12:27:53 PM »

Thanks for the feedback :) I'll be sure to contribute anything else that springs to mind in the near future.

robin1973

  • Newbie
  • *
  • Karma: 0
  • Posts: 5
[MOD] Video Button for Youtube, Google Video etc. (sNews 1.5RC1-2)
« Reply #6 on: October 21, 2006, 09:18:30 PM »

Thanks for great mod.

I used it on my page with some modyfications. I like play my own video that way.

little fix:
Code: [Select]
html_input('button', '', '', 'Video', '', 'button', 'onclick="tags(\'video\')"', '', '', '', '', '', '', '', '');doesn't work for me

but
Code: [Select]
html_input('button', 'Video', '', 'Video', '', 'button', 'onclick="tag(\'video\')"', '', '', '', '', '', '', '', '');works great

My modyfication - playing my own video

1. Upload video file to http://myhomedir/video/   for example "demo.avi"
2. Modify code

before
Code: [Select]
else if(url.indexOf("youtube") != -1){add

Code: [Select]
     else if(url.indexOf("my") != -1){
                var videoRegex         = new RegExp("=([^&]+)");
                var videoMatch         = videoRegex.exec(url);
                 var videoID            = videoMatch[1];
                 var start             = "";
               
                var end                = "";
            }
changing twice http://direct-london.co.uk/video/ to your URL site

4. After pressing Video button in sNews  editor simple write my=demo.avi in prompt URL


I think it's possible to change URL adres in sample above to db('website') but I don't know how yet  :-(

mosh

  • Hero Member
  • *****
  • Karma: 77
  • Posts: 510
  • Awesome day :)
    • cms-zen
[MOD] Video Button for Youtube, Google Video etc. (sNews 1.5RC1-2)
« Reply #7 on: October 21, 2006, 11:14:52 PM »

thanks for the mod :)

it dosnt work for me,

the button shows, it popup a small window where i enter the youtube address,
but it dont do nothing after i press the ok.

i did try the fix, but didnt work.

thank you :)

Smoothie

  • Newbie
  • *
  • Karma: 0
  • Posts: 18
    • http://rob3rt.net
[MOD] Video Button for Youtube, Google Video etc. (sNews 1.5RC1-2)
« Reply #8 on: October 21, 2006, 11:16:41 PM »

Might be because I wrote the mod for RC1 of sNews.  I'll look into it when I get the time.

robin1973

  • Newbie
  • *
  • Karma: 0
  • Posts: 5
[MOD] Video Button for Youtube, Google Video etc. (sNews 1.5RC1-2)
« Reply #9 on: October 21, 2006, 11:26:14 PM »

I am using this mod with latest sNews15RC2 version and works good (after fix one line)
Code: [Select]
 html_input('button', 'Video', '', 'Video', '', 'button', 'onclick="tag(\'video\')"', '', '', '', '', '', '', '', '');

mosh

  • Hero Member
  • *****
  • Karma: 77
  • Posts: 510
  • Awesome day :)
    • cms-zen
[MOD] Video Button for Youtube, Google Video etc. (sNews 1.5RC1-2)
« Reply #10 on: October 21, 2006, 11:35:46 PM »

i did try the fix, no luck :)

thank you