8 Replies Latest reply on Jul 24, 2012 5:31 AM by ultranix

    parse text from playlist

    ultranix

      Title

      parse text from playlist

      Post

      Hey there, I have a PLS playlist:

      [playlist]
      File1=01 - Introduction To The Audio Book.mp3
      Title1=David Allen - Introduction To The Audio Book [www.finansineateitis.lt]
      Length1=32
      File2=02 - A New Practice For A New Reality.mp3
      Title2=David Allen - A New Practice For A New Reality [www.finansineateitis.lt]
      Length2=238
      File3=03 - The 'Ready State' Of The Martial Artist.mp3
      Title3=David Allen - The 'Ready State' Of The Martial Artist [www.finansineateitis.lt]
      Length3=93
      File4=04 - Dealing Effectively With Internal Commitments.mp3
      Title4=David Allen - Dealing Effectively With Internal Commitments [www.finansineateitis.lt]
      Length4=123
      File5=05 - The Basic Requirements For Managing Commitments.mp3
      Title5=David Allen - The Basic Requirements For Managing Commitments [www.finansineateitis.lt]
      Length5=189
      File6=06 - The Real Work Of Knowledge Work.mp3
      Title6=David Allen - The Real Work Of Knowledge Work [www.finansineateitis.lt]
      Length6=43
      NumberOfEntries=6
      Version=2

      All I want to parse is 1) filename (everything after File1=; File2=; File3=; etc.) and put in into globals (used for creating new records in input layout) and 2) length (everything after Length1=; Length2=; Length3=;


      How do i do that?

        • 1. Re: parse text from playlist
          philmodjunk

          Is this text in a single field in a single record or does the following block represent text in just one field:

          File1=01 - Introduction To The Audio Book.mp3
          Title1=David Allen - Introduction To The Audio Book [www.finansineateitis.lt]
          Length1=32

          On this field, does Getvalue (thisField ; 1 ) return:

          "File1=01 - Introduction To The Audio Book.mp3" ?

          I think a looping script should be able to use get value to pull a line of text and then extract all text to the right of the "=" using the position, right and length functions.

          My questions are just to confirm the details needed to construct such a script.

          • 2. Re: parse text from playlist
            ultranix

            Well, not exactly. I have global fields for input purposes:

            1) xfilename1 and that should consist of "01 - Introduction To The Audio Book.mp3"

            2) xduration1 = "32" (or, in other case, converted to time, 00:00:32)

             

            then xfilename2 - 02 - A New Practice For A New Reality.mp3

            xduration2 - 238 (00:03:58)

             

            and so on.

            • 3. Re: parse text from playlist
              philmodjunk

              That doesn't answer my questions. I'm asking about the format of the data before you starting parsing it. Is it all in one field of one record or multiple records?

              and when you use the getvalue function on this text like I described in my last post, what result do you get?

              I wouldn't use a set of individual global fields fields like this for storing the data after it is parsed, I'd createa series of records with a single duration and filename field in each. That's much easier to work with in most situations.

              • 4. Re: parse text from playlist
                ultranix

                well, what confuses you is my "style" of input.

                I don't "store" data in global fields. they are cleared (with a script) as soon as new records (with indexed fields, non-global) are created. I use globals to run the script that double-checks whether the record is already present in the database (find mode, set field, constrain found set, if get found count = 0, then create new record) and therefore to avoid duplicates.

                I use regular fields for the stored data. and that playlist. I suppose it would be a global field, which would be copy-pasted from text editing software.

                to my mind, it goes like this:

                1) enter data entry layout.

                2) custom dialog shows up "Do you want to insert playlist data..." Yes | No

                3) if Yes - then you have the ability to paste text into the field

                4) Parse | Cancel buttons.

                5) After I click Parse, it parses as many filenames and durations as it is on the text entered previously.

                Am I make myself clear?

                • 5. Re: parse text from playlist
                  philmodjunk

                  Whether you store the data for a brief moment or permanently, it's stored in those fields. The issue is that you have a limited set of separate fields and this makes your script to parse the data more complex and less flexible. If you are moving the data in and out of global field, you probably don't need them at all, you can use variables instead.

                  You still haven't answered my questions about the format of the data before it is parsed. Each of your answers tell me about what you want produced by parsing the text.

                  BEFORE PARSING,

                  Is the text shown in your original post in just one single field?

                  Would GetValue ( ThisTextToBeParsed ; 1 )

                  return:

                  [playlist]

                  or

                  File1=01 - Introduction To The Audio Book.mp3

                  or something else? (Need to make sure that characters FileMaker recognizes as a "return" separate your lines of text.)

                  • 6. Re: parse text from playlist
                    ultranix

                    It is shown in just one single field, i.e. GetValue ( ThisTextToBeParsed ; 1 ) would return [playlist]

                    • 7. Re: parse text from playlist
                      philmodjunk

                      Ok then. This is the script I can think of to parse the data. I'll use a related table for generating the list of parsed values and then discuss what changes would be needed to use the separate fields that you wanted to use. I'm also going to assume that this text is in a global field. If not a simple Set Field step putting it in a global field will take care of that detail.

                      Go To Layout ["Parsed List" (ParsedList)]
                      Set Variable [$K ; Value: 2 ] //first line of text to contain something we want to parse.
                      Loop
                         New Record/Request
                         Set Field [ParsedList::FileName ; Let ( [ T = GetValue ( Globals::gParseText ; $K ) ;
                                                                                   L = Length ( T ) ;
                                                                                   P = Position ( T ; "=" ; 1 ; 1 )
                                                                                ];
                                                                                If ( P ; Right ( T ; L - P ) ; "ParseError " & $K )
                                                                               ) ]
                         Set Field [ParsedList::Duration ; Let ( [ T = GetValue ( Globals::gParseText ; $K + 2 ) ;
                                                                                   L = Length ( T ) ;
                                                                                   P = Position ( T ; "=" ; 1 ; 1 )
                                                                                ];
                                                                                If ( P ; Right ( T ; L - P ) ; "ParseError " & $K )
                                                                               ) ]
                         Set Variable [$K ; value: $K + 3 ]
                         Exit Loop if [$K > ValueCount ( Globals::gParseText ) ]
                      End Loop


                      Note that it would be simple to add one more set field step that loads a foreign key field with a value from the primary key field of a parent record to link all these records with parsed text to a specific parent record.

                      Doing the same with separate fields. Not what I'd recommend as it complicates the scripting but you could replace the set field steps with set field by name steps where the Value of $K could be used in a calculation that produces the field's name. 

                      • 8. Re: parse text from playlist
                        ultranix

                        thanks, it worked (Y)