-3

I have a .mov file that displays a bunch of information when edited in a text editor. I'd like to create a program that extracts information and creates a .txt file so I can run it each month when I get a new .mov file.

Here is what the information looks like in the .mov file...

[Categories]
1   hollywoodhd 1295    1295    Movies  1
2   mega    1095    1095    Movies  1
3   still   1095    1095    Movies  1
4   special 895 895 Movies  1
5   family  1095    1095    Movies  1

[Titles]
  hollywoodhd1 1 0 8046 0 919 PG-13 6712 1 identity_hd "(HD) Identity Thief" Disk 0 04/15/13 11/01/13 0 0 0 0 0 0 1 1 0 16000000 H3 16:9 0 0
  hollywoodhd2 3 0 8016 0 930 PG 5347 1 escapep_hd "(HD) Escape from Planet Earth" Disk 0 04/01/13 10/01/13 0 0 0 0 0 0 1 1 0 16000000 H3 16:9 0 0
  hollywoodhd3 1 0 8012 0 930 PG-13 5828 1 darkski_hd "(HD) Dark Skies" Disk 0 04/01/13 10/01/13 0 0 0 0 0 0 1 1 0 16000000 H3 16:9 0 0
  hollywoodhd3 2 0 8007 0 928 PG-13 5735 1 guilttri_hd "(HD) The Guilt Trip" Disk 0 04/01/13 10/01/13 0 0 0 0 0 0 1 1 0 16000000 H3 16:9 0 0
  hollywoodhd3 3 0 8013 0 928 PG-13 7813 1 jackreac_hd "(HD) Jack Reacher" Disk 0 04/01/13 10/01/13 0 0 0 0 0 0 1 1 0 16000000 H3 16:9 0 0
  hollywoodhd4 1 0 7993 0 919 PG-13 9500 1 lesmiser_hd "(HD) Les Miserables" Disk 0 03/06/13 09/01/13 0 0 0 0 0 0 1 1 0 16000000 H3 16:9 0 0

After [Titles], I only need the name of the movie and the rating to be placed in a text file. If possible, I'd like to prompt the user to choose which file to read from, so anyone can type the name or path of the file if someone else runs the program.

I was planning on using c++. The point is to have it automated so I can run the program each month and just pull out the movie title and rating, rather than copying and pasting it into word and deleting all the other stuff.

4

2 回答 2

0

In Python (and not the "right" way to do it) but generic enough:

dict = {} # Movie titles and ratings

# open up the .mov file, check for tell-tale patterns and pair them up
with open('yourfilehere.mov', 'r') as infile:
    for line in infile.readlines():
        for word in line.split():
            if word in ['G', 'PG', 'PG-13', 'R', 'X']:
                hold = word
            elif word[0] == '"' and word[-1] == '"':
                dict[word[1:-1]] = hold

# write the pairings into a new file, separated by a tab                
with open('output.txt', 'w') as outfile:
    for key in dict.keys():
        outfile.write(key + "\t" + dict[key] + "\n")

Hopefully this is enough to point you in the right direction with your own code. Consider looking for a library meant for handling .mov metadata, or at least finding a good resource on how .mov files are structured.

于 2013-05-25T00:24:01.863 回答
0

I will give you some pseudo code on how to parse that file:

void Read(stringFileName)
{
     //very self explanatory
}

int FindStr(stringToFind, stringToSearchWith, charDelimeter)
{

    //process
    return indexOfDelimeter;
}

    //stringToFind          - what data in the text are you looking for
    //stringToSearchWith    - in what text should I look for this(assuming you stored the .txt file into a string
    //charDelimeter         - whats the next character after finding the stringToFind.
    //                      - this is important so that you can know whats the corresponding data in that string e.g myFavNum 10000000e-210
    //the delimeter is a `space`

int ConvertToInt(stringToSearchWith, index)
{
    //process
    return toInt;
}

    //stringToSearchWith - assuming that this is only a line in your .txt file,
    //                   - this is where you want to convert string into int
    //index              - where is the data in the string?

Summary:

  1. Read

  2. Find

  3. Convert

于 2013-05-25T00:45:03.903 回答