Who needs a Video Clip?

Discussion in 'General Discussion' started by Vorak, Nov 2, 2006.

Remove all ads!
Support Terra-Arcanum:

GOG.com

PayPal - The safer, easier way to pay online!
  1. Dark Elf

    Dark Elf Administrator Staff Member

    Messages:
    10,796
    Media:
    34
    Likes Received:
    164
    Joined:
    Feb 6, 2002
    Until such time that I've figured out how to convert all the Youtube embedding code to actual videos, you'll have to make do with the Youtube tags I haxx0red in.
     
  2. Crypton

    Crypton Member

    Messages:
    589
    Likes Received:
    2
    Joined:
    May 22, 2008
    Let me help you with that, so I can triple post lame-ass videos once again. Here, I wrote you a script that should do it:

    Code:
    <?php
    $host = '127.0.0.1';
    $username = 'root';
    $password = 'password';
    $database = 'name';
    $table_name = 'phpbb_posts';
    
    $conn = mysql_connect($host, $username, $password);
    
    if (!$conn) {
        echo "Unable to connect to DB: " . mysql_error();
        exit;
    }
    
    if (!mysql_select_db($database)) {
        echo "Unable to select " . $database . ": " . mysql_error();
        exit;
    }
    
    $sql = "SELECT post_id, post_text FROM {$table_name}";
    
    $result = mysql_query($sql);
    
    if (!$result) {
        echo "Could not successfully run query ($sql) from DB: " . mysql_error();
        exit;
    }
    
    if (mysql_num_rows($result) == 0) {
        echo "No rows found, nothing to print so am exiting";
        exit;
    }
    
    while ($row = mysql_fetch_assoc($result)) {
    
        $post_id = $row['post_id'];
        $post_text = $row['post_text'];
        $pattern = "%(<object.*?>)(.*)http://www.youtube.com/v/(.*)([\?].*)(<\/object.*?>)%is";
        $post_text = preg_replace($pattern, "[youtube]http://www.youtube.com/watch?v=$3[/youtube]", $post_text);
    	
        $post_text = mysql_real_escape_string($post_text);
        $post_text_checksum = md5($post_text);
    	
        echo "{$post_text} <br /> {$post_text_checksum} <br />";
    	
        $sql = "UPDATE {$table_name} SET post_text='{$post_text}', post_text_checksum='{$post_text_checksum}' WHERE post_id={$post_id}";
        mysql_query($sql);
    }
    
    mysql_free_result($result);
    mysql_close($conn);
    ?>
    
    It replaces:
    Code:
    <object width="560" height="315"><param name="movie" value="http://www.youtube.com/v/ET9SNXpeORY?version=3&amp;hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/ET9SNXpeORY?version=3&amp;hl=en_US" type="application/x-shockwave-flash" width="560" height="315" allowscriptaccess="always" allowfullscreen="true"></embed></object>
    To:

    Code:
    [youtube]http://www.youtube.com/watch?v=ET9SNXpeORY[/youtube]
    Now you only have add a custom youtube bbcode through the admin panel. Here's the code: https://www.phpbb.com/customise/db/bbcode/youtube/

    Cheers :hippy:

    P.S. I also have to mention that you should not forget to backup the db before you begin, and purge the phpbb cache after you ran the script.
     
  3. Dark Elf

    Dark Elf Administrator Staff Member

    Messages:
    10,796
    Media:
    34
    Likes Received:
    164
    Joined:
    Feb 6, 2002
    Thank you Crypton, I'll look into it once I get home from work this evening / Aurdal will beat me to it.
     
  4. Xz

    Xz Monkey Admin Staff Member

    Messages:
    5,085
    Likes Received:
    4
    Joined:
    May 31, 2003
    On the trial run on my local copy of the database your script seems to have done little. This seems to be because the <object> tags are actually stored as &lt;object&gt; in the database. I'm no good with regex, but I'll see if I can tweak it.


    Edit:
    This pattern seems to work. But still no changes in the database.
    Code:
    $pattern = "%(\&lt\;object.*?\&gt\;)(.*)http://www.youtube.com/v/(.*)([\?].*)(\&lt\;\/object.*?\&gt\;)%is";
     
  5. Crypton

    Crypton Member

    Messages:
    589
    Likes Received:
    2
    Joined:
    May 22, 2008
    I have tested that script myself before I posted it here and it worked correctly. However, I'm using the latest version of PHP, MySQL and phpbb. If you guys were using phpbb v2 or older, then the content of the post_text might be formatted differently.

    When you run the script, does it output something? perhaps text of fixed posts? I don't have the access to the db, so I can't really tell where is the problem. Could you export a one random row (with the youtube video) from the phpbb_posts table, and send it to me through PM, so I can see how much are those tables different?
     
  6. Xz

    Xz Monkey Admin Staff Member

    Messages:
    5,085
    Likes Received:
    4
    Joined:
    May 31, 2003
    The problem was that post_text_checksum is only called post_checksum in the database structure. Also since it was empty for all the old posts I just took it out. However, there's another problem. If there's more than one video in the post only the first one will be converted. The others disappear completely. I suspect that also goes for any other content following a video.
     
  7. Crypton

    Crypton Member

    Messages:
    589
    Likes Received:
    2
    Joined:
    May 22, 2008
    Oupies, you're right, my fault :) Here is the fixed body of the while loop:

    Code:
    {
        $post_id = $row['post_id'];
        $post_text = $row['post_text'];
    	
        $pattern = '%\&lt\;object.*?\&gt\;(.*)http://www.youtube.com/v/(.*)[\?].*(.*)\&lt\;\/object.*?\&gt\;%i';
        $post_text = preg_replace($pattern, "[youtube]http://www.youtube.com/watch?v=$2[/youtube]", $post_text);
    	
        $post_checksum = md5($post_text);
        $post_text = mysql_real_escape_string($post_text);
    	
        echo "{$post_text} <br /> {$post_checksum} <br />";
    	
        $sql = "UPDATE {$table_name} SET post_text='{$post_text}', post_checksum='{$post_checksum}' WHERE post_id={$post_id}";
        mysql_query($sql);
    }
    
     
  8. Zanza

    Zanza Well-Known Member

    Messages:
    3,296
    Likes Received:
    61
    Joined:
    Apr 20, 2009
  9. Crypton

    Crypton Member

    Messages:
    589
    Likes Received:
    2
    Joined:
    May 22, 2008
    Awesome. :hidepc:
     
  10. Yuki

    Yuki Well-Known Member

    Messages:
    1,398
    Likes Received:
    0
    Joined:
    Feb 28, 2009
    It is a rule now that we cannot quote videos
     
  11. Wolfsbane

    Wolfsbane Well-Known Member

    Messages:
    4,498
    Likes Received:
    4
    Joined:
    Nov 11, 2005
  12. Crypton

    Crypton Member

    Messages:
    589
    Likes Received:
    2
    Joined:
    May 22, 2008
  13. Xz

    Xz Monkey Admin Staff Member

    Messages:
    5,085
    Likes Received:
    4
    Joined:
    May 31, 2003
    Thank you Crypton, the new code seems to work as expected. However, it seems phpBB doesn't recognise the youtube tags as bbcode. Perhaps there's a connection between that and bbcode stored by phpBB has a unique id of some sort.

    As you can see the id seems to be specific to the post and not to the bbcode instance, and it does not change upon edit. The id is stored in the field: 'bbcode_uid'. I'll see if I can update the script.

    Edit: Fixed that, however it also seems to be dependent on a bbcode_bitfield.
     
  14. wobbler

    wobbler Well-Known Member

    Messages:
    2,494
    Likes Received:
    11
    Joined:
    Aug 23, 2006
    [youtube]http://www.youtube.com/watch?v=4wSr7h_pjxs[/youtube]
     
  15. Arthgon

    Arthgon Well-Known Member

    Messages:
    2,733
    Likes Received:
    12
    Joined:
    Dec 30, 2007
    Yeah. I remember that song. Did you know that the guys in the videp clip are the Party Animals? That's a pop-gabber group from The Netherlands.

    [youtube]http://www.youtube.com/watch?v=pJkgOK-7Sj4[/youtube]

    HAKKEN!!!!!!
     
  16. Crypton

    Crypton Member

    Messages:
    589
    Likes Received:
    2
    Joined:
    May 22, 2008
    [youtube]http://www.youtube.com/watch?v=yv4GHXn7KWQ[/youtube] [youtube]http://www.youtube.com/watch?v=i0cjGVpKLd4[/youtube]

    :hippy:
     
  17. Arthgon

    Arthgon Well-Known Member

    Messages:
    2,733
    Likes Received:
    12
    Joined:
    Dec 30, 2007
    A blast from the past - 1992 Rotterdam Termination Source - Poing.

    Composed by Maurice Steenbergen and Danny Scholte.

    [youtube]http://www.youtube.com/watch?v=dqD1OohY2to[/youtube]

    Hardcore!

    [youtube]http://www.youtube.com/watch?v=22WUgQkbx_k[/youtube]

    [youtube]http://www.youtube.com/watch?v=6oIoqGnUaNY[/youtube]
     
  18. Wolfsbane

    Wolfsbane Well-Known Member

    Messages:
    4,498
    Likes Received:
    4
    Joined:
    Nov 11, 2005
    I just need to share this with you - I can't stop myself from humming this wherever I goddamn go. Enjoy!

    [youtube]http://www.youtube.com/watch?v=hy-H-KJRYbw[/youtube]
     
  19. Muro

    Muro Well-Known Member

    Messages:
    4,182
    Likes Received:
    22
    Joined:
    May 22, 2007
    I find this incredibly catchy.

    [youtube]http://www.youtube.com/watch?v=KVodXir8y1w[/youtube]

    I also recommend the NSFW version for [strike]those who prefer a porn variant of everything[/strike] everyone.
     
  20. Crypton

    Crypton Member

    Messages:
    589
    Likes Received:
    2
    Joined:
    May 22, 2008
    [youtube]http://www.youtube.com/watch?v=CL2YPO6SVDM[/youtube]
    [youtube]http://www.youtube.com/watch?v=X0y9YGd_jPc[/youtube]
     
Our Host!