You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.3 KiB
44 lines
1.3 KiB
6 years ago
|
# coding=utf-8
|
||
|
|
||
5 years ago
|
from __future__ import absolute_import
|
||
6 years ago
|
import logging
|
||
|
|
||
|
from subzero.modification.mods import SubtitleModification
|
||
|
from subzero.modification import registry
|
||
5 years ago
|
import six
|
||
6 years ago
|
|
||
|
logger = logging.getLogger(__name__)
|
||
|
|
||
|
|
||
|
class ShiftOffset(SubtitleModification):
|
||
|
identifier = "shift_offset"
|
||
|
description = "Change the timing of the subtitle"
|
||
|
exclusive = False
|
||
|
advanced = True
|
||
|
args_mergeable = True
|
||
|
modifies_whole_file = True
|
||
|
|
||
|
long_description = "Adds or substracts a certain amount of time from the whole subtitle to match your media"
|
||
|
|
||
|
@classmethod
|
||
|
def merge_args(cls, args1, args2):
|
||
5 years ago
|
new_args = dict((key, int(value)) for key, value in six.iteritems(args1))
|
||
6 years ago
|
|
||
5 years ago
|
for key, value in six.iteritems(args2):
|
||
6 years ago
|
if not int(value):
|
||
|
continue
|
||
|
|
||
|
if key in new_args:
|
||
|
new_args[key] += int(value)
|
||
|
else:
|
||
|
new_args[key] = int(value)
|
||
|
|
||
5 years ago
|
return dict([k_v for k_v in six.iteritems(new_args) if bool(k_v[1])])
|
||
6 years ago
|
|
||
|
def modify(self, content, debug=False, parent=None, **kwargs):
|
||
|
parent.f.shift(h=int(kwargs.get("h", 0)), m=int(kwargs.get("m", 0)), s=int(kwargs.get("s", 0)),
|
||
|
ms=int(kwargs.get("ms", 0)))
|
||
|
|
||
|
|
||
|
registry.register(ShiftOffset)
|