Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
srt2ass [Le 06/06/2012, 15:27] Crazyfaboo Gestion italique à présent en {\i1}{\i0} |
srt2ass [Le 06/09/2012, 12:11] (Version actuelle) Crazyfaboo Amélioration du script, correction de bugs, liste d'exclusions. |
||
---|---|---|---|
Ligne 48: | Ligne 48: | ||
import codecs | import codecs | ||
import argparse | import argparse | ||
- | import os, glob | + | import sys, os, glob |
+ | |||
+ | # Use this list to delete automatically subs containing one of the following words. All in lower case. | ||
+ | exclusion = ["subtitles by", "sync by", "<font", "synchro:", "sync:", "transcript:", "subtitles:", "subtitle:", "sync and corrections"] | ||
class Console: | class Console: | ||
Ligne 54: | Ligne 57: | ||
| | ||
@classmethod | @classmethod | ||
- | def l(c, message): | + | def l(c, message, linefeed = True): |
- | print message | + | sys.stdout.write(message) |
+ | if linefeed: | ||
+ | sys.stdout.write("\n") | ||
| | ||
@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("## Warning ## " + message) | + | c.v("## Warning ## " + message, linefeed) |
+ | |||
+ | @classmethod | ||
+ | def nl(c): | ||
+ | if c.verbose: | ||
+ | sys.stdout.write("\n") | ||
class SubElement: | class SubElement: | ||
Ligne 107: | Ligne 117: | ||
font = "Regular" | font = "Regular" | ||
| | ||
- | text = text.replace("<i>", "{\i1}").replace("</i>", "{\i0}") | + | text = text.replace("<i>", "{\\i1}").replace("</i>", "{\\i0}") |
+ | # Fixes the subtitle | ||
+ | if text.find("{\\i1}") != -1 and text.find("{\\i0}") == -1: | ||
+ | text += "{\\i0}" | ||
| | ||
return "Dialogue: 0,{0},{1},{2},,0000,0000,0000,,{3}\n".format(start, end, font, text) | return "Dialogue: 0,{0},{1},{2},,0000,0000,0000,,{3}\n".format(start, end, font, text) | ||
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('utf-8') \ | l = line.encode('utf-8') \ | ||
Ligne 202: | Ligne 216: | ||
.replace("\r", "") | .replace("\r", "") | ||
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("Reading SRT # " + l + "\r") | + | Console.v("Reading SRT #" + str(l) + "\r", False) |
if int(l) != count: | if int(l) != count: | ||
- | Console.w("Bad SRT number! Found: #" + l + ", but should be #" + count) | + | Console.nl() |
+ | Console.w("Bad SRT number! Found: #" + str(l) + ", but should be #" + str(count)) | ||
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("", "œ") \ | + | if not skip: |
- | .replace("", "’") \ | + | skip = self.exclude(l) |
- | .replace("", "“") \ | + | if skip: |
- | .replace("", "”") \ | + | Console.nl() |
- | .replace("", "€") \ | + | Console.w("Skipping SRT '" + l + "'") |
- | .replace("´´", '"') \ | + | elif len(l) > 0: |
- | .replace("´", "'") \ | + | l = l.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, line): | def applyLanguageOnLine(self, line): | ||
return line | return line | ||
+ | | ||
+ | def exclude(self, line): | ||
+ | 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, args.font_regular, args.font_size, args.delete) | Srt2Ass(srt, args.font_regular, args.font_size, args.delete) | ||
+ | |||
</file> | </file> | ||
<note>Les erreurs d'encodage du fichier SRT ne sont pas gérées par ce script. En cas de problème de conversion, ouvrez le fichier SRT avec Subtitle Editor et faites Enregistrer. La conversion fonctionnera alors parfaitement.</note> | <note>Les erreurs d'encodage du fichier SRT ne sont pas gérées par ce script. En cas de problème de conversion, ouvrez le fichier SRT avec Subtitle Editor et faites Enregistrer. La conversion fonctionnera alors parfaitement.</note> |