Parsing infos/numbers

Hello.

If it is so, that your text has control characters at the end of it, then this way, may do the trick:

I always hope it is as easy as that. :slight_smile:

set a to "20:30:47:15ÃŽ"

set b to words of (text 1 thru 11 of a)
 b

:smiley:

if you should have to change from BigEndian to SmallEndian, then I think the Unix tool dd can be handy, just another option, as I think Nigel’s method is the easiest one.

Edit

The swab option of dd isn’t usable, since it only swaps odd and even bytes.

Perl has its pack and unpack functions that is usuable.

Does not work either…
I also tried :

set duree_a_traiter to ((characters 1 thru -2 of duree_a_traiter) as string)

And i checked how many char i could remove at the end without removing any actual value i need, i came to 2.
I can remove 2 char with this command and it doesnt affect my value. I must have invisible char in the log.

But it doesnt solve my problem…

Yes it produces a readable copy. I cant process it with my scriupt either tho…

Why can’t you process it with your script? And, you are truly awesome Nigel!

If you just show us a line or two with the data you are getting from the converted file, then I am sure we can think of something. :slight_smile:

I mean, i can. But i get the same error. Ill post you the whole log file asap

Here the log file of today : http://c-and-d.fr/perso/ArchivePlay.log

I ran the script with the sample datas which you posted.
So, there weren’t the extraneous nil bytes.

Yvan KOENIG (VALLAURIS, France) mardi 4 décembre 2012 20:49:55

You ran the sxript on the archiveplay.log i just posted and you are able to se the dur_sec value?

Of course the answer is NO.
Compare the time where I post my first message with the time when you posted the link.

Try to replace the instruction reading the file by this one :


set fichierSource to ((path to desktop as text) & "ArchivePlay.log")
tell application "TextWrangler"
	activate
	open fichierSource
	zap gremlins text of document 1 with nulls
	set bigtext to text of document 1
	close document 1 saving no
end tell

With your sample file it works.

Yvan KOENIG (VALLAURIS, France) mardi 4 décembre 2012 21:20:14

The file to which you’ve linked seems OK and the text it contains is little-endian UTF-16.

The times you’re trying to convert to seconds look like SMPTE codes, where the figures after the decimal point are frames, probably in 25ths of a second.

Assuming you’ve used my previous code to get the text into the script properly, you can convert ‘duration’ to seconds like this:

set duration to item 8 of enregistrement_a_traiter2 -- existing line.

tell duration to set duration to (word 1) * hours + (word 2) * minutes + (word 3)
set duration to duration div 1 + (duration mod 1) * 4

@yvan This isna big step forward!
This works for me and my log file!

Thanks a lot for the tip.

The only thing is that i will have to install text wrangler on my process machine and use it in addition…

What does exactly do textwrangler that cant be made in applescript?

I dont quite understand your bit of script.

Anyway thanks a lot for the tip!

Exactly, these are smpte timecodes

But i dont need the exact frame count, as i cannot trim my movie to a specific frame in qt… Thats why i added a an extra second at the end of each clip i wanted to trim.
The +9 is because i have a 10 seconds white in between each clips on my big video file (the one i’m segmenting with this script)

If there is a way to trim to,the exact frame thzt would be awsome but i didnt find anything.
By the way, i tried to process my log with your scriot but the result was the same, the number could not be used as integer…

The only working solution for now is the textwrangler one
Thanks a lot to everyone helping in this thread ')

Encore un français qui ne juge pas utile d’ouvrir le dictionnaire des applications utilisées !

Je le fais donc pour vous :

zap gremlins‚v : Removes or replaces unwanted characters from text
zap gremlins specifier : the text to be processed
[zap action delete_gremlin/Œreplace_with_code/Œreplace_with_char] : action to be performed on gremlin characters (defaults to delete_gremlin)
[zap character text] : character to use as the replacement with “replace_with_char” is used
[nulls boolean] : zap null (ASCII 0) characters?
[controls boolean] : zap control characters?
[non ASCII characters boolean] : zap non-ASCII characters?
→ text : the modified text

En bon Français, la commande :
zap gremlins text of document 1 with nulls
supprime les octets nuls du texte.
De ce fait le script peut traiter du texte sans « parasites ».

Il y a probablement moyen d’effectuer le nettoyage autrement.
Je cherchais avant tout à donner au plus vite une formule opérationnelle.
Maintenant que le problème est clairement identifié je suis sur que Niget va vous concocter une incantation magique effectuant le nettoyage sans aspirateur.

Yvan KOENIG (VALLAURIS, France) mardi 4 décembre 2012 21:46:00

Merci mais j’avais ouvert le dico, mais c’est le null que je ne comprenais pas.

Merci pour le tuyeau

For others : the textwrangler tips cleared the file of all unwanted bytes!
But it would be nice not to use another app

This can do almost the same, but you’ll loose the linefeeds, so you are back into square one, with a sed script for getting the data out of the log.

tr -d “[:control:]” <ArchivePlay.log >|new.log

The unix command tr - translit can be invoked from the command line to to this. There is no problem on doing that comand on every paragraph of your logfile, paragraph by paragraph by a do shell script.

Never mind the above, it doesn’t work anyways.

This was interesting, and i did find something to work for you, I did this with the logfile you posted, and I got sane characters back, when I looked at it in Script Debugger:


set muf8 to (do shell script "iconv -f UTF-16LE -t UTF-8 /Users/you/your/path/To/Nigels/fixed/Logfile")
# Now the text should be able to be processed as you wanted it to.

:slight_smile:

Awesome !!!
This is perfect.
Yvan predict that you would do some magic here; and you did.
Thanks a lot.
I’ll post the whole script when i’ll be done. Might be usefull to others.

In fact, I tought to Nigel (apologizes for the typo in my original message)

I’m not sure of who is behind the pseudo McUsrII.
Maybe it’s my old acquintance McUsr but I’m not sure so I was unable to guess that he would deliver a magical incantation before Nigel.

Yvan KOENIG (VALLAURIS, France) mardi 11 décembre 2012 14:55:58

It is McUsr Yvan, and I’ll leave the magic to Nigel. :slight_smile:

since you’re around, would you know how to trim in quictime to an exact frame?
I looked into the dictionary of quictime 7 (qt X doesnt mention frames), and apparently it s possible to use frames. But it is possible to use frame to trim?

edit : nevermind, i found what i was looking for. The syntax is different. I had to do thid

	
		tell document 1
			select at in_point to out_point
			trim
		end tell