Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédente | |||
| srt2ass [Le 06/06/2012, 15:27] – Gestion italique à présent en {\i1}{\i0} Crazyfaboo | srt2ass [Le 06/09/2012, 12:11] (Version actuelle) – Amélioration du script, correction de bugs, liste d'exclusions. Crazyfaboo | ||
|---|---|---|---|
| Ligne 48: | Ligne 48: | ||
| import codecs | import codecs | ||
| import argparse | import argparse | ||
| - | import os, glob | + | import |
| + | |||
| + | # Use this list to delete automatically subs containing one of the following words. All in lower case. | ||
| + | exclusion = [" | ||
| class Console: | class Console: | ||
| Ligne 54: | Ligne 57: | ||
| | | ||
| @classmethod | @classmethod | ||
| - | def l(c, message): | + | def l(c, message, linefeed = True): |
| - | | + | |
| + | if linefeed: | ||
| + | sys.stdout.write(" | ||
| | | ||
| @classmethod | @classmethod | ||
| - | def v(c, message): | + | def v(c, message, linefeed = True): |
| if c.verbose: | if c.verbose: | ||
| - | c.l(message) | + | c.l(message, linefeed) |
| | | ||
| @classmethod | @classmethod | ||
| - | def w(c, message): | + | def w(c, message, linefeed = True): |
| - | c.v("## | + | c.v("## |
| + | |||
| + | @classmethod | ||
| + | def nl(c): | ||
| + | if c.verbose: | ||
| + | sys.stdout.write(" | ||
| class SubElement: | class SubElement: | ||
| Ligne 107: | Ligne 117: | ||
| font = " | font = " | ||
| | | ||
| - | text = text.replace("< | + | text = text.replace("< |
| + | # Fixes the subtitle | ||
| + | if text.find(" | ||
| + | text += " | ||
| | | ||
| return " | return " | ||
| Ligne 197: | Ligne 210: | ||
| count = 0 | count = 0 | ||
| emptySub = [] | emptySub = [] | ||
| + | skip = False | ||
| for line in self.lines: | for line in self.lines: | ||
| l = line.encode(' | l = line.encode(' | ||
| Ligne 202: | Ligne 216: | ||
| .replace(" | .replace(" | ||
| if isJustNew: | if isJustNew: | ||
| + | skip = False | ||
| isJustNew = False | isJustNew = False | ||
| nextCountReady = False | nextCountReady = False | ||
| Ligne 209: | Ligne 224: | ||
| elif nextCountReady and l.isdigit(): | elif nextCountReady and l.isdigit(): | ||
| count += 1 | count += 1 | ||
| - | Console.v(" | + | Console.v(" |
| if int(l) != count: | if int(l) != count: | ||
| - | Console.w(" | + | |
| + | | ||
| if el != None: | if el != None: | ||
| if el.text == '': | if el.text == '': | ||
| Ligne 220: | Ligne 236: | ||
| isJustNew = True | isJustNew = True | ||
| else: | else: | ||
| - | l = l.replace(" | + | |
| - | .replace(" | + | skip = self.exclude(l) |
| - | .replace(" | + | if skip: |
| - | .replace(" | + | Console.nl() |
| - | .replace(" | + | Console.w(" |
| - | .replace(" | + | elif len(l) > 0: |
| - | .replace(" | + | |
| - | .replace(" | + | .replace(" |
| - | .replace(" | + | .replace(" |
| - | .replace(" | + | .replace(" |
| - | l = self.applyLanguageOnLine(l) | + | .replace(" |
| - | el.appendLine(l) | + | .replace(" |
| + | .replace(" | ||
| + | .replace(" | ||
| + | .replace(" | ||
| + | .replace(" | ||
| + | l = self.applyLanguageOnLine(l) | ||
| + | el.appendLine(l) | ||
| nextCountReady = True | nextCountReady = True | ||
| | | ||
| - | if (el != None): | + | if el != None and len(str(el)) > 0: |
| self.elements.append(el) | self.elements.append(el) | ||
| | | ||
| Ligne 251: | Ligne 273: | ||
| def applyLanguageOnLine(self, | def applyLanguageOnLine(self, | ||
| return line | return line | ||
| + | | ||
| + | def exclude(self, | ||
| + | l = line.lower() | ||
| + | for x in exclusion: | ||
| + | if l.find(x) != -1: | ||
| + | return True | ||
| + | return False | ||
| class Srt2Ass: | class Srt2Ass: | ||
| Ligne 286: | Ligne 315: | ||
| for srt in srtfiles: | for srt in srtfiles: | ||
| Srt2Ass(srt, | Srt2Ass(srt, | ||
| + | |||
| </ | </ | ||
| < | < | ||
