damien.h

Downloading YouTube Videos with a Groovy one-liner, kind of

Inspired by Downloading YouTube videos with a Perl one-liner, I’ve put together a piece of code to do the same thing with Groovy. Not as succinct as Perl. But figure out how much noise there will be in plain Java.

HttpURLConnection.setFollowRedirects(false)
def vid = (args[0] =~ (/(? new URL("http://www.youtube.com/get_video?video_id=$vid&t=${(uri =~ (/(? os.write(it)}}

Let’s take a closer look at the code. To capture the redirect location, we must temporarily disallow HttpURLConnection to follow redirects.

HttpURLConnection.setFollowRedirects(false)

Then we extract the v id from the original YouTube URL and compose the URI for the embedded player. Open a connection to the video URI and extract the redirect location from the HTTP header. The input parameter arg[0] should be something like http://www.youtube.com/watch?v=5C0I7Ef4gQI

def vid = (args[0] =~ (/(?<=v=).*$/)).getAt(0)
def uri = ((HttpURLConnection)new URL("http://www.youtube.com/v/$vid").openConnection()).getHeaderField('Location')

Now we must enable http redirects again, otherwise the last line of code won’t work.

HttpURLConnection.setFollowRedirects(true)

Finally, go ahead to compose the video data download URI, open a connection and download the data stream.

new File("${vid}.flv").withOutputStream{os -> new URL("http://www.youtube.com/get_video?video_id=$vid&t=${(uri =~ (/(? os.write(it)}}

Save the script to a groovy file like “YoutubeSaver.groovy”. Run the script from command line and give the video URL as the parameter. For example,

groovy youtubesaver http://www.youtube.com/watch?v=5C0I7Ef4gQI

Hello world, again (Part II, how I moved from JRoller to WordPress)

This is my summary about the migration of my blog from JRoller to here.

I’m a Java engineer working in China. So when I was looking for a free blogging service, JRoller was my natural choice, because

1. In China, Blogger, WordPress, LiveJournal, and all other mainstream blogging sites are blocked. So there are sadly not many choices left for me.

2. Chinese local blogging sites are crap, specially from a developer’s perspective.

3. JRoller is the best free blogging service implemented in Java today. It’s hosted by JavaLobby which is one of my favorites. There are a lot of brilliant folks hosting their blogs there. And since it’s not so mainstream, it’s not blocked in China. Hurray!

But after more than 3 months living with JRoller, I have to say I’m an unhappy user. Roller’s (JRoller’s, actually) lack of attractive features and looks, defective Chinese support, mysterious API support, make it fairly uncompetitive compared to today’s top ones, and make my blogging experience rather unexciting.

So I decided to move to WordPress, setting up on a server space I’m sharing with my friend, to get rid of all the problems. And I have to say WordPress is simply great.

So I did some Google search about the migration of my posts from JRoller to WordPress. I found a post from zeusville very helpful. And Jesus Rodriguez, the blogger, was kind enough to send me the custom JRoller template file which I wasn’t able to download from his blog anymore. Thanks again, Jesus.

Now I’m already very comfortable with WordPress. BTW. This post is written with Windows Live Writer. I have to say that this is the best free offline blogging software I’ve used so far. Unfortunately it comes from Microsoft so it only runs on Windows. But maybe it’ll have a chance running on Mono on Linux. I’ll give it a try later.

Hello world, again!

Hi, folks! So I’ve finally made up my mind to move my blog out of JRoller. Now this blog is on a domain and space owned by myself, which is virtually the best solution for blogging, which is also sadly non-free.

Thanks to Feedburner, you feed reading monkeys don’t need to update your feed subscription so this should be a smooth change.

I’ll write up some more about the migration tomorrow. So here’s just a quick update. Good night:)

JRoller upgraded!

Wow! JRoller has upgraded to the latest Roller 3.1, and got a fresh facelift which is in harmony with the lovely DZone.

The immediate difference I see with my blog is that my control panel is now partially in Chinese!:) But to my much disappointment, the awkward multi-language problem is still not fixed now. ???????????

I read in the newsletter that this upgrade also brought scalability headaches. Best luck to the JRoller folks and wish the problem can be resolved soon:)

Project Zero: First Impressions

Last weekend, Project Zero officially unveiled its community site. Project Zero is a fresh new project from IBM which aims at the agile web development framework domain which is getting momentum very fast lately with the popular RoR and the promising newcomer Grails.

Project Zero’s tagline is, “Zero complexity. Zero overhead. Zero obstacles.” “The Project Zero environment includes a scripting runtime for Groovy and PHP with application programming interfaces optimized for producing REST-style services, integration mash-ups and rich Web interfaces.”

Zero complexity or not, there are a few interesting aspects about Zero worthing noting.

1. Zero leverages Groovy.
That’s right! Probably the first time I’ve seen Groovy adopted into a project by a major company. Great news for Groovy lovers!

2. Zero supports PHP.
That’s sounds a bit weird. The fact is, Zero has implemented the support for PHP in Java. However, only a small subset of the standard PHP libraries are supported by now. Read the FAQ for more details.

3. Zero is self-contained
What that means is that each Zero application runs only by the Zero runtime. It doesn’t need to be deployed to any web server. The Zero runtime contains a minimalist server based on WAS CE. This is similar to Grails. (But Grails applications can also be deployed to any JEE server.)

4. Zero is NOT open source. But it invites the community to drive it.
Community-Driven Commercial Development is Zero’s official name for its development approach. This is already causing a lot of debates in the community. Let’s wait and see how this will work. Check out the official FAQ for more details.

Overall, Project Zero looks like an interesting endeavor from a major player in the industry to commercially challenge the world of agile web development. But judging from what it looks at this stage, I’m not 100% convinced if Zero has got everything right.

Next time, I’ll write up my first experiences playing with Zero, and putting it up against Grails.

Problem with posting from Windows Live Writer

Windows Live Writer is really quite a nice tool for posting to blogs. But despite of my effort to get it to work with jroller, I’ve always failed. I have seen someone succeeded posting to jroller, but I always get the following error. Could anyone give me any hint what I’m doing wrong?
Here’s what I did to set up jroller in WLW:

  1. Start Live Writer and Add a new Weblog Account. Fill in the URL of your weblog, your user name and password at jroller.
  2. Choose Metaweblog API as the type of weblog. And Type “http://www.jroller.com/xmlrpc” as the Remote posting URL.
  3. Write a new post, and select Publish. The following error dialog shows up.
    Error Message from JRoller

Browse Happy logo

My tweets

 

2007 年七月
« 六   八 »
 1
2345678
9101112131415
16171819202122
23242526272829
3031  

分类目录

Articles

Fancy Stats