Refactoring iplayer-dl

I’ve done a bit of work on refactoring iplayer-dl, with two aims in mind:

  1. Improving the JavaScript parsing that determines available versions
  2. Making the code easier to repurpose and integrate into GUIs etc.

The most important result of this work is that it’s no longer a standalone script. This shouldn’t necessarily make it harder to use, though. Once you’ve unpacked the code, you’ll need to run the following commands in the iplayer-dl directory to install the libraries and command-line tool:

ruby setup.rb config
sudo ruby setup.rb install

You can omit sudo on Windows, I think; some Linuxes might require you to use su instead.

The iplayer-dl command should be installed somewhere in your path, and you’ll be able to use it from anywhere just by typing its name.

The tarball conforms to the Debian packaging guidelines for Ruby applications, incidentally, so it should be straightforward to make a .deb for Ubuntu/Debian, or even a port for MacPorts.

You can download a snapshot, or check out the latest version:

svn co http://paulbattley.googlecode.com/svn/iplayer-dl

If you’re reporting a bug, please also write the URL or PID of the programme you were trying to download.

Keeping up with iplayer-dl

I’ve had a productive evening hacking iplayer-dl. Here’s a short list of improvements:

  • Checks the availability of different versions of the video based on type and date.
  • Fetches the ‘Original’ version by preference. (Previously, it would tend to fetch the sign language version. This can be modified in the code if you do want signed videos.)
  • Resumes downloading if interrupted and restarted.
  • You can now specify just a PID (the eight letter/number code) on the command line instead of the URL, if you prefer.
  • Uses the XML metadata service to determine the title and subtitle with greater accuracy.

And, as I promised, here’s a Subversion repository for those of you who want to keep up to date with changes:

svn co http://paulbattley.googlecode.com/svn/iplayer-dl

The latest version will continue to be available via the download link.

There’s an update here.

iPlayer cat and mouse

My iPlayer download script had been failing on a number of programmes recently, and I’d assumed that they were just not encoded as MPEG 4 files. Having seen them work on a real iPhone, though, I now know that it’s not the case.

It didn’t take me long to find the problem: there can now be multiple pid values in the file, and my naïve regular expression was selecting the first one, which was the wrong one. Selecting the last one seems to work in all the cases I’ve tried, so I’ve made that change. I don’t think that this was a deliberate attempt to lock scripts out, but it had that effect.

If it wasn’t working for you, try downloading the script again, and let me know how it goes.

iplayer-dl

Incidentally, I know that the Beebhack wiki is sometimes returning a spammy parking page. I’m not sure what’s going on.

Selenium, Firefox 3, and Mac OS X

The latest Firefox 3 betas are really good, and a big improvement over Firefox 2. The improvement in performance on my Eee PC is enormous, but even on the quad-core Xeon I’ve got at work, the increased snappiness is welcome. There are some good interface tweaks as well; after learning to work with the ‘Awesome Bar’ rather than against it, I’ve come to like it. Unfortunately, there’s a downside: Selenium, which we use for acceptance testing at Reevoo, doesn’t work with Firefox 3.

I’m sure that this state of affairs will be addressed in the near future as Firefox 3 gets closer to release, but, in the meantime, it’s easy enough to get Selenium working without having to go back to the Dark Ages of Firefox 2 browsing:

  • Install Firefox 3 in ~/Applications
  • Install Firefox 2 in /Applications

Stick the newer application from your home directory in the Dock and use it for browsing; Selenium will find the older application in the system Applications directory and use that for its purposes. Everyone’s happy!

Princess Diana is still dead

This might not make a lot of sense unless you’re very familiar with the British press, but the Daily Express managed to achieve the perfect front page today:

The perfect Daily Express front page

Diana, Madeleine, and Shannon. The hat-trick. But how are they going to manage to keep Diana on the front page for another ten years?

Xi’an outside the wall

I hadn’t realised just how much of Xi’an lay outside the city walls until my last day there. I walked south from the South Gate of the city in a zig-zag until I reached the Big Wild Goose Pagoda—which turned out to be much further than I’d anticipated from my not-to-any-particular-scale map. On the way, I passed through an electronics district, and paused to listen to some amateur Chinese hip-hop on a Samsung-sponsored stage at the side of the street. I’d definitely have missed that if I’d taken the bus!

The Big Wild Goose Pagoda, Xi'an

Getting into the pavilion itself is a bit confusing: first you must buy a ticket (RMB 25) for Daci’en temple, whose entrance lies on the south side of the surrounding wall. Once inside, you can then buy a second ticket (RMB 20) to climb the tower’s seven floors. It’s quite an exertion, but the view from the top is as good as you can ever get in north-eastern China.

Looking north at Xi'an from the top of the Big Wild Goose Pagoda

On my way back, I had intended to visit the museum a couple of blocks away, but it wasn’t to be. When I arrived, I found a confused crowd milling around in front of the museum, and security guards preventing anyone from buying tickets. I don’t know what was going on, but it was apparent that I wasn’t going to get in.

Chinese supermarkets

There are plenty of familiar chains in China, including a number of supermarkets such as Wal-Mart and Carrefour. Once you get inside, though, Chinese supermarkets are a little bit different from what you might be used to.

You can buy frozen chickens in Chinese supermarkets. Unlike my local supermarket in London, they still have the head and feet on.

Live turtles paddle around a crowded tank in the seafood section.

Half an aisle is signposted and devoted solely to various brands of MSG.

Xi’an

Xi'an viewed from the South Gate

One of the most annoying things in China is being within spitting distance (I use the term advisedly: expectoration is a national pastime) of your destination, but with a six-lane highway between you and it. Getting to the other side often involves a lengthy detour via an underpass or footbridge, adding hundreds of metres, or, if you’re lucky, a pedestrian crossing. In some cities, that’s OK. In Xi’an, there’s an extra dimension of excitement: there are no traffic lights.

But Xi’an’s traffic flows surprisingly well in spite of this. Vehicles negotiate based on size, speed, and by possession of a patch of ground. In the same way that an HGV can always pull out of a little side street in England, a bus in Xi’an can always get where its driver wants it to go, but the little guys don’t seem to get crushed to death—at least, not as often as you might assume. Rather like those Dutch experiments, it seems to work: everyone keeps an eye out for everyone else, which is probably at least as safe as blindly claiming the right of way. It still takes an unaccustomed boldness to stride out into the middle of a busy road the first few times, though.

I arrived in Xi’an yesterday morning on the overnight sleeper train from Beijing. It’s a bit over eleven hours, but I spent most of it blissfully unaware. Last time I took an overnight train in China, I went for the ‘soft sleeper’. This time, there were none available, so I had to settle for a ‘hard sleeper’ instead. The name’s a complete misnomer. The beds are the same. You get blankets, a pillow, boiling water on tap, and all the normal amenities of the soft sleeper. The differences are: six instead of four beds per compartment (three high); no doors on the compartments. That’s it, really. And the hard sleeper’s quite a bit cheaper.

Two things that really make sleep possible on the sleeper train are an eye mask and earplugs. The mask is to keep out the lights from pauses at isolated stations in the middle of the night. The earplugs are because the train makes all sorts of strange noises. Thanks to these two items, I slept soundly throughout, waking up refreshed and ready for a day of tourism.

I spent my first day in the city wandering around a few sites in the centre. The Bell Tower and the Drum Tower both gave excellent views of the city. The Stone Forest museum has lots of stelae (big stones with writing on), but lacks something if you don’t read Classical Chinese.

In the evening, I took advantage of the opportunity to make and eat some dumplings (jiăo zi) in the hostel, and ended up being filmed by a crew from Hong Kong making a travel programme for cable TV. Strange: it’s the second time I’ve come to China, and the second time I’ve ended up being on TV as a result!

Despite chatting and drinking beer late into the night, I managed to wake up early this morning to go to see the Terracotta Army, one of my main reasons for visiting Xi’an . It turned out to be a bit underwhelming. I wouldn’t say that I was disappointed, just that I was expecting more, somehow. The exhibition doesn’t quite convey the scale of the achievement, and the distance between the visitors and the artefacts lends the whole experience a sense that you’re looking at mantelpiece ornaments. I suppose that if, rather than peering from the margins of a large hangar, you could get among them, it might improve the experience, but I’m not sure how this could be achieved in practice.

Xi'an viewed from the South Gate

I’m still glad I went—and I get to one-up everyone who’s seen the dozen on display in London!

I used public transport to reach the excavation site. I could have paid RMB 180 for a tour from my hostel, but it would have taken the whole day with all the inevitable detours to souvenir shops and other tat emporia along the way. And I wouldn’t have been very free to do things at my own pace. Instead, I took the public bus for RMB 7 each way and paid the entrance fee of RMB 65. I got there early to beat the crowds, saved money, and I was back in Xi’an for lunch.

That gave me time to rent a cycle (RMB 20) for a ride around the top of the city walls. It was hard work: it’s a good hour and a quarter all the way round even at my brisk pace, and my posterior was beginning to suffer after about an hour of the bumpy terrain. It’s really good, however, and I’d thoroughly recommend it as an activity for anyone visiting Xi’an. You do get to see a lot from up there.

I’ve got one more day here in Xi’an; tomorrow night, I’m back on the sleeper train to return to Beijing in time for my flight home on Tuesday.

Best registration plate ever?

I know it’s puerile, but I couldn’t help laughing when this truck went past me in Beijing: the number plate was such a perfect combination of letters and numbers. I just had time to whip out my camera and grab a slightly blurry shot before it disappeared.

Beijing truck registration 京GAY069

That’s not a registration number, it’s a sexual position!

Dodging the crowds at the Great Wall

You can’t go to China and not see the Great Wall, can you? Well, I did: I missed it last time! So this time I took a day trip to Bādálǐng (八达岭) to see the Great Wall of China. Badaling is the easiest part of the wall to get to from Beijing and, for the same reason, rather crowded. The Great Wall is the most-visited attraction in the world, and Badaling probably constitutes the bulk of that. Even on a cold Monday in March, the ambience was, in places, more that of a rush-hour subway station than a historical monument.

Crowded section of the wall at Badaling

By walking further than the crowds are willing or able to go, you can, however, get to some relatively quiet parts. You just have to elbow your way through the tour groups and persistent hawkers of tat to get there.

Badaling isn't all crowds

And it is a great wall. Walking along (and up and down) it is tiring enough; the idea of building the thing defies comprehension. It’s like someone built a castle on a hilltop and then just kept going for thousands of miles. It’s truly amazing.

A long, sinuous stretch of the Great Wall at Badaling

Badaling’s reputation as the most over-restored and commercialised section of the wall is entirely deserved. However, it’s hard going even with the restored paths, steps, and handrails. There are some inclines of about forty degrees without any steps—just smooth paving. It’s hard work walking up, and it’s hard work walking down. And when you get to the end of the restored section, your way is blocked and you have to go back and do it all over again just to get out! (Actually, there is a cable car. That’s cheating, obviously.)

As a defensive fortification, though, the Great Wall just doesn’t work. The t-shirt and postcard vendors avoid the entrance fee by scampering up the hillside and over the wall! And if someone selling postcards for a few yuan can breach the defences, the Mongol warriors aren’t going to be stopped by it …

Vendor at Badaling avoiding the entrance fee by scaling the wall

Just to add a truly weird touch, there’s an advert for Niagara Falls on the back of my Great Wall ticket.