Merge pull request #116 from esha71/master
Fixed timestamp formatting in WebVTTFormatter
This commit is contained in:
		
						commit
						f30e344f99
					
				|  | @ -5,9 +5,9 @@ import pprint | ||||||
| 
 | 
 | ||||||
| class Formatter(object): | class Formatter(object): | ||||||
|     """Formatter should be used as an abstract base class. |     """Formatter should be used as an abstract base class. | ||||||
|      | 
 | ||||||
|     Formatter classes should inherit from this class and implement |     Formatter classes should inherit from this class and implement | ||||||
|     their own .format() method which should return a string. A  |     their own .format() method which should return a string. A | ||||||
|     transcript is represented by a List of Dictionary items. |     transcript is represented by a List of Dictionary items. | ||||||
|     """ |     """ | ||||||
| 
 | 
 | ||||||
|  | @ -95,14 +95,11 @@ class WebVTTFormatter(Formatter): | ||||||
|         '00:00:06.930' |         '00:00:06.930' | ||||||
|         """ |         """ | ||||||
|         time = float(time) |         time = float(time) | ||||||
|         hours, mins, secs = ( |         hours, remainder = divmod(time, 3600) | ||||||
|             int(time) // 3600, |         mins, secs = divmod(remainder, 60) | ||||||
|             int(time) // 60, |  | ||||||
|             int(time) % 60, |  | ||||||
|         ) |  | ||||||
|         ms = int(round((time - int(time))*1000, 2)) |         ms = int(round((time - int(time))*1000, 2)) | ||||||
|         return "{:02d}:{:02d}:{:02d}.{:03d}".format(hours, mins, secs, ms) |         return "{:02.0f}:{:02.0f}:{:02.0f}.{:03d}".format(hours, mins, secs, ms) | ||||||
|      | 
 | ||||||
|     def format_transcript(self, transcript, **kwargs): |     def format_transcript(self, transcript, **kwargs): | ||||||
|         """A basic implementation of WEBVTT formatting. |         """A basic implementation of WEBVTT formatting. | ||||||
| 
 | 
 | ||||||
|  | @ -126,7 +123,7 @@ class WebVTTFormatter(Formatter): | ||||||
|                     self._seconds_to_timestamp(duration) |                     self._seconds_to_timestamp(duration) | ||||||
|                 ) |                 ) | ||||||
|             lines.append("{}\n{}".format(time_text, line['text'])) |             lines.append("{}\n{}".format(time_text, line['text'])) | ||||||
|          | 
 | ||||||
|         return "WEBVTT\n\n" + "\n\n".join(lines) + "\n" |         return "WEBVTT\n\n" + "\n\n".join(lines) + "\n" | ||||||
| 
 | 
 | ||||||
|     def format_transcripts(self, transcripts, **kwargs): |     def format_transcripts(self, transcripts, **kwargs): | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue