wanted: script to compile file names/duration

It may be in here and I’m unable to find it, but what I am looking for is a script that will look inside a specified Finder folder full of Quicktime movies only, and compile all of the file names and duration of each QT file into textEdit or Mail. I don’t write scripts at all, so I’m looking for something from scratch. Any help is greatly appreciated. Thanks.

Andrew

Model: Mac Pro
Browser: Safari
Operating System: Mac OS X (10.4)

I don’t think duration is a property of a QuickTime file that can be extracted using AppleScript. Only the size of the file is available.

EDIT: Like Adam, who posted while I was typing, I thought this was not possible, but the movie information window shows the duration, and I found it in the dictionary. I had to do some extra searching for the proper syntax.

Hi.

This post interested me because I have a folder of saved video chats (ecamm’s Conference Recorder saves them automatically) between my children and their grandfather, and it would be nice to add the duration to their names (a little different from your goal) so thanks for the idea.

I don’t have time right now to combine the following scripts to fully do what you want, but maybe you’ll be able to work that out.

This will list the names and copy them to the clipboard - it’s unclear whether TextEdit or Mail would be better; this allows a choice.


set movieFolder to choose folder
set movieNames to ""--empty string
tell application "Finder"
	set movieList to name of every file of folder movieFolder--list of movie names
	
	repeat with aMovie in movieList
		set movieNames to movieNames & aMovie & return--coerce list to string, one name per line
	end repeat
	
	set the clipboard to movieNames
end tell

display dialog movieNames--just to show the result, this can be removed

Do you want the duration in “00:00:00” format? I found the solution to that here: http://bbs.applescript.net/viewtopic.php?id=15802

This will display the duration of a single selected file:


set theMovie to choose file without invisibles
tell application "QuickTime Player"
	open theMovie
	set the time_scale to the time scale of movie 1
	set the movie_duration to the duration of movie 1
	set the movie_length to ((((movie_duration / time_scale) div 60) * 10 div 10) as string) & ":" & (((((movie_duration / time_scale / 60) - ((movie_duration / time_scale) div 60)) * 60) * 10 div 10) as string)
	close movie 1
end tell

display dialog movie_length

I was trying to avoid opening the movie - clearly a bad move. I also didn’t know about ‘time scale’. Now that I do, this script will grab all the movies in a chosen folder (and it assumes all are movies openable by QuickTime) and write a file to the desktop containing the data.

set MList to "Movies and Durations" & return
set MovieFolder to choose folder without invisibles
tell application "Finder" to set M to files of MovieFolder as alias list
repeat with aF in M
	set N to name of (info for contents of aF)
	set MList to MList & N & ", "
	
	tell application "QuickTime Player"
		open aF
		set the time_scale to the time scale of movie 1
		set the movie_duration to the duration of movie 1
		set the movie_length to ((((movie_duration / time_scale) div 60) * 10 div 10) as string) & " minutes & " & (((((movie_duration / time_scale / 60) - ((movie_duration / time_scale) div 60)) * 60) * 10 div 10) as string) & " seconds"
		close movie 1
	end tell
	
	set MList to MList & movie_length & return
end repeat

set dataFile to open for access ((path to desktop as text) & "Movies&Durations.txt") with write permission
try
	set eof of dataFile to 0 -- erase anything there
	write MList to dataFile
	close access dataFile
on error
	close access dataFile
end try

Nice - thanks Adam

I didn’t think to start the list with it’s description; I’ll remember that. andrewk will be pleased, and I have a head start on what I want to do.

j

capitalj and Adam having done all the hard work, I couldn’t resist my own variation. :slight_smile:

set MovieFolder to (choose folder without invisibles)
tell application "Finder"
	try
		set M to files of MovieFolder as alias list
	on error
		set M to {first file of MovieFolder as alias}
	end try
end tell

set MList to {"Movies and Durations", ""}
set padding to tab & tab
repeat with aF in M
	tell application "QuickTime Player"
		open aF
		set {name:N, duration:movie_duration, time scale:time_scale} to front movie
		close front movie
	end tell
	set running_time to movie_duration / time_scale
	-- To round the seconds instead of truncating, change 'div 1' in the next line to 'as integer'.
	tell (1000000 + running_time div hours * 10000 + running_time mod hours div minutes * 100 + running_time mod minutes div 1) as string
		set hhmmss to text 2 thru 3 & ":" & text 4 thru 5 & ":" & text 6 thru 7
	end tell
	set end of MList to N & padding & hhmmss
end repeat

set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to return
set {text:MList} to MList as string
set AppleScript's text item delimiters to astid

set dataFile to (open for access ((path to desktop as Unicode text) & "Movies&Durations.txt") with write permission)
try
	set eof dataFile to 0 -- erase anything there
	write MList to dataFile
end try
close access dataFile

Nice, Nigel - forgot to fix the time calc.

I’ve added this bit to get the tabbing to work out better - not terribly reliable I suspect, but works for my test files:


tell (1000000 + running_time div hours * 10000 + running_time mod hours div minutes * 100 + running_time mod minutes div 1) as string
		set hhmmss to text 2 thru 3 & ":" & text 4 thru 5 & ":" & text 6 thru 7
	end tell
-- Added bit ----
	set nn to (count of characters of N)
	if nn < 19 then
		set padding to tab & tab & tab
	else if nn < 24 then
		set padding to tab & tab
	else
		set padding to tab
	end if
-- End added bit ----
	set end of MList to N & padding & hhmmss

This is incredible, works perfectly. Thanks guys, you have no idea how much time this is going to save me and my co-workers. I work at a TV station where we compile cue sheets of Quicktime files sometimes 50-100 items long. If one file name is misspelled or duration incorrect, we go off the air, this is a lifesaver. I cant say enough good things about forums and communities like these. Keep it up. Thanks again.

Andrew

Cool, thanks Jaques. I wish I had half your knowledge.

j

I agree with CapJ, but interestingly there’s surprisingly little difference in time. On MM, about 400 millisec for 16 files out of a run of 10 to 11 seconds with QuickTime Reader open to start with - about 4%, marginally longer if you consider the time to open QuickTime Reader, but this only happens once. Having said that, I do admire Jacques’ grasp of dictionaries.

Thirded. Fancy finding the best QuickTime solution in System Events’s dictionary!

On a mere dual-processor machine, with the same number of files, with QuickTime already open, and timing only the file gathering and the repeat loop, Jacques’s script is about four to five times as fast as mine. A good technique to know!

I see System Events’s dictionary talks about “audio datas”, “movie datas”, etc. I thought it was bad enough seeing a disk’s local volume property explained as: “Is the media a local volume?” :wink:

Good point on the speed in bold. I just looked at the time taken by Script Debugger 4 instead of timing it as I should have. :rolleyes: Absolutely agree on “A good technique to know!” I had never looked at the Movie Suite. Kudos to Jacques.