Squid + VideoCache on Mac OS X Leopard

As the VideoCache website (http://cachevideos.com/ yay Drupal lol ) says:

"VideoCache is a squid URL rewriter plugin written in Python which traps the requests to squid for various audio/video websites and cache the audio/videos in the local storage on proxy server for serving the subsequent requests for the same audio/video. It caches the audio/video independently of squid caching system. The cached files are stored in a browsable fashion."

In short, it caches (i.e. maintains a reusable copy of) all the Youtube, Google Videos, Metacafe, and other services' videos that you play. The fun starts when, upon a page refresh on a youtube video, you don't have to re-download the video. Rather the VideoCache Squid(proxy) plugin comes into action and taps the video request to the one already existing on the hard drive! An awesome solution for LANs and ISPs!

To install Squid and VideoCache on Mac OS X Leopard (10.5):

Squid installation

  1. Find the latest stable release's(currently squid-3.0.STABLE9) tarball at http://www.squid-cache.org/Versions/v3/3.0/ and download it:
    $ curl -o /tmp/squid.tar http://www.squid-cache.org/Versions/v3/3.0/squid-3.0.STABLE9.tar.gz
    And now extract it:
    $ tar zxvf /tmp/squid.tar
    $ cd /tmp/squid-3.0.STABLE9/
  2. Now the squid building and installation:
    $ ./configure
    $ make
    $ sudo make install
  3. Edit the squid.conf file
    $ mate /usr/local/squid/etc/squid.conf # Use your favorite editor.
    And append the following line into it:
    http_access allow localhost
  4. To start squid you just need to:
    $ sudo /usr/local/squid/sbin/squid -D

VideoCache installation

  1. Download the latest VideoCache source(currently videocache-1.6) tarball from http://cachevideos.com/download
    $ curl -o /tmp/vc.tar http://cachevideos.com/sites/gurpartap.com/files/pub/videocache/videocache-1.6.tar.gz
    and extract it
    $ tar zxvf /tmp/vc.tar
    $ cd /tmp/videocache-*
  2. Edit setup.py in your favorite editor.
    $ mate setup.py
    and set the installation variables as the following:
    squid_user = 'nobody'
    squid_group = 'nobody'
    apache_conf_dir = '/private/etc/apache2/other/'
    etc_dir = '/usr/local/squid/etc'
  3. Now onto the VideoCache installation:
    $ sudo python setup.py install
    You'll get a good notice to restart your apache daemon. Use the following command instead of the instructed one:
    $ sudo apachectl restart
  4. Set the right permissions by making the logs directory writable and shift the ownership to VideoCache's user (i.e. nobody):
    $ sudo chown nobody:nobody /var/logs/videocache/
    $ sudo chmod 755 /var/logs/videocache/
  5. We'll now have to hack the VideoCache's script. Remember that you'll need to repeat this step each time you upgrade your VideoCache installation.
    $ mate /usr/share/videocache/videocache.py # Of course you are using your fav. editor here ;)
    Change the line 41 from:
    mainconf =  readMainConfig(readStartupConfig('/etc/videocache.conf', '/'))
    To:
    mainconf =  readMainConfig(readStartupConfig('/usr/local/squid/etc/videocache.conf', '/'))
  6. To bypass the video file requests via VideoCache, edit the squid.conf file:
    $ mate /usr/local/squid/etc/squid.conf
    And append the following lines to it, if they don't already exist:
    # --BEGIN-- videocache config for squid
    url_rewrite_program /usr/bin/python /usr/share/videocache/videocache.py
    url_rewrite_children 10
    acl videocache_allow_url url_regex -i \.youtube\.com\/get_video
    acl videocache_allow_url url_regex -i \.cache[a-z0-9]?[a-z0-9]?[a-z0-9]?\.googlevideo\.com\/videoplayback
    acl videocache_allow_url url_regex -i \.cache[a-z0-9]?[a-z0-9]?[a-z0-9]?\.googlevideo\.com\/get_video
    acl videocache_allow_url url_regex -i proxy\-[0-9][0-9]\.dailymotion\.com\/
    acl videocache_allow_url url_regex -i [a-z0-9][0-9a-z][0-9a-z]?[0-9a-z]?[0-9a-z]?\.xtube\.com\/(.*)flv
    acl videocache_allow_url url_regex -i bitcast\.vimeo\.com\/vimeo\/videos\/
    acl videocache_allow_url url_regex -i va\.wrzuta\.pl\/wa[0-9][0-9][0-9][0-9]?
     
     
    acl videocache_allow_url url_regex -i \.files\.youporn\.com\/(.*)\/flv\/
    acl videocache_allow_url url_regex -i \.msn\.com\.edgesuite\.net\/(.*)\.flv
    acl videocache_allow_dom dstdomain v.mccont.com vp.video.google.com dl.redtube.com
    acl videocache_deny_url url_regex -i http:\/\/[a-z][a-z]\.youtube\.com http:\/\/www\.youtube\.com
    url_rewrite_access deny videocache_deny_url
    url_rewrite_access allow videocache_allow_url
    url_rewrite_access allow videocache_allow_dom
    redirector_bypass on
    # --END-- videocache config for squid

    These are the same as at the end of this page: http://cachevideos.com/installation#install-from-source-steps
  7. Now's the time to (re)start Squid:
    $ sudo /usr/local/squid/sbin/squid -D
    Or, just "reconfigure" squid for the new configuration, if squid was already running:
    $ sudo /usr/local/squid/sbin/squid -k reconfigure
    I use logs and Activity Monitor (available in /Applications/Utilities) to track down any problem that may persist.

Happy Times! lol

4 Comments

Its http://cachevideos.com

Thank you sir ji :)

Thank you sir ji Thumb Up

FYI starting squid

Just an FYI -- before starting squid the first time you have create the caches - this requires the /usr/local/squid/var directory to be writable by the nobody user. You will also get errors starting squid until you make the /usr/local/squid/var/logs directory writable by the user nobody.

Before I spend time trying,

Before I spend time trying, is there any reason why this shouldn't work in 10.6 too?

Post new comment

Smileys
:);):P*JOKINGLY*8)8-|:(:O(pl)]:<O:)<:o):thinking(Y)
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <del> <code> <ul> <ol> <li> <small> <br> <img> <h2> <h3> <h4>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.
  • Textual smileys will be replaced with graphical ones.

More information about formatting options