YouTube-esq module for Menalto Gallery v3

I’ve been using Gallery2 on my site now for a few years now. I’ve always had issues with it though, due to it’s somewhat overwhelming complexity, the templating system which I really couldn’t even get a grasp of, and based on some framework I really didn’t understand, I got reluctant to attempt to do anything with the code in the way of writing modules for it. That and file permissions issues plagued my gallery and stopped it working on several occasions.

So I read that Gallery3 was almost ready, and installed the RC2 version. It’s much better in the terms of the way it’s built. It’s modules are simpler to write with a somewhat simple ‘hooks’ based system which actually make extending it’s functionality and hooking into the theme’s areas relatively easily.

One of the main things that I’ve always wanted to do is have my videos stored on my Gallery instead of on YouTube. I get more web-visitor stats from the server, Gallery, and Google Analytics – something I don’t get with YouTube. However, G3 doesn’t support this out of the box. So I wrote one. It’s a somewhat basic implementation of what I eventually want it to be. The biggest part of this for me was trying to get to grips with Gallery3’s new framework (based on Kohana). I figured most of it out by copying the basic structures of other modules I’d installed and modifying it for me own needs. A couple of hours and I’d picked it up relatively easily.

You can download it here: [download id=15 format=1]

I probably shouldn’t be doing this, but in the interest of avoiding dead links, I’ve been updating this post during the development of this module as opposed to posting a new post each time there was a new version.

A couple of things you should note however. If you want to upload a video of more than a couple of megabytes, use the ‘Server Add’ module, as the upload will eventually stall/time out/crash as the transcoding process takes a while. You can check the progress of each of the transcoding tasks (one task for each resolution) in the Maintenance tab of the Admin area. If you see a task as ‘Stalled’, it means ffmpeg has either crashed, or that particular installation doesn’t like one (or more) of the parameters in the command sent to ffmpeg for transcoding.

It currently logs a decent amount of data to var/modules/transcode/log/transcode.log. This is the general output of the module behind the scenes. If a problem arises, this is the first place to look. Also, it logs ffmpeg’s output to a separate file (this is for 2 purposes, one so we can see what ffmpeg is doing having been executed from php/apache, and secondly so the module can work out how far into the transcoding process it is). Here, there’s one log file for each transcode/ffmpeg process.

If you can’t figure out why things aren’t working, drop me a line here, my Contact page, or on the Menalto forum here. I don’t expect this to be perfect, and it’s my first contribution to any open source project, so don’t shoot me down too hard 🙂


Download here: [download id=”27″ format=”1″]

Change Log
7th October 2010 :: Version 1 :: Initial release.
8th October 2010 :: Version 2 :: Removed dependency on php5-ffmpeg, refine audio codec selection list, add support for ffprobe to detect input video’s parameters.
10th October 2010 :: Version 3 :: Removed dependency on ffprobe, improved audio codec detection.
25th October 2010 :: Version 5 :: This module actually starts working on servers other than my own!
28th October 2010 :: Version 6 :: Fixed a bug that makes ffmpeg fall over if the input video’s audio sample resolution is not supported by ADPCM. It now fixes the sample rate to one of 11025 kHz, 22050 kHz or 44100 kHz (whichever is the next lower than the input sample rate).
30th October 2010 :: Version 7 :: Fixed issues providing an ffmpeg path and not saving correctly when no audio codecs are in the select list to begin with.
1st November 2010 :: Version 8 :: Bug fixes, thanks to netprince for the patch, and diverselab, jhend60, shecter and mamouneyya for help getting this working.
3rd November 2010 :: Version 9 :: Final stable release. Fixed issues with crashing due to ffmpeg not detecting/recognising the input file’s audio codec.
11th November 2010 :: Version 10 :: Bitrate tweaks and fix to audio bitrate channel detection and calculation.
13th September 2012 : Version 11 : Applied patch to prevent “Alternative Resolutions” banner appearing on photo pages and pages where transcoding has not been carried out (patch provided by Jannik Graversen).
15th September 2012 : Version 12 : Update codebase, cleanup, fix parsing of ffmpeg output to determine codec support. Utilise ffprobe to get details of source video as it provides a JSON interface. Added “Default Resolution” field, to auto-select on the frontend as opposed to the smallest resolution available. Only display “Alternative Resolutions” if 2 or more resolutions are available. Improvement on the back of patch from v11, using item->is_movie as opposed to counting resolutions to determine whether or not to display that area. Tested with ffmpeg version 0.6.5 through 0.11.1.
17th September 2012 : Version 13 : Fix versioning issue in installed, problem preventing save after upgrade or clean install.

Codex page on Gallery’s website:

Bug in Magento affecting the recalling of newsletter templates to send

So I wondered if I could go a whole week without finding another bug/flaw/issue in the latest Magento. I was wrong.

We’re trying to send out a newsletter using the built-in feature. I created a template, then went to queue to send it, and I was like; “So, what’s this ‘message’ field?”. I pondered for a bit, typed a message in, thinking it may have just been for some placeholder in the template somewhere, and hit send. When the newsletter turned up, lo-and-behold, there was just my message, without the rest of the template. WTF? Did it again, thinking I’d screwed something up – same result. Hmm..

Bit of Googling at this point revealed this thread on Magento’s forums. “A bug?”, I thought as I read on. “Couldn’t possibly be!”. </sarcasm>

As the code/class that had the flaw only had one function and extended the Adminhtml_Block_Widget_Form class, I decided to just write a quick extension to replace the class that Magento comes with, with this flaw fixed. I attach to this post my quick extension. Just drop this in the Magento webroot and extract. It’ll put the files in the relevant places, and just start working.

Attached file here: [download id=”3″ format=”7″]

Adding multiple products to the cart simultaneously in Magento

Some people ask me if it’s possible to do what some other sites do, allowing you to check a box next to a product on a listing page, and then add all selected items to the cart in one go. This is possible in Magento, it’s just not built in. There’s a few ways you can do this. You can either make an ajax call using a button against each product, which fires off a GET request to the server to add. This method will most likely return the HTML for the cart, and since we’re not interested in the response, said HTML can be discarded.

Continue reading “Adding multiple products to the cart simultaneously in Magento” »

Magento Discount Rules – Buy X Get Lowest Priced Item

I figured out today that the discount/promotion rules in Magento aren’t exactly obvious, nor straight forward to apply. If you don’t have the logical mind of a programmer, setting up rules for products that only meet certain criteria can be a tricky one. Take this example:

Buy 4 for 3 on any product in [this] category.

Sounds simple, no? Actually, no. Continue reading “Magento Discount Rules – Buy X Get Lowest Priced Item” »

Bug in Magento core affecting Catalog Price Rules targetting Customer Groups

I came across this issue to begin with using the Wildcardbi_RulePriceAttribute module to be able to specify custom prices for specific customer groups (in this case, wholesale/trade pricing) without having to setup an entire new store view for it.

Continue reading “Bug in Magento core affecting Catalog Price Rules targetting Customer Groups” »