Squeak, Smalltalk and OOP

Articles‎ > ‎

Saving QuickTime movies

Unless you have bought a Pro key to unlock the advanced features of the QuickTime Player and its plug-in sibling, you can’t save the movies from your favorite web browser. Well, this situation was true until you get a free access to the backstage with F-Script.

The following steps provide a brief explanation of the usage of F-Script to explore the QuickTime Kit and go beyond the restricted features of the web plug-in.

Start your favorite Cocoa-based web browser (e.g. Safari, Shiira or Camino).

Start F-Script Anywhere and inject F-Script into the web browser.

Switch to the browser and visit a web page with some QuickTime movies on it.

Select the FSA menu and open a new F-Script workspace.

Type the following command in the shell and press the return key:

QTMovie movies

The #movies method is undocumented but as you can see, it’s incredibly simple to retrieve all movies currently handled by instances of the QTMovie class.

The movies are returned in an NSArray:

NSCFArray {<QTMovie: 0x4b059d0 time scale = 600, duration = 18018, rate = 0.000000, tracks = { 0x30f5c0 0x5e101f0 0x4b54490 0x4b54590 0x5e10540 }>}

Let’s get the URL of the first movie in the list:

(QTMovie movies at:0) URL

With this information, you could easily grab this URL with cURL, but we will be a bit clever and use the powerful QuickTime Kit framework to save the movie directly from the F-Script console.

By the way, thanks to OOPAL, it is possible to send the #URL message to the #movies array and get back an array filled with the URL of each movie:QTMovie movies URL

We create an instance of a NSSavePanel:

panel := NSSavePanel savePanel

then we ask ourselves to select a folder and give a name to the movie file:

panel runModal

We set attributes so the movie is actually flattened instead of referenced:

movie := QTMovie movies at:0.
attributes := NSMutableDictionary dictionaryWithDictionary:movie movieAttributes. 
ttributes setObject:(NSNumber numberWithBool:true) forKey:QTMovieFlatten.

We are now ready to save the movie:

movie writeToFile:(panel filename) withAttributes:attributes

That’s it!

If you open the movie, you will see that the scaling is not right and that the control bar is missing. You can tweak these attributes just like we did for the flattening.

F-Script is a powerful tool to manipulate live objects and to explore the complex Cocoa frameworks. Furthermore, its simple Smalltalk-like syntax makes it easy to add new features to existing applications while retaining the familiarity of the Objective-C language.