OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2011 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 import csv | 7 import csv |
8 import os | 8 import os |
9 import random | 9 import random |
10 | 10 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 csv.Error if the number of columns is not the same as the number of | 50 csv.Error if the number of columns is not the same as the number of |
51 tiles. | 51 tiles. |
52 """ | 52 """ |
53 # Clean up all data. | 53 # Clean up all data. |
54 self._exts = [] | 54 self._exts = [] |
55 self._specs = {} | 55 self._specs = {} |
56 self._video_titles = [] | 56 self._video_titles = [] |
57 self._tags = {} | 57 self._tags = {} |
58 file = open(csv_file, 'rb') | 58 file = open(csv_file, 'rb') |
59 reader = csv.reader(file) | 59 reader = csv.reader(file) |
60 for counter, row in enumerate(reader): | 60 for row_counter, row in enumerate(reader): |
61 if counter == 0: | 61 if row_counter == 0: |
62 # First row is comment. So, skip it. | 62 # First row is comment. So, skip it. |
63 pass | 63 pass |
64 elif counter == 1: | 64 elif row_counter == 1: |
65 # Second row is for header (video titles). | 65 # Second row is for header (video titles). |
66 for title in row[1:]: | 66 for column_counter, title in enumerate(row[1:]): |
67 self._video_titles.append(title) | 67 # Skip the first column since it is for tag ('video' or 'audio'). |
| 68 if column_counter > 0: |
| 69 self._video_titles.append(title) |
68 self._specs[title] = [] | 70 self._specs[title] = [] |
69 else: | 71 else: |
70 # Error checking is done here based on the number of titles | 72 # Error checking is done here based on the number of titles |
71 if len(self._video_titles) != len(row) - 1: | 73 if len(self._video_titles) != len(row) - 2: |
72 print "Row %d should have %d columns but has %d columns" % (counter, | 74 print "Row %d should have %d columns but has %d columns" % ( |
73 len(self._video_titles), len(row)) | 75 row_counter, len(self._video_titles), len(row)) |
74 raise csv.Error | 76 raise csv.Error |
75 # First column should contain extension. | 77 # First column should contain extension. |
76 self._exts.append(row[0]) | 78 self._exts.append(row[0]) |
77 # Second column should contain tag (audio or video). | 79 # Second column should contain tag (audio or video). |
78 self._tags[row[0]] = row[1] | 80 self._tags[row[0]] = row[1] |
79 for i in range(len(row) - 2): | 81 for i in range(len(row) - 2): |
80 self._specs[self._video_titles[i]].append(row[i + 2]) | 82 self._specs[self._video_titles[i]].append(row[i + 2]) |
81 file.close() | 83 file.close() |
82 | 84 |
83 def _GenerateMediaInfo(self, sub_type, name, media_test_matrix_home_url): | 85 def _GenerateMediaInfo(self, sub_type, name, media_test_matrix_home_url): |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 """ | 192 """ |
191 media_infos = [] | 193 media_infos = [] |
192 for i in range(0, len(self._video_titles)-1): | 194 for i in range(0, len(self._video_titles)-1): |
193 name = self._video_titles[i] | 195 name = self._video_titles[i] |
194 for sub_type in range(len(self._exts)): | 196 for sub_type in range(len(self._exts)): |
195 (info, url, link, tag, is_video, nickname) = ( | 197 (info, url, link, tag, is_video, nickname) = ( |
196 self._GenerateMediaInfo(sub_type, name, media_matrix_home_url)) | 198 self._GenerateMediaInfo(sub_type, name, media_matrix_home_url)) |
197 tag = ['audio', 'video'][is_video] | 199 tag = ['audio', 'video'][is_video] |
198 if ((not NOT_AVAILABLE_STRING in info) and | 200 if ((not NOT_AVAILABLE_STRING in info) and |
199 ((not video_only) or (video_only and is_video))): | 201 ((not video_only) or (video_only and is_video))): |
200 media_infos.append([url, nickname, tag]) | 202 media_infos.append([tag, url, nickname]) |
201 return media_infos | 203 return media_infos |
202 | 204 |
203 @staticmethod | 205 @staticmethod |
204 def LookForMediaInfoInCompactFormByNickName(compact_list, target): | 206 def LookForMediaInfoInCompactFormByNickName(compact_list, target): |
205 """Look for video by its nickname in the compact_list. | 207 """Look for video by its nickname in the compact_list. |
206 | 208 |
207 Args: | 209 Args: |
208 compact_list: a list generated by GenerateAllMediaInfosInCompactForm. | 210 compact_list: a list generated by GenerateAllMediaInfosInCompactForm. |
209 target: a target nickname string to look for. | 211 target: a target nickname string to look for. |
210 | 212 |
211 Returns: | 213 Returns: |
212 A tuple (url, nickname, tag) where nickname is a target string. | 214 A tuple (url, nickname, tag) where nickname is a target string. |
213 url: URL of the video/audio. | 215 url: URL of the video/audio. |
214 nickname: nickname of the video/audio for presentation | 216 nickname: nickname of the video/audio for presentation |
215 (such as bear.webm). | 217 (such as bear.webm). |
216 tag: HTML5 tag for the video/audio. | 218 tag: HTML5 tag for the video/audio. |
217 """ | 219 """ |
218 for url, nickname, tag in compact_list: | 220 for tag, url, nickname in compact_list: |
219 if target == nickname: | 221 if target == nickname: |
220 return (tag, url, nickname) | 222 return (tag, url, nickname) |
OLD | NEW |