1# coding=utf-8 2 3from __future__ import absolute_import 4import logging 5from collections import OrderedDict 6 7from subzero.modification.mods import SubtitleModification 8from subzero.modification import registry 9 10logger = logging.getLogger(__name__) 11 12 13COLOR_MAP = OrderedDict([ 14 ("white", "#FFFFFF"), 15 ("light-grey", "#C0C0C0"), 16 ("red", "#FF0000"), 17 ("green", "#00FF00"), 18 ("yellow", "#FFFF00"), 19 ("blue", "#0000FF"), 20 ("magenta", "#FF00FF"), 21 ("cyan", "#00FFFF"), 22 ("black", "#000000"), 23 ("dark-red", "#800000"), 24 ("dark-green", "#008000"), 25 ("dark-yellow", "#808000"), 26 ("dark-blue", "#000080"), 27 ("dark-magenta", "#800080"), 28 ("dark-cyan", "#008080"), 29 ("dark-grey", "#808080"), 30]) 31 32 33class Color(SubtitleModification): 34 identifier = "color" 35 description = "Change the color of the subtitle" 36 exclusive = True 37 advanced = True 38 modifies_whole_file = True 39 apply_last = True 40 41 colors = COLOR_MAP 42 43 long_description = "Adds the requested color to every line of the subtitle. Support depends on player." 44 45 def modify(self, content, debug=False, parent=None, **kwargs): 46 color = self.colors.get(kwargs.get("name")) 47 if color: 48 for entry in parent.f: 49 entry.text = u'<font color="%s">%s</font>' % (color, entry.text) 50 51 52registry.register(Color) 53