Rename content of an .eyetv package

Hi,

I'm a total newbie at AppleScript but I've toying for some time with the idea of using it to automate the process that I use to help me deal with Handbrake recode of EyeTv recordings. 

An .eyetv file is essentially a package containing a few proprietary files of no interest to me and the video as a .mpg file that Handbrake “sees” and recode.

The problem is that there is no relation between the name of the package and the name of the .mpeg file inside it (it consist mostly of a bunch of almaphanumerics caracters such as "00000000253e126c" that Handbrake will use to name the encoded file… which is a pain). 

As of right now, I open the package and rename the .mpg file inside to that of the .eyetv file. It works great for one, two or even three but I'm stuck with more than 200 and would like to automate the process. 

I know enough to loop through every file in a folder but I'm totaly clueless about how to get to the inside of a package (if it is at all possible), find the .mpg file inside and rename it.

Any tip ?

I can help you if you provide the path to .mpg file (that is, package structure). You can’t get entire contents of .evetv package, but you can get entire contents of child folder of .evetv package. What is its name?

For example, the Handbrake.app is also package, like your .evetv package. I can get its entire contents because I know the name of its child folder (it is “Contents”):


set handbrakePackage to path to application "HandBrake"

tell application "Finder"
	set thePackageContents to entire contents of folder "Contents" of handbrakePackage
end tell

The result is list. Now I can sort it, filter, copy some item, rename it and so on

Other example. Getting every file of package whose name extension is “xpc”:


set handbrakePackage to path to application "HandBrake"

tell application "Finder" to set thePackageContents to (every file of entire contents of folder "Contents" of handbrakePackage whose name extension is "xpc") as alias list

First, thanks for the prompt reply.

The structure of an .eyetv package (‘myEyeTvRecording.eyetv’) is as follows :

  • myEyeTvRecording.eyetv
    00000000253b3525.eyetvp
    00000000253e126c.eyetvi
    00000000253e126c.eyetvr
    00000000253e126c.mpg
    00000000253e126c.thumbnail.tiff
    00000000253e126c.tiff

The first 3 are more or less text files used by EyeTv and the last 2 are just images for previsualisations purposes. As you can see, all the files have the same name.
Important sidenote, it is of no importance if ALL the files are renamed as myEyeTvRecording but it’s only the .mpg one that really counts.

In your packages all is simpler as I see.


set mpgFiles to {}
tell application "Finder"
	set theEveTVfiles to (get selection) -- get selected .evetv packages
	repeat with anAlias in theEveTVfiles -- loop with every package
		-- get list of mpg files of current package
		set mpgs to (every file of anAlias whose name extension is "mpg") as alias list
		repeat with theMpg in mpgs -- loop with every mpg file of current package
			set end of mpgFiles to contents of theMpg
		end repeat
	end repeat
end tell
return mpgFiles -- list of all founded mpg files, as alias list

Now, having references list, you can loop this list and rename the mpg files as needed, using Finder.
For example, if you want to set name of mpg file to name of its package, you can replace return mpgFiles with this:


tell application "Finder"
repeat with theMpg in mpgFiles
	set name of theMpg to (text 1 thru -5 of (name of container of theMpg)) & ".mpg"
end repeat

NOTE: I don’t know about .eveTV packages. If the mpg file in each package may be only 1 then alias list should be replaced with single alias:


set mpgFiles to {}
tell application "Finder"
	set theEveTVfiles to (get selection) -- get selected .evetv packages
	repeat with anAlias in theEveTVfiles -- loop with every package
		-- add single alias to global aliases list
		set end of mpgFiles to (some file of anAlias whose name extension is "mpg") as alias
	end repeat
end tell
return mpgFiles -- list of all founded mpg files, as alias list

OK, many thanks for the infos, I’m gonna see where I can go with all of that.

All right, did it :slight_smile: :stuck_out_tongue:

Thanks to your pointers, I’ve made something that works and even goes beyond the initial terms since after being renamed, the .mpg files are now extracted from the .eyetv package which are then sent then ignominiously to the trash…

It goes like this :

tell application "Finder"
	set selected to selection
	set current_folder to item 1 of selected
	set theEveTVfiles to every file of current_folder -- get selected .evetv packages
	repeat with anItem in theEveTVfiles -- loop with every package
		-- find the .mpg file inside the package
		set mpgFile to (some file of anItem whose name extension is "mpg")
		-- change the .mpg files name to that of it's parent package
		set name of mpgFile to (text 1 thru -7 of (name of container of mpgFile as text)) & ".mpg"
		-- the .mpg file's name has changed so we need to "find" it again
		set mpgFile to (some file of anItem whose name extension is "mpg")
		-- move the .mpg file out of the .eyev package
		move mpgFile to current_folder
		-- delete the now useless .eyetv package
		delete anItem
	end repeat
end tell

Works as a charm, now Handbrake can “see” all the files inside current_folder at once and treat them.

Thanks again.

The name of mpgFile is changed, but not reference mpgFile to the file. Let me remind you that the file name is the text, and the file is a reference to it (the address of the first byte of the file on the disk, that is, the number). While the file remains on old position on the disk, its reference (address) doesn’t change.

So, this code line second time is unnecessarily.

Except that without this line, it throws an error that says literally that he can’t find the document with the old name ("Impossible to get document file "0000000024fac368.mpg" of document file etc, etc (see below)) when it tries to execute the “move to” command.

It’s the fact that he’s apparently still referencing the renamed file by it’s old name that made me use the “set mpgFile to (some file of anItem whose name extension is “mpg”)” line again.

“number -1728 from document file “0000000024fac368.mpg” of document file “Le dessous des cartes - 240, Islam(s), islamisme(s) - quelle géographie ? (2020).eyetv” of folder “dossier sans titre 2” of folder “Rip” of folder “Desktop” of folder “MBP” of folder “Users” of startup disk”

That’s not so. Aliases behave that way – but not on APFS formatted disks – but Finder references are ultimately based on path strings.

You’re right as always, Shane. 1) I missed the point that the OP changed the alias of my code to a Finder reference. 2) Although I experimented a little with Finder references and did not know that they are hardcoded to the filename, I instinctively knew that it was better to use alias. Anyway, thanks for the info on Finder references.