Class: Titlekit::Specification

Inherits:
Object
  • Object
show all
Defined in:
lib/titlekit/specification.rb

Direct Known Subclasses

Have, Want

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSpecification



7
8
9
10
11
12
13
14
15
16
# File 'lib/titlekit/specification.rb', line 7

def initialize
  @encoding = nil
  @file = nil
  @fps = nil
  @references = {}
  @subtitles = []
  @track = nil

  return self
end

Instance Attribute Details

#subtitlesObject

Only for internal usage by the job



5
6
7
# File 'lib/titlekit/specification.rb', line 5

def subtitles
  @subtitles
end

Instance Method Details

#encoding(*args) ⇒ Object

Specifies the encoding you have or want.



22
23
24
25
26
27
28
29
# File 'lib/titlekit/specification.rb', line 22

def encoding(*args)
  if args.empty?
    return @encoding
  else
    @encoding = args[0]
    return self
  end
end

#file(*args) ⇒ Object

Specifies the file (path) you have or want.



35
36
37
38
39
40
41
42
# File 'lib/titlekit/specification.rb', line 35

def file(*args)
  if args.empty?
    return @file
  else
    @file = args[0]
    return self
  end
end

#fps(*args) ⇒ Object

Specifies the framerate you have or want.



61
62
63
64
65
66
67
68
# File 'lib/titlekit/specification.rb', line 61

def fps(*args)
  if args.empty?
    return @fps
  else
    @fps = args[0]
    return self
  end
end

#reference(name, *args, hours: nil, minutes: nil, seconds: nil, milliseconds: nil, srt_timecode: nil, ssa_timecode: nil, ass_timecode: nil) ⇒ Object

Places a named reference (in the form of a string or a symbol) on a timecode specified by either hours, minutes, seconds or milliseconds.

Its typical use-case is to reference a specific subtitle you can recognize in both the movie and your subtitle file, where usually for the subtitle file (represented by Have) you will reference the subtitle index and for the movie (represented by Want) you will reference the timecode that is displayed when the line occurs in the movie.

Examples:

Referencing a timecode by hours

have.reference('Earl grey, hot', hours: 0.963)

Referencing a timecode by seconds

have.reference('In a galaxy ...', seconds: 14.2)

Referencing a timecode by an SRT-style timecode

have.reference('In a galaxy ...', srt_timecode: '00:00:14,200')

Referencing a timecode by an ASS-style timecode

have.reference('In a galaxy ...', ass_timecode: '0:00:14,20')

Referencing a timecode by an SSA-style timecode

have.reference('In a galaxy ...', ssa_timecode: '0:00:14,20')

Symbols can be used as references as well!

have.reference(:narrator_begins, minutes: 9.6)


109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/titlekit/specification.rb', line 109

def reference(name,
              *args,
              hours: nil,
              minutes: nil,
              seconds: nil,
              milliseconds: nil,
              srt_timecode: nil,
              ssa_timecode: nil,
              ass_timecode: nil)

  @references[name] = case
  when hours
    { timecode: hours * 3600 }
  when minutes
    { timecode: minutes * 60 }
  when seconds
    { timecode: seconds }
  when milliseconds
    { timecode: milliseconds / 1000 }
  when srt_timecode
    { timecode: Titlekit::SRT.parse_timecode(srt_timecode) }
  when ssa_timecode
    { timecode: Titlekit::SSA.parse_timecode(ssa_timecode) }
  when ass_timecode
    { timecode: Titlekit::ASS.parse_timecode(ass_timecode) }
  end

  return self
end

#referencesObject

Returns all named references you have specified



71
72
73
# File 'lib/titlekit/specification.rb', line 71

def references
  return @references
end

#track(*args) ⇒ Object

Specifies the track the subtitles should be assigned to.



48
49
50
51
52
53
54
55
# File 'lib/titlekit/specification.rb', line 48

def track(*args)
  if args.empty?
    return @track
  else
    @track = args[0]
    return self
  end
end