Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mdburke

macrumors member
Original poster
Apr 17, 2008
31
0
So, since all my movies were ripped to avi before I converted to Mac, I needed a solution to add them to iTunes and play them on my Apple TV without converting them all. What I did was install Perian and other codecs on the Apple TV. Then I used the script Apple TV Fooler to "convert" the files to a .mov acceptable by iTunes. What Apple TV Fooler does is add a 1 second blank clip (H.264, AAC) to the beginning of each movie so that iTunes thinks that it is the correct file type. This worked perfectly and solved my problem.

However, now that I've gone ahead and done this to all my movies, I'd like to undo it so that these files can be used by Plex since I am interested in buying a Mini and making my own Media Center. Does anyone have any knowledge of how to create a similar script, except with the reverse effects (delete the first 1 second of each movie)?

Thanks.
 

mdburke

macrumors member
Original poster
Apr 17, 2008
31
0
Well, I suppose I can post the script that adds the clip:
Code:
property extension_list : {"avi", "divx", "flv", "mpg", "mp2", "vob", "m2v", "wmv", "mov"}
global target_folder
global NothingMovPath

on run
	set AppleScript's text item delimiters to ", "
	set AppleScript's text item delimiters to ""
end run

-- This droplet processes both files or folders of files dropped onto the applet
on open these_items
	-- this routine uses the gestaltVersion_info() sub-routine
	copy my gestaltVersion_info("qtim", 8) to {QT_version, QT_string}
	if the QT_version is less than "0502" then
		display dialog "This script requires QuickTime 5.0.2 or higher." & ¬
			return & return & "The currently installed version is: " & ¬
			QT_string buttons {"Cancel"} default button 1
	end if
	
	--set the target_folder to choose folder with prompt "Destination folder for the converted files:"
	repeat with i from 1 to the count of these_items
		set this_item to (item i of these_items)
		set the item_info to info for this_item
		if folder of the item_info is true then
			process_folder(this_item)
		else if (alias of the item_info is false) and (the name extension of the item_info is in the extension_list) then
			process_item(this_item)
		end if
	end repeat
	-- delete the temp folder
	tell application "Finder"
		empty trash
	end tell
end open

-- this sub-routine processes folders
on process_folder(this_folder)
	set these_items to list folder this_folder without invisibles
	repeat with i from 1 to the count of these_items
		set this_item to alias ((this_folder as text) & (item i of these_items))
		set the item_info to info for this_item
		if folder of the item_info is true then
			process_folder(this_item)
		else if (alias of the item_info is false) and ¬
			(the name extension of the item_info is in the extension_list) then
			process_item(this_item)
		end if
	end repeat
end process_folder

-- this sub-routine processes files
on process_item(this_item)
	-- NOTE that the variable this_item is a file reference in alias format
	-- FILE PROCESSING STATEMENTS GOES HERE
	with timeout of 3600 seconds -- one hour per movie time limit
		set NothingMovPath to path to resource "nothing.mov"
		tell application "QuickTime Player"
			launch -- bypasses promo movie
			activate
			my toggle_suppress(true)
			
			stop every document
			close every document saving no
			
			try
				open this_item
				
				tell application "Finder"
					-- set the file_name to the name of the original_file
					set the file_name to my add_mov_ext(this_item)
					set the target_folder to the container of the this_item
					if exists file file_name of the desktop then ¬
						delete file file_name of the desktop
					set the new_file to ((desktop as text) & file_name)
				end tell
				tell document 1
					rewind
					select all
					copy
					select none
				end tell
				close document 1 saving no
				open NothingMovPath
				tell document 1
					select none
					rewind
					add
					select none
					rewind
				end tell
				save self contained document 1 in file new_file
				tell application "Finder"
					
					--comment out the "delete this_item" and "empty trash" lines if you don't want to get rid of the original files
					
					delete this_item
					move file new_file to the target_folder with replacing
					-- empty trash
					
					--adds converted file to itunes
					
					(*tell application "iTunes"
						launch
						set this_track to add new_file to playlist "Library" of source "Library"
						duplicate this_track to this_playlist
					end tell*)
					
				end tell
				
			on error error_msg
				try
					beep
					display dialog error_msg buttons {"Cancel", "Continue"} default button 2 with icon 1
				on error
					my toggle_suppress(false)
					error number -128
				end try
			end try
			my toggle_suppress(false)
			close document 1 saving no
		end tell
	end timeout
end process_item

on add_mov_ext(this_item)
	set the item_info to info for this_item
	set the item_name to (the name of the item_info) as string
	set the name_extension to (the name extension of the item_info) as string
	if the name_extension is not "" then
		set the base_name to (characters 1 thru -((length of name_extension) + 2) of the item_name) as string
		set the new_name to the base_name & ".mov"
	else
		set the new_name to the item_name & ".mov"
	end if
	return the new_name
end add_mov_ext

on toggle_suppress(status_flag)
	tell application "QuickTime Player"
		set ignore auto play to the status_flag
		set ignore auto present to the status_flag
	end tell
end toggle_suppress

on gestaltVersion_info(gestalt_code, string_length)
	try
		tell application "Finder" to ¬
			copy my NumToHex((system attribute gestalt_code), ¬
				string_length) to {a, b, c, d}
		set the numeric_version to {a, b, c, d} as string
		if a is "0" then set a to ""
		set the version_string to (a & b & "." & c & "." & d) as string
		return {numeric_version, version_string}
	on error
		return {"", "unknown"}
	end try
end gestaltVersion_info

on NumToHex(hexData, stringLength)
	set hexString to {}
	repeat with i from stringLength to 1 by -1
		set hexString to ((hexData mod 16) as string) & hexString
		set hexData to hexData div 16
	end repeat
	return (hexString as string)
end NumToHex

I had to modify it a little bit to get it working on Leopard.

Again, any suggestions are welcome.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.