Pārlūkot izejas kodu

Remove the dependency on movInfo (i.e. mplayer) and just use ExifTool. It works for most things we see and it is a lot cheaper and more portable than many other options.

Zachary Kotlarek 11 gadi atpakaļ
vecāks
revīzija
714e633888
1 mainītis faili ar 32 papildinājumiem un 19 dzēšanām
  1. 32 19
      transmission.pl

+ 32 - 19
transmission.pl

@@ -8,6 +8,7 @@ use Date::Parse;
 use File::Touch;
 use File::Temp qw/ :mktemp /;
 use File::Basename;
+use Image::ExifTool qw/ :Public/;
 use FindBin qw($Bin);
 use lib $Bin;
 use Fetch;
@@ -31,7 +32,7 @@ sub runAndCheck(@);
 # Parameters
 my $maxAge         = 2.5 * 86400;
 my $tvDir          = `~/bin/video/mediaPath` . '/TV';
-my $monitoredExec  = '/Users/profplump/bin/video/torrentMonitored.pl';
+my $monitoredExec  = $ENV{'HOME'} . '/bin/video/torrentMonitored.pl';
 my $host           = 'http://baldwin-ipv4.uberzach.com:9091';
 my $url            = $host . '/transmission/rpc';
 my $content        = '{"method":"torrent-get","arguments":{"fields":["hashString","id","addedDate","comment","creator","dateCreated","isPrivate","name","totalSize","pieceCount","pieceSize","downloadedEver","error","errorString","eta","haveUnchecked","haveValid","leftUntilDone","metadataPercentComplete","peersConnected","peersGettingFromUs","peersSendingToUs","rateDownload","rateUpload","recheckProgress","sizeWhenDone","status","trackerStats","uploadedEver","uploadRatio","seedRatioLimit","seedRatioMode","downloadDir","files","fileStats"]}}';
@@ -485,24 +486,36 @@ sub guessExt($) {
 		$ext = 'txt';
 	}
 
-	# Ask movInfo.pl about the demuxer
+	# Guess the file type if we don't have one yet
 	if (!$ext) {
+
+		my $mime  = '';
 		my $demux = '';
-		open(INFO, '-|', $ENV{'HOME'} . '/bin/video/movInfo.pl', $file, 'DEMUXER');
-		while (<INFO>) {
-			$demux .= $_;
+
+		# Try ExifTool
+		my $exif = ImageInfo($file);
+		if (defined($exif) && ref($exif) eq 'HASH') {
+			if ($exif->{'MIMEType'}) {
+				$mime = $exif->{'MIMEType'};
+
+			}
+			if ($exif->{'FileType'}) {
+				$demux = $exif->{'FileType'};
+			}
 		}
-		close(INFO);
-		$demux =~ s/^\s+//;
-		$demux =~ s/\s+$//;
 
-		# Grab a MIME type from file(1)
-		my $mime = '';
-		open(FILE, '-|', 'file', '-b', $file);
-		while (<FILE>) {
-			$mime .= $_;
+		# Try file(1) if we didn't find a MIME type yet
+		if (!$mime) {
+			open(FILE, ' - | ', ' file ', ' -b ', $file);
+			while (<FILE>) {
+				$mime .= $_;
+			}
+			close(FILE);
 		}
-		close(FILE);
+
+		# Cleanup the demuxer and MIME type
+		$demux =~ s/^\s+//;
+		$demux =~ s/\s+$//;
 		$mime =~ s/^\s+//;
 		$mime =~ s/\s+$//;
 		$mime =~ s/\;.*$//;
@@ -510,15 +523,15 @@ sub guessExt($) {
 
 		# Try to pick an extension we understand
 		$ext = 'avi';
-		if ($demux =~ /mkv/i || $mime =~ /Matroska/i) {
+		if ($demux =~ /MKV/i || $mime =~ /Matroska/i) {
 			$ext = 'mkv';
-		} elsif ($demux =~ /asf/i || $mime =~ /\bASF\b/i) {
+		} elsif ($demux =~ /ASF/i || $mime =~ /\bASF\b/i) {
 			$ext = 'wmv';
 		} elsif ($mime =~ /\bZIP/i) {
 			$ext = 'zip';
 		} elsif ($mime =~ /\bAVI\b/i) {
 			$ext = 'avi';
-		} elsif ($demux =~ /mpegts/i) {
+		} elsif ($demux =~ /MPEGTS/i) {
 			$ext = 'ts';
 		}
 	}
@@ -538,10 +551,10 @@ sub processFile($$) {
 			print STDERR 'Declining to save packaging file: ' . $file . "\n";
 		}
 		return 1;
-	}	
+	}
 
 	# Guess a file extension and basename
-	my $ext = &guessExt($file);
+	my $ext      = &guessExt($file);
 	my $filename = basename($file);
 
 	# Delete WMV files -- mostly viruses/fake