SVN: toys/rsget.pl: RSGet/AutoUpdate.pm RSGet/Curl.pm RSGet/Main.pm Video Video/YouTube

sparky sparky at pld-linux.org
Sat Oct 3 23:40:41 CEST 2009


Author: sparky
Date: Sat Oct  3 23:40:40 2009
New Revision: 10668

Added:
   toys/rsget.pl/Video/
   toys/rsget.pl/Video/YouTube
Modified:
   toys/rsget.pl/RSGet/AutoUpdate.pm
   toys/rsget.pl/RSGet/Curl.pm
   toys/rsget.pl/RSGet/Main.pm
Log:
- prepare for video handlers
- added Video/YouTube


Modified: toys/rsget.pl/RSGet/AutoUpdate.pm
==============================================================================
--- toys/rsget.pl/RSGet/AutoUpdate.pm	(original)
+++ toys/rsget.pl/RSGet/AutoUpdate.pm	Sat Oct  3 23:40:40 2009
@@ -16,6 +16,8 @@
 		qr{(svn|https?)://.{4,}} ],
 );
 
+my @update_dirs = qw(data RSGet Get Link Video);
+
 sub update
 {
 	unless ( require_prog( "svn" ) ) {
@@ -31,7 +33,7 @@
 	local $ENV{LC_ALL} = "C";
 	my $svn_uri = setting("svn_uri");
 	my $updated = 0;
-	foreach my $dir ( qw(data RSGet Get Link) ) {
+	foreach my $dir ( @update_dirs ) {
 		my $last;
 		print "  $dir:\n";
 		open SVN, "-|", "svn", "co", "$svn_uri/$dir";
@@ -48,7 +50,7 @@
 	}
 	chdir $start_dir;
 
-	$updated -= 4;
+	$updated -= scalar @update_dirs;
 	return undef unless $updated >= 0;
 	return $updated;
 }

Modified: toys/rsget.pl/RSGet/Curl.pm
==============================================================================
--- toys/rsget.pl/RSGet/Curl.pm	(original)
+++ toys/rsget.pl/RSGet/Curl.pm	Sat Oct  3 23:40:40 2009
@@ -99,6 +99,8 @@
 		$curl->setopt( CURLOPT_WRITEFUNCTION, \&body_file );
 		$curl->setopt( CURLOPT_WRITEDATA, $supercurl );
 
+		$supercurl->{force_name} = $opts{fname} if $opts{fname};
+
 		# if file exists try to continue
 		my $fn = $get_obj->{_opts}->{fname};
 		if ( $fn ) {
@@ -175,7 +177,9 @@
 	}
 
 	my $fname;
-	if ( $supercurl->{head} =~
+	if ( $supercurl->{force_name} ) {
+		$fname = $supercurl->{force_name};
+	} elsif ( $supercurl->{head} =~
 			/^Content-Disposition:\s*attachment;\s*filename\*=UTF-8''(.+?);?\s*$/mi ) {
 		$fname = de_ml( uri_unescape( $1 ) );
 	} elsif ( $supercurl->{head} =~

Modified: toys/rsget.pl/RSGet/Main.pm
==============================================================================
--- toys/rsget.pl/RSGet/Main.pm	(original)
+++ toys/rsget.pl/RSGet/Main.pm	Sat Oct  3 23:40:40 2009
@@ -169,7 +169,7 @@
 		unshift @paths, $main::local_path;
 	}
 	foreach my $path ( @paths ) {
-		foreach my $type ( qw(Get Link) ) {
+		foreach my $type ( qw(Get Link Video) ) {
 			my $dir = "$path/$type";
 			next unless -d $dir;
 			foreach ( sort glob "$path/$type/*" ) {

Added: toys/rsget.pl/Video/YouTube
==============================================================================
--- (empty file)
+++ toys/rsget.pl/Video/YouTube	Sat Oct  3 23:40:40 2009
@@ -0,0 +1,40 @@
+#!/usr/bin/perl
+
+name: YouTube
+short: V:YT
+uri: qr{youtube\.com/watch\?v=.*}
+slots: 8
+status: OK 2009-10-03
+
+pre:
+	use URI::Escape;
+
+start:
+	! $-{_uri} =~ m{[\?&]v=([-_a-zA-Z0-9]+)(?:&.*)?$};
+	$-{v} = $1;
+
+	GET( "http://www.youtube.com/watch?v=$-{v}" );
+
+	! m{<meta name="title" content="(.*?)">};
+	my $name = $1;
+
+	! /"fmt_map"\s*:\s*"(.*?)"/;
+	my %fmts = map { m{(\d+)/}; $1 => $_ } split ",", uri_unescape( $1 );
+
+	my $fmt = "18";
+	$fmt = "35" if $fmts{35};
+	$fmt = "22" if $fmts{22};
+
+	my $ext = "mp4";
+	$ext = "flv" if $fmt eq "35";
+
+	! /"t"\s*:\s*"(.*?)"/;
+	my $t = $1;
+
+	my $fname = $name . "." . $ext;
+	INFO( name => $fname, size => -1 );
+
+	DOWNLOAD( "http://youtube.com/get_video?video_id=$-{v}&t=$t&fmt=$fmt",
+		fname => $fname );
+
+# vim:ts=4:sw=4


More information about the pld-cvs-commit mailing list