Perl program for makeiPhoneRefMovie

This creates the small .mov (or whatnot) redirect files that Apple’s makeiPhoneRefMovie generates. This is simply a driver to creat those files with makeiPhoneRefMovie.

#!/usr/bin/perl -w
#
# gen_mwn_iphone_mov_redirect_files.pl
#
# This makes the special iPhone .mov rediect files (~ 300 bytes) that the iPhone
# uses to redirect to the appropriate actual movie file.
#
# To use this utility:
#
# Make sure that the program makeiPhoneRefMovie is in your $PATH with:
#
#  which makeiPhoneRefMovie
#
# Then, let fly!
#
# ./gen_mwn_iphone_mov_redirect_files.pl
#
# Then, FTP the .mov files that are created up to the CDN.
#

use strict;
use File::Basename;
use Net::FTP;
use DBI;
use Cwd;

# Where to output files
my $dirOutput = "./iphone-ref-movs/";

my $dirBase = getcwd;

# Working directories
my %workingDirs = ( dirOutput => $dirBase . "/iphone-ref-movs/", );

# Prepend url strings
my $url3gp = "http://low_bandbidth_url_goes_here/";
my $urlM4v = "http://high_bandbidth_url_goes_here/";

# MySQL connection data
my $dbHost     = "db_hostname_here";
my $dbDatabase = "db_databasename_here";
my $mysqlDsn   = "DBI:mysql:$dbDatabase;host=$dbHost";
my $dbUsername = "db_username_here";
my $dbPassword = "db_password_here";

# Create working directories, if they do not already exist.
while ( my ( $key, $value ) = each(%workingDirs) ) {
	if ( !-d $value ) { mkdir $value or die $!; }
	print $key . ": " . $value . "\n";
}

# Connect to MySQL database
my $dbh = DBI->connect( $mysqlDsn, $dbUsername, $dbPassword )
  or die "Cannot connect to database $dbHost: $@";

# Get a list of @songFilenames from the database
my $sqlQuery = "SELECT filename FROM videos WHERE filename != ''";
my $sth      = $dbh->prepare($sqlQuery);
$sth->execute();
my @songFilenames;
while ( my ($songFilename) = $sth->fetchrow_array() ) {
	push( @songFilenames, $songFilename );
}
$dbh->disconnect();
my $numSongIds = @songFilenames;

# Create the mov redirect files
foreach my $songFilename (@songFilenames) {
	my $dirOutput = $workingDirs{dirOutput};

	my $url3gp = $url3gp . $songFilename . ".3gp";
	my $urlM4v = $urlM4v . $songFilename . ".m4v";
	my $filenameMov = $dirOutput . $songFilename . ".mov";

	my $cmd       = "makeiPhoneRefMovie $url3gp $urlM4v $urlM4v $filenameMov";
	system($cmd);
}
Be Sociable, Share!

One thought on “Perl program for makeiPhoneRefMovie

  1. Just want to say your article is as amazing.
    The clarity in your post is just great and i can assume you are an expert on this subject.
    Well with your permission let me to grab your RSS feed to keep updated with forthcoming post.
    Thanks a million and please continue the enjoyable work.

Comments are closed.