Best way to parse a subtitle file (.srt) ?

Hey there!
I'm a total newbie with Cocoa and I'm currently trying to improve my knowledge in parsing files through a simple TableView. More precisely, I'd like to parse .srt files. Those are subtitle files that can be opened with a basic text-editor. Here's the structure of such a file :
1
+00:00:00,324 --> 00:00:02,257+
+Previously on Greek...+
2
+00:00:02,638 --> 00:00:05,022+
+Come on! That's gonna be+
+the best party ever!+
3
+00:00:05,126 --> 00:00:07,540+
+Yeah, I know... but she doesn't+
+want to see me again.+
As you see, each subtitle is composed of 3 parts : a kind of ID, the output period (xx:xx:xx,xxx) and the content (which is supposed to be composed of 2 lines max. but not everytime so...).
I'd like to be able to read an SRT file so that I can put its content into my TableView (which has 3 columns : one for the beginning time, one for the end time and one for the content).
Any help would be appreciated!
Thanks in advance and sorry for my rusty English
PS: I'm not asking for a code; just for a solution, a way to do it

Electrobitch wrote:
I'm not asking for a code; just for a solution, a way to do it
Lots of threads go something like, "How would I go about... Does anyone have any ideas?". So I write a little essay about general approach with reference links, only to be asked for sample code. Them I'm asked for ideas about where to put the sample code. Then I find out the OP is sitting in a cubical somewhere, the boss expects to see working screens in 6 hours 23 minutes, and my student was looking for finished code from the start.
So usually I'm happy to avoid code. However in this case I wouldn't recommend a Cocoa class, a script language or the front end of a compiler. My approach would be to just parse the file in C. I doubt it will take many lines, but it would be way easier for me to post commented code than to explain how to start from scratch, ok?
Can you tell me if the format you described is a standard? I.e., is your file exactly the same as a SRT format I can find on the web? (E.g., here's one that includes some html: [http://forum.doom9.org/archive/index.php/t-73953.html]). Just so you'll know how obsolete I am, I never heard of SRT before. If one of my kids was around I'm guessing I wouldn't need to Google it, but I'm on my own today.
I just need to know how much variation there could possibly be from what you posted. Hopefully my code will be clear enough for you to trim it yourself, but I'd like to get it as close as I can the first time.
\- Ray

Similar Messages

  • Best way to read from a file

    What would be the best way to read from a file. Which classes do I need to use?
    I have to write a program, which reads data from a comma separated flat file, parse it and after inserting some busineess logic insert into a databse .
    I will have to read the data line by line.
    Any help????

    I would use:
         public void readData()
              try
                   data = new String[this.countRows("comp.txt")][];
                   BufferedReader br = new BufferedReader(new FileReader("comp.txt"));
                   for(int x = 0; x < data.length; x++)
                        StringTokenizer temp = new StringTokenizer(br.readLine(), "?");
                        data[x] = new String[temp.countTokens()];
                        for(int y = 0; y < data[x].length; y++)
                             data[x][y] = temp.nextToken();
              catch(Exception e)
                   System.out.println(e.toString());
         private int countRows(String f)
              int t = 0;
              try
                   BufferedReader brCountRows = new BufferedReader(new FileReader(f));
                   while(brCountRows.readLine() != null)
                        t++;
              catch(Exception e)
                   System.out.println(e.toString());
                   return t;
              return t;
         }It works deliciously!

  • What is the best way to include an xml file in JSP?

    I have a jsp page that I need to include an xml file. The xml file
              uses an xsl to render the file. What is the best way to include the
              xml file and still maintain the structure of the style sheet?
              Thanks
              Jennifer
              

              The best way is using the tag lib. If you cannot, but you can use JAXP, you can
              try
              javax.xml.transform.Transformer.transform(Source xmlSource,
              Result outputTarget)
              throws TransformerException
              You construct the transformer with you xsl, use you xml file or DOM to form xmlSource,
              and use JSPWriter "out" to form outputTarget (StreamResult). But if your JSP page
              generates the xml itself, tag lib is the only way.
              [email protected] (Jennifer) wrote:
              >[email protected] (Jennifer) wrote in message news:<[email protected]>...
              >> I have a jsp page that I need to include an xml file. The xml file
              >> uses an xsl to render the file. What is the best way to include the
              >> xml file and still maintain the structure of the style sheet?
              >>
              >> Thanks
              >>
              >> Jennifer
              >
              >Or is there a way to parse the xml file with the jsp page to display
              >the information. I cannot use the Java Standard Tag Libraries as the
              >version of iplanet we are running does not support the JSTL
              >
              >Thanks
              >
              >Jennifer
              

  • What is the best way to keep my personal files stored in iCloud separate from my work-related files?

    What is the best way to keep my personal files stored in iCloud separate from my work-related files? It seems that I'm not allowed to link my iPad mini and my work iMac using two different accounts, so I'm wondering how to make my single personal account work for both, while keeping personal vs work files reasonably separated.
    Thanks for any suggestions.

    Is it possible for you to upgrade your account to iCloud Drive? That would mean, all Macs upgraded to Yosemite, and all mobile devices to iOS8?
    See:  iCloud Drive FAQ and iCloud: About using iWork for iOS and iCloud
    In iCloud Drive you could create two separate custom folders, one for work documents and one for private documents and organize your documents there.  Don't use the app specific folders (Keynote, Pages, Numbers, ...) , because you can only create one level of folders inside these folders.

  • What's the best way for reading this binary file?

    I've written a program that acquires data from a DAQmx card and writes it on a binary file (attached file and picture). The data that I'm acquiring comes from 8 channels, at 2.5MS/s for, at least, 5 seconds. What's the best way of reading this binary file, knowing that:
    -I'll need it also on graphics (only after acquiring)
    -I also need to see these values and use them later in Matlab.
    I've tried the "Array to Spreadsheet String", but LabView goes out of memory (even if I don't use all of the 8 channels, but only 1).
    LabView 8.6
    Solved!
    Go to Solution.
    Attachments:
    AcquireWrite02.vi ‏15 KB
    myvi.jpg ‏55 KB

    But my real problem, at least now, is how can I divide the information to get not only one graphic but eight?
    I can read the file, but I get this (with only two channels):
    So what I tried was, using a for loop, saving 250 elements in different arrays and then writing it to the .txt file. But it doesn't come right... I used 250 because that's what I got from the graphic: at each 250 points it plots the other channel.
    Am I missing something here? How should I treat the information coming from the binary file, if not the way I'm doing?
    (attached are the .vi files I'm using to save in the .txt format)
    (EDITED. I just saw that I was dividing my graph's data in 4 just before plotting it... so It isn't 250 but 1000 elements for each channel... Still, the problem has not been solved)
    Message Edited by Danigno on 11-17-2008 08:47 AM
    Attachments:
    mygraph.jpg ‏280 KB
    Read Binary File and Save as txt - 2 channels - with SetFilePosition.vi ‏14 KB
    Read Binary File and Save as txt - with SetFilePosition_b_save2files_with_array.vi ‏14 KB

  • What is best way dealing with large tiff file in OSX Lion?

    I'm working with large tiff  file (engineering drawing), but preview couldnt handle (unresponsive) this situation.
    What is best way dealing with large tiff file in OSX Lion? (Viewing only or simple editing)
    Thx,
    54n9471

    Use an iPad and this app http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=400600005&mt=8

  • What's the best way to parse a BSTR in TestStand?

    I receive a BSTR from an OLE interface; what is the best way to parse this into something understandable? Has anyone written a routing for this?

    Hi,
    If you are using a OLE interface I think you will be using the Active X Automation adaptor.
    TestStand Active X Automation Adaptor automatically converts BSTR when it store the data in a TestStand variable.
    Then you should be able to use the regular string functions which are available in TestStand to parse the strings.
    Please let me know if you have any more questions.
    Regards
    Anand Jain

  • Best way to validate and xml file against a schema?

    As the subject states, I want to validate my xml file against a given schema....
    Currently my code looks like this:
    InputSource ipSource = new InputSource(new ByteArrayInputStream(bytesData)); // my xml file
    DOMParser parser = new DOMParser();
    parser.parse(ipSource);
    Document doc = parser.getDocument();
    I see that there is a setFeature method on DomParser.... but from what I read that doesnt support
    xml schema's, just DTD's. So what is the best way to validate with schema's?
    Any help would be appreciated

    This is the other way I tried doing it.... the problem with this way is I am building my xml file through DOM
    operations... and I haven't figured out how to add the schema line to the xml file through DOM manipulations.
    Has anyone done this bofore?
    try
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
         factory.setNamespaceAware(false);
         factory.setValidating(true);
         InputSource ipSource = new InputSource(new ByteArrayInputStream(bytesData));
         DocumentBuilder builder = factory.newDocumentBuilder();
         doc      = builder.parse(ipSource);
         return doc;
    catch(Throwable t)
         System.out.println("parse error: " +t);
    return doc;
    }

  • WHAT IS THE BEST WAY TO CREATE AN XSD FILE (TO BE USED BY SOAP ADAPTER)

    Dear friends
    I have a simple scenario.
    OUTBOUND DATA  -->  SOAP ADAPTER  --> ( XI )  -->  RFC ADAPTER  --> INBOUND DATA
    The XML file that I got from mapping area of IR (Design) is as follows
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:MT_NAME_SOURCE xmlns:ns0="http://test3.com">
       <FIRSTNAME>DAVE</FIRSTNAME>
       <LASTNAME>SMITH</LASTNAME>
    </ns0:MT_NAME_SOURCE>
    If you notice, there are only 2 fields.
    I need to create an XSD file and import it as an external object, which I can use for SOAP Adapter.
    Which is the best way to create it.
    Also, I need to know if there is any step by step of sending a message from XML SPY. I have downloaded this software, but am not able to undertand how to use this.
    Hope to hear from any experts on this forum.
    Thanks in advance
    Ram

    Hi Ram,
    See the below blog..
    It shows how to send SOAP message using XML Spy.
    It also shows how to generate wsdl.
    /people/siva.maranani/blog/2005/09/03/invoke-webservices-using-sapxi
    Regards,
    Sumit

  • What is the best way to save an ai file so it can be opened in corel draw

    I have an ai file that needs to be opened in corel draw by a client. It needs to remain editable all paths and colors ect.
    Whats the best way to save it so it can be.
    yes I know corel is not as good as Illustrator but its what they have.

    Moving files back and forth between Adobe Illustrator and CorelDRAW is tricky. There's quite a bit more to it than knowing what version of CorelDRAW the client is using. If the artwork is fairly simple then there shouldn't be any problem with transferring the artwork into CorelDRAW. If the artwork has gradients, transparency effects, a lot of clipping masks, etc. then it's going to be a lot more dicey getting it to import into CorelDRAW properly. In addition to the .AI file you provide, you should give the client a PDF they can view in Adobe Reader or Acrobat so they can proof how the artwork is really supposed to look.
    I use Adobe Illustrator CC and CorelDRAW X6 in my work. I've used both applications for over 20 years. I don't consider either application better than the other. They both have their own unique strengths and weaknesses. I'll do a good bit of creative work within CorelDRAW to use certain features Illustrator either lacks or just doesn't do as well. Or I may need to design a really big project at full scale and Corel has a much bigger art board than Illustrator. Most of the time I move a lot of the stuff I created in CorelDRAW over to Illustrator for further refinement or moving it into Photoshop as paths or smart objects or just getting it ready to print (I don't like Corel's color engine even though it has improved in recent years).
    Like others have said, you need to know the basics of what the user has -mainly which version of CorelDRAW. The newer versions like the one I'm using can open Illustrator CS5 files. For older versions, you may have to save down to CS2 or even really old versions like Illustrator 8.
    CorelDRAW will not support certain Illustrator-dependent effects. For instance, if you apply a gradient to an object outline it will be lost when opened in CorelDRAW. A lot of other effects won't be maintained when opened in Corel unless they are flattened/expanded. Some effects may even have to be rasterized, and that can create other issues. Out of effects that are maintained, some may have to be adjusted. CorelDRAW and Adobe Illustrator handle things like gradient fills differently and don't understand how to portray gradients from their rival application accurately. Some nice fill that was created in CorelDRAW may have to be tweaked or completely rebuilt when opened in Illustrator.
    I get a lot of customer files in CorelDRAW and also a lot in Illustrator. That reason alone makes it necessary for me to have both CorelDRAW and Adobe Illustrator running on my computer.

  • Best way to work with FCP files and Adobe Premiere

    Hi,
    I have a bit of a technical problem. I'm editing a doco for broadcast on TV and have shot on HDV and downloaded onto our system as PAL, Apple Pro Res 422, 25 fps. oowever, Our graphics editor is on Adobe Premiere CS4.
    What is the best way to get it onto her system and back off again and onto ours, with the mimimum or no loss of quality?
    I've heard that an XML might work, but will it work on Adobe CS4? I don't know how this will pan out if it's XML. Will we be able to open it all back up in FCP when she hands it back. What sort of file do we get back from the Adobe Prem Pro Cs4 system?
    I'm a bit nervous about it all.
    Hope you can help.
    Cheers,
    Margie

    This got me curious Eagleray as I do this all the time within my Mac FCS to CS all the time. But to a PC got me a googlin. Hope this discussion _http://www.animotion.nl/en/tutorials/fcp-xml-premiere-pro-cs5/_ helps as quite a few students seem to have Macs at school and PCs at home. Also do be aware of the different formatting of some PC drives like FAT16, FAT32, NTFS vs the Mac GUID. The Mac can read them all with the proper system addons/drivers, they show up in System Preferences Preference Panes under "OTHER". I use NTFS-3G to mount NTFS PC drives. I think it was free, if not there is another one I used to use that is free from some open source NTFS group. FAT has the size limit issue of I think 2 or 4gb (you can't copy anything bigger than that at one time to a Mac from a FAT drive). I'm on Snow Leopard on my 8core. My partner who edits in PP CS3 on a PC brought over his Maxtor USB the other day for me to copy some video files from and it's been having problems mounting, I believe since I upped to SL. I threw it on my 6 year old PowerBook G4 running 10.5.8 and it mounted right away. Just another weird gotcha. But take a quick look, tho the title says CS5 in it, a few students were using CS4 on a PC.
    Message was edited by: TimeKoder13
    Message was edited by: TimeKoder13

  • Best way to work with large file?

    Ok I have a huge file (200mb) that is all sequenes of numbers separate by commas. I wish to know if a specific sequence exists in this file. What is the best way of doing that check? I cant load the whole file into a StringBuffer since it is too large.

    Well, it's not necessarily too large. You might be able to load it all into memory at once.
    But you're right. It's not a good idea.
    What you can do is use a StreamTokenizer set to split on commas.
    Conceptually, you need to have a simple state machine that keeps track of how many consecutive numbers from that sequence you've read. As soon as you hit a number that's not the next one in the sequence, you reset to the beginning of the sequence.
    It's not hard to write it yourself, but there might be a simpler way--one of the IO classes or regex classes might have something for processing a stream that way.

  • What is the best way to read in a file?

    i'm currently doing it like this:
    Vector inVector = new Vector();
    try
    File file = new File( "C:/1jkiesel/testAgent/Customers.txt" );
    BufferedReader in = new BufferedReader( new FileReader( file ) );
    String str;
    while( ( str = in.readLine() ) != null )
    inVector.add( str );
    in.close();
    catch( IOException e )
    e.printStackTrace();
    is there a better way? especially th full file path thing...

    I did a search in the formums for
    "best practice read file"
    there were too many results so it was not very helpful
    I think that the best practice is to look at the "read" methods for
    each stream super class and decide which one is best for the particular
    application you have.
    I ask a follow up question:
    Is there a web page where we can find some comparisons of the various methods? Comparisons like speed, size, exception handling?
    hope this helps

  • What is the best way to reduce a .mov file size

    I had a music DVD that I converted to a .mov so that I could cut and paste in QT pro which i have done.
    Now I have a .mov file that is 46 gigabits in size and I want to reduce it considerably without ruining the quality of sound or visual.
    Whats the best way to do this.
    Thanks

    punt

  • What is the best way to integrate a sound file (mp3) into a PDF?

    I saw that its possible to do it by Tools->Multimedia->Sound. This works fine on a computer but not a tablet. So what is the right way to embed a sound file into a PDF of maybe by Indesign? What i want is that people can easily open a document (PDF) on a tablet and when they click on a (play)icon that they hear a sound file. The best thing is that they can stop or put it on pause.

    I think this functionality relies on Flash, so it's not likely it's going
    to work on mobile devices, certainly not on iOS ones.

Maybe you are looking for

  • Iphone to itunes sync fail during step 3

    HI I uprgraded my Iphone to the new ios 8 and now I cant sync it anymore. The fail occurs during step 3 when it is transferring purchased apps. The error text reads "The Iphone could not be synced because this computer is no longer authorized for pur

  • Problem with SQL to create a temp table to evaluate sort merge join

    Can anyone help me with the below sql to enable the performance of the use merge join to be evaluated. This sql is placed in a file and ran from the prompt. timing start CREATE table testsql as SELECT /*+ USE_MERGE(t1000 t8000)*/ t1000, t8000 FROM t1

  • SVG workflow is a joke

    Hey. Since Adobe does not provide any good tool for UI design (Photoshop is messy, Fireworks has its memory fatal bug and Illustrator is not pixel perfect with rounding errors wherever you look), I wanted to ask what you would suggest to design for w

  • How are the buttons reffered in JSP scriptlet

    hi all i am currently working with enabling and disabling of buttons at run time using functions in scriptlets which is refers document.form name.button id.disable=false; the error raised so far document.form name.button id is null or not valid

  • ASM with Oracle10 cannot see disks on Solaris

    Hi, I just installed Oracle10g on Solaris-64 and first thing I tried was to create database using ASM. Seems, ASM cannot find any disks though all 6 of them are available. I tried different ways, but there is no result so far. Any idea what am I doin