Ruby script xor fix

Following is a patch against Paul Battley's Ruby iplayer downloader (http://paulbattley.googlecode.com/svn/iplayer-dl, revision 162), that removes the xor 'DRM' the BBC are currently using. This should work for both the command-line and GUI versions.

To apply the patch: cd /path/to/iplayer patch -p1 < /path/to/patch

diff -up a/lib/iplayer/downloader.rb b/lib/iplayer/downloader.rb --- a/lib/iplayer/downloader.rb +++ b/lib/iplayer/downloader.rb @@ -4,6 +4,7 @@ class Downloader PROGRAMME_URL = 'http://www.bbc.co.uk/iplayer/page/item/%s.shtml' SELECTOR_URL = 'http://www.bbc.co.uk/mediaselector/3/auth/iplayer_streaming_http_mp4/%s?%s' + XOR_KEYS = [0x3c, 0x53] Version = Struct.new(:name, :pid) @@ -64,11 +65,21 @@ class Downloader bytes_got = offset yield(bytes_got, max) if block_given? +   xor_start = 0x2800 +   xor_end = max - 0x400 +    get(location, Browser::QT_UA, 'Range'=>"bytes=#{offset}-") do |response| response.read_body do |data| -       bytes_got += data.length +       data.each_byte do |d| +         if (bytes_got >= xor_start) && (bytes_got < xor_end-2) +           d ^= XOR_KEYS[(bytes_got-xor_start) & 1] +         elsif (bytes_got >= xor_end-2) && (bytes_got < xor_end) +           d ^= XOR_KEYS[(xor_end-bytes_got+1) & 1] +         end +         bytes_got += 1 +         io << d.chr +       end yield(bytes_got, max) if block_given? -       io << data end end end