1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

XF 1.5 Converting YouTube, SoundCloud links on a large site

Discussion in 'Installation, Upgrade, and Import Support' started by iaresee, Oct 24, 2015.

  1. iaresee

    iaresee Member

    I'm in the process of migrating a largish VB4 site to Xenforo that has a lot of YouTube and SoundCloud embedded media links in the post content. The Post Content Find/Replace add-on and the regex tips from @Jake Bunce are a great tools, but it was falling over trying to read a database as large as the one I have.

    So I wrote a command line utility to do the conversion. You can get it here: https://github.com/ianchesal/xenforo-conversion

    It's part of what will be larger suite of tools that I'm using to do the conversion, but for now that's the first piece I'm putting out as open source.

    There are a bunch of examples for common media embeds in the README file.

    Here's an example that'll do YouTube embeds in your post content for you:

    Code:
    bundle exec bin/find_and_replace --yes '[video' '\[video=youtube\S*?;(\S+?)\].*?\[\/video\]' '[media=youtube]\1[/media]'
    That'll find stuff like:

    Code:
    [video=youtube;t4KIAWNZ5tY]http://www.youtube.com/watch?v=t4KIAWNZ5tY[/video]
    [video=youtube_share;RkkCDHmBAs8]http://youtu.be/RkkCDHmBAs8[/video]
    And convert it to:

    Code:
    [media=youtube]t4KIAWNZ5tY[/media]
    [media=youtube]RkkCDHmBAs8[/media]
    The script can be run against large sites with on a machine with minimal memory thanks to batch fetching of results.

    Props to @Kier for the idea to pre-limit the number of posts you need to run the actual regex on with an initial search expression. That's a nice optimization.
     
    Jake Bunce likes this.
  2. iaresee

    iaresee Member

    Just pushed an update to find-and-replace that lets you run it against any table, field and index. For example, if you wanted to find-and-replace SoundCloud links in user signatures:

    Code:
    bundle exec bin/find_and_replace --table xf_user_profile --index user_id --field signature --yes '[soundcloud]' '\[soundcloud\]\s*http(?:s)?:\/\/soundcloud\.com\/(.*?)\[\/soundcloud\]' '[media=soundcloud]\1[/media]'
    
    Or better yet, get rid of them (because really...SoundCloud players in signatures, amiright?):

    Code:
    bundle exec bin/find_and_replace --table xf_user_profile --index user_id --field signature --yes '[soundcloud]' '\[soundcloud\].*?\[\/soundcloud\]' ''
    
     
    Jake Bunce likes this.

Share This Page