• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: asx file creation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: asx file creation


  • Subject: Re: asx file creation
  • From: kai <email@hidden>
  • Date: Fri, 1 Apr 2005 21:09:08 +0100


On Mon, 28 Mar 2005 14:49:26 -0800, nate wrote:

Hello, I currently have a web server up and running on osx and I want to use applescript or maybe perl? I'm not sure which yet to perform a sort of file conversion if you will. I am looking to have it parse a text file and output it in other format, basically it's coming from a text file and going to an asx file (which is really just an xml output).

here is a brief input file with 2x records.

----
000 Manufacturer Ascent No. 999 Equip AM-LOG Version 7.51 FLEx 1007


010 Title ALIAS
011 Client                               Facility
012 Shoot Date           Transfer Date 02-14-05  Opr PDD  Asst      Bay

100 Edit 0001 to V1234 Field A1 NTSC Split Delay
110 Scene 11 Take 1 Cam Roll A1064 Sound 241 19:45:57:05.0
201 Rnk-X 3P 23.98 A1064 007021+00 000001280 Key EASTM KR292763 007021+00 P1
300 VTR-A Assemble 416R04 At 04:00:00:00.0 For 00:00:53:10.0 Using LTC
400 SOUND Playback 241 At 19:45:57:05.0 For 00:00:53:10.0 Using LTC


100 Edit 0002 to V1234 Field A1 NTSC Split Delay
110 Scene 11 Take 2 Cam Roll A1064 Sound 241 19:49:13:14.0
201 Rnk-X 3P 23.98 A1064 007080+00 000001148 Key EASTM KR292763 007080+00 P3
300 VTR-A Assemble 416R04 At 04:00:53:10.0 For 00:00:47:25.0 Using LTC
400 SOUND Playback 241 At 19:49:13:14.0 For 00:00:47:25.0 Using LTC
----



the output would need to look like: ---- <ASX version="3.0"> <TITLE>Alias</TITLE> <ENTRY> <TITLE>Edit 0001 to V1234</TITLE> <REF href="Alias.WMV"/> <STARTTIME VALUE="00:00:00" /> <DURATION VALUE = "00:00:53"/> </ENTRY> <ENTRY> <TITLE>Edit 0002 to V1234</TITLE> <REF href="Alias.WMV"/> <STARTTIME VALUE="00:00:53" /> <DURATION VALUE = "00:00:47"/> </ENTRY></ASX> ----

So what I am asking I guess, is, is this even doable? If so, how do I even begin? O.O
Any help is much appreciated.

Looks as if this question might have been overlooked, Nate - so I'll take a crack at it, FWIW...


In theory, AppleScript should be able to parse the input data into the form you require - with a few qualifications:

[1] It's not easy to tell if the data received here had extra spaces introduced (particularly at line endings) when sending. I've therefore had to use some guesswork about that. (I'm not that familiar with asx files.)

[2] I also couldn't work out how you derived the start times in the output data - since they look slightly different from those in the input data. I've assumed the differences were the result of a couple of small errors - and continued regardless. (Like some of my other vices, I try to keep assumptions to a minimum - but not always with resounding success...)

[3] Finally, the following example was based on certain information consistently appearing on the same line numbers (010, 100, 300, etc.)

If necessary, it should be fairly simple to fix the first couple of points. The last one might be resolved with a little more care. The main point here is merely to demonstrate that this sort of thing should be perfectly possible.

I've tried to keep the lines fairly short to avoid too much wrapping - though some instances may still occur (and the input data towards the end is almost *bound* to break up). Anyway, if you want to pursue this approach, and still need some more help, just shout.

Um... sorry about the length, folks:

--------------------

property uCase : "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
property lCase : "abcdefghijklmnopqrstuvwxyz"

property tabStr : "    " (* 4 spaces *)
property retStr : ASCII character 10
property timeTags : {{" At ", "STARTTIME"}, {" For ", "DURATION"}}

on capsToLowerCase(l)
	repeat with n from 1 to count l
		set text item delimiters to l's item n
		if (count uCase's text items) > 1 then set l's item n to ¬
			lCase's item (1 + (count uCase's text item 1))
	end repeat
	set text item delimiters to {""}
	l
end capsToLowerCase

on capsToTitleCase(t)
	set l to {}
	set s to 1
	tell t to repeat with n from 2 to (count words)
		set e to (count (text 1 thru word n)) - (count word n)
		set l's end to item s & my ¬
			capsToLowerCase(items (s + 1) thru e)
		set s to e + 1
	end repeat
	set l's end to t's item s
	if s is (count t) then return l as string
	(l as string) & capsToLowerCase(t's items (s + 1) thru -1)
end capsToTitleCase

on dataToASX(d)
	set l to {}
	set text item delimiters to "010 Title "
	set d to d's text item -1
	set text item delimiters to retStr
	set mTitle to capsToTitleCase(d's text item 1)
	set l to {"<TITLE>" & mTitle & "</TITLE>"}
	set text item delimiters to retStr & "100 "
	repeat with e in (get rest of d's text items)
		set l's end to "<ENTRY>"
		set text item delimiters to tabStr
		set l's end to "<TITLE>" & e's text item 1 & "</TITLE>"
		set l's end to "<REF href=\"" & mTitle & ".WMV\"/>"
		set text item delimiters to retStr & "300 "
		set e to e's text item -1
		set text item delimiters to retStr
		set e to e's text item 1
		repeat with t in timeTags
			set text item delimiters to t's item 1
			set l's end to "<" & t's item 2 & " VALUE=\"" & ¬
				(e's text item -1)'s text 1 thru 8 & "\"/>"
		end repeat
		set l's end to "</ENTRY>"
	end repeat
	set text item delimiters to retStr
	set l to "<ASX version=\"3.0\">" & retStr & l & "</ASX>"
	set text item delimiters to {""}
	l
end dataToASX

set inputData to "000 Manufacturer Ascent No. 999 Equip AM-LOG Version 7.51 FLEx 1007

010 Title ALIAS
011 Client                               Facility
012 Shoot Date           Transfer Date 02-14-05  Opr PDD  Asst      Bay

100 Edit 0001 to V1234 Field A1 NTSC Split Delay
110 Scene 11 Take 1 Cam Roll A1064 Sound 241 19:45:57:05.0
201 Rnk-X 3P 23.98 A1064 007021+00 000001280 Key EASTM KR292763 007021+00 P1
300 VTR-A Assemble 416R04 At 04:00:00:00.0 For 00:00:53:10.0 Using LTC
400 SOUND Playback 241 At 19:45:57:05.0 For 00:00:53:10.0 Using LTC


100 Edit 0002 to V1234 Field A1 NTSC Split Delay
110 Scene 11 Take 2 Cam Roll A1064 Sound 241 19:49:13:14.0
201 Rnk-X 3P 23.98 A1064 007080+00 000001148 Key EASTM KR292763 007080+00 P3
300 VTR-A Assemble 416R04 At 04:00:53:10.0 For 00:00:47:25.0 Using LTC
400 SOUND Playback 241 At 19:49:13:14.0 For 00:00:47:25.0 Using LTC"


dataToASX(inputData)

--------------------

(*
--> "<ASX version=\"3.0\">
<TITLE>Alias</TITLE>
<ENTRY>
<TITLE>Edit 0001 to V1234</TITLE>
<REF href=\"Alias.WMV\"/>
<STARTTIME VALUE=\"04:00:00\"/>
<DURATION VALUE=\"00:00:53\"/>
</ENTRY>
<ENTRY>
<TITLE>Edit 0002 to V1234</TITLE>
<REF href=\"Alias.WMV\"/>
<STARTTIME VALUE=\"04:00:53\"/>
<DURATION VALUE=\"00:00:47\"/>
</ENTRY></ASX>"
*)

--------------------

---
kai
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: asx file creation
      • From: nate <email@hidden>
  • Prev by Date: Run Apple Script
  • Next by Date: Adding items to a record in a list.
  • Previous by thread: Run Apple Script
  • Next by thread: Re: asx file creation
  • Index(es):
    • Date
    • Thread