Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| srt2ass [Le 15/12/2011, 15:22] – modification externe 127.0.0.1 | srt2ass [Le 06/09/2012, 12:11] (Version actuelle) – Amélioration du script, correction de bugs, liste d'exclusions. Crazyfaboo | ||
|---|---|---|---|
| Ligne 27: | Ligne 27: | ||
| </ | </ | ||
| + | < | ||
| ====== Conversion en ligne de commande ====== | ====== Conversion en ligne de commande ====== | ||
| Ligne 47: | 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 53: | 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 84: | Ligne 95: | ||
| class AdvancedSubStationAlphaWriter: | class AdvancedSubStationAlphaWriter: | ||
| | | ||
| - | def __init__(self, | + | def __init__(self, |
| Console.v(' | Console.v(' | ||
| self.fontRegular = regular | self.fontRegular = regular | ||
| - | self.fontItalic = italic | ||
| self.fontSize = size | self.fontSize = size | ||
| self.filename = filename | self.filename = filename | ||
| Ligne 107: | Ligne 117: | ||
| font = " | font = " | ||
| | | ||
| - | | + | text = text.replace("< |
| - | if isItalic: | + | # Fixes the subtitle |
| - | font = " | + | if text.find(" |
| - | | + | text += " |
| | | ||
| return " | return " | ||
| Ligne 132: | Ligne 142: | ||
| + " | + " | ||
| + " | + " | ||
| - | + " | ||
| + " | + " | ||
| + " | + " | ||
| + " | + " | ||
| + | |||
| + | #+ " | ||
| + | | ||
| class SubRipReader: | class SubRipReader: | ||
| Ligne 198: | 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 203: | Ligne 216: | ||
| .replace(" | .replace(" | ||
| if isJustNew: | if isJustNew: | ||
| + | skip = False | ||
| isJustNew = False | isJustNew = False | ||
| nextCountReady = False | nextCountReady = False | ||
| Ligne 210: | 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 221: | 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(" |
| - | l = self.applyLanguageOnLine(l) | + | .replace(" |
| - | el.appendLine(l) | + | |
| + | | ||
| + | .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: | ||
| | | ||
| - | def __init__(self, | + | def __init__(self, |
| ass = srt.replace(' | ass = srt.replace(' | ||
| subs = SubRipReader(srt) | subs = SubRipReader(srt) | ||
| - | AdvancedSubStationAlphaWriter(ass, | + | AdvancedSubStationAlphaWriter(ass, |
| if delete: | if delete: | ||
| Console.l(" | Console.l(" | ||
| Ligne 267: | Ligne 296: | ||
| parser.add_argument(' | parser.add_argument(' | ||
| parser.add_argument(' | parser.add_argument(' | ||
| - | parser.add_argument(' | ||
| parser.add_argument(' | parser.add_argument(' | ||
| parser.add_argument(' | parser.add_argument(' | ||
| Ligne 286: | Ligne 314: | ||
| | | ||
| for srt in srtfiles: | for srt in srtfiles: | ||
| - | Srt2Ass(srt, | + | Srt2Ass(srt, |
| </ | </ | ||
| + | < | ||
