Sunday, November 29, 2020

#1 2020-10-29 07:23:33 am

Almarenan
Member
Registered: 2020-10-27
Posts: 9

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 ?


Filed under: eyetv, package

Offline

 

#2 2020-10-29 08:08:18 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 1444

Re: Rename content of an .eyetv package

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"):

Applescript:


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":

Applescript:


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

Last edited by KniazidisR (2020-10-29 08:36:44 am)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

#3 2020-10-29 09:05:50 am

Almarenan
Member
Registered: 2020-10-27
Posts: 9

Re: Rename content of an .eyetv package

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.

Offline

 

#4 2020-10-29 09:46:51 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 1444

Re: Rename content of an .eyetv package

In your packages all is simpler as I see.

Applescript:


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:

Applescript:


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:

Applescript:


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

Last edited by KniazidisR (2020-10-29 10:12:47 am)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

#5 2020-10-29 10:31:21 am

Almarenan
Member
Registered: 2020-10-27
Posts: 9

Re: Rename content of an .eyetv package

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

Offline

 

#6 2020-10-30 12:26:11 pm

Almarenan
Member
Registered: 2020-10-27
Posts: 9

Re: Rename content of an .eyetv package

All right, did it smile 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 :

Applescript:

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.


Filed under: , eyetv, package, HandBrake

Offline

 

#7 2020-10-30 02:19:46 pm

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 1444

Re: Rename content of an .eyetv package

Almarenan wrote:

Applescript:


       -- 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")
       


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.

Last edited by KniazidisR (2020-10-30 02:30:06 pm)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

#8 2020-10-30 02:50:16 pm

Almarenan
Member
Registered: 2020-10-27
Posts: 9

Re: Rename content of an .eyetv package

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"

Offline

 

#9 2020-10-30 05:31:29 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6499

Re: Rename content of an .eyetv package

KniazidisR wrote:

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.



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


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#10 2020-10-30 10:56:47 pm

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 1444

Re: Rename content of an .eyetv package

Shane Stanley wrote:

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.

Last edited by KniazidisR (2020-10-30 10:57:11 pm)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)