1 def load_story(self, movies_map, story_type='plot'):
2 """Load story files for given set of movies.
3
4 Args:
5 movies_map: Dictionary of movie named tuples.
6 story_type: 'plot', 'split_plot', 'subtitle', 'dvs', 'script'.
7
8 Returns:
9 story: Story for each movie indexed by imdb_key.
10
11 Raises:
12 ValueError: If input story type is not supported.
13 """
14 story = {}
15 for imdb_key, movie in movies_map.iteritems():
16 if story_type == 'plot':
17 if not movie.text.plot:
18 continue
19 plot_filename = os.path.join(PKG, movie.text.plot)
20 if not self._check_exists(plot_filename):
21 continue
22 this_story = self._read_plot(plot_filename)
23
24 elif story_type == 'split_plot':
25 fname = 'story/split_plot/' + imdb_key + '.split.wiki'
26 split_plot_filename = os.path.join(PKG, fname)
27 if not self._check_exists(split_plot_filename):
28 continue
29 this_story = self._read_plot(split_plot_filename)
30
31 elif story_type == 'subtitle':
32 if not movie.text.subtitle:
33 continue
34 subtitle_filename = os.path.join(PKG, movie.text.subtitle)
35 if not self._check_exists(subtitle_filename):
36 continue
37 this_story = self._read_subtitle(subtitle_filename)
38
39 elif story_type == 'dvs':
40 if not movie.text.dvs:
41 continue
42 dvs_filename = os.path.join(PKG, movie.text.dvs)
43 if not self._check_exists(dvs_filename):
44 continue
45 this_story = self._read_subtitle(dvs_filename)
46
47 elif story_type == 'script':
48 if not movie.text.script:
49 continue
50 script_filename = os.path.join(PKG, movie.text.script)
51 if not self._check_exists(script_filename):
52 continue
53 this_story = self._read_plot(script_filename)
54
55 else:
56 raise ValueError('Unsupported story type!')
57
58 story[imdb_key] = this_story
59
60 if not story:
61 raise ValueError('Story returned empty!')
62
63 return story