VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsTitleSubsInfo"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
' -------------------------------------------------------------------------------
'
'   AVStoDVD - by MrC
'   File: clsTitleSubsInfo.cls
'   Purpose: Class that handle Subs Title Info properties
'   Requires: clsMediaInfo.cls
'
' -------------------------------------------------------------------------------


Option Explicit
Option Compare Binary
Option Base 0


Private SubsID As String
Private SubsStreamOrder As String           'for Subs Demuxing: FFmpeg and MKVexctract use different tracks numbering
Private SubsFormat As String
Private SubsLanguage As String
Private SubsTitle As String
Private SubsLinesNum As String

Public Function Initialize(SourceMediaInfo As clsMediaInfo, Optional TextTrack As Integer) As Boolean

    Dim aStream
        
    With SourceMediaInfo
        SubsID = .TextID(TextTrack)
        If Val(.VideoTracksCount) = 0 Then
            SubsStreamOrder = "0"
        Else
            If IsNumeric(.TextStreamOrder(TextTrack)) = True Then
                SubsStreamOrder = .TextStreamOrder(TextTrack)
            ElseIf InStr(1, .TextStreamOrder(TextTrack), "-") <> 0 Then
                aStream = Split(.TextStreamOrder(TextTrack), "-")
                If IsNumeric(aStream(UBound(aStream))) = True Then
                    SubsStreamOrder = aStream(UBound(aStream))
                End If
            End If
        End If
        SubsFormat = .TextFormat(TextTrack)
        SubsTitle = .TextTitle(TextTrack)
        SubsLanguage = .TextLanguage(TextTrack)
        SubsLinesNum = ""          ' MediaInfo cannot detect subs lines number, need parsing
    End With
    Initialize = CBool(Len(SubsFormat))

End Function

Public Property Get ID() As String

    'Dim aID
    
    'aID = Split(SubsID, "-")
    'If UBound(aID) > 0 Then
    '    ID = aID(UBound(aID))
    'Else
        ID = SubsID
    'End If

End Property
    
Public Property Let ID(value As String)

    SubsID = value
    
End Property

Public Property Get StreamOrder() As String

    StreamOrder = SubsStreamOrder

End Property
    
Public Property Let StreamOrder(value As String)

    SubsStreamOrder = value
    
End Property

Public Property Get Format() As String

    Select Case UCase(SubsFormat)
    Case "VOBSUB"
        Format = "VobSub"
    Case "UTF-8"
        Format = "SubRip"
    Case "SSA"
        Format = "SubStation Alpha"
    Case "ASS"
        Format = "Advance7d SubStation"
    Case "SUP"
        Format = "IfoEdit"
    Case "SST"
        Format = "Scenarist"
    Case "SUB"
        Format = "MicroDVD"
    Case Else
        Format = SubsFormat
    End Select

End Property
    
Public Property Let Format(value As String)

    Select Case UCase(value)
    Case "VOBSUB"
        SubsFormat = "VobSub"
    Case "SUBRIP"
        SubsFormat = "UTF-8"
    Case "SUBSTATION ALPHA"
        SubsFormat = "SSA"
    Case "ADVANCED SUBSTATION"
        SubsFormat = "ASS"
    Case "IFOEDIT"
        SubsFormat = "SUP"
    Case "SCENARIST"
        SubsFormat = "SST"
    Case "MICRODVD"
        SubsFormat = "SUB"
    Case Else
        SubsFormat = value
    End Select
    
End Property

Public Property Get Title() As String

    Title = SubsTitle

End Property
    
Public Property Let Title(value As String)

    SubsTitle = value
    
End Property

Public Property Get LinesNum() As String

    LinesNum = SubsLinesNum

End Property
    
Public Property Let LinesNum(value As String)

    SubsLinesNum = value
    
End Property

Public Property Get Language() As String

    Language = SubsLanguage

End Property
    
Public Property Let Language(value As String)

    SubsLanguage = value
    
End Property

Public Property Get LanguageCode() As String

    If Len(SubsLanguage) >= 2 Then
        LanguageCode = UCase(Left(SubsLanguage, 2))
    End If

End Property
    
Public Property Get Summary() As String

    If SubsFormat <> "" Then
        Summary = Format & " (" & UCase(Extension) & ")" & _
                  IIf(SubsTitle = "", "", " - " & SubsTitle) & _
                  IIf(LanguageCode = "", "", " - " & LanguageCode)
    End If

End Property

Public Property Get SummaryLong() As String

    If SubsFormat <> "" Then
        If SubsID <> "" Then
            SummaryLong = "Track ID: " & SubsID & vbCrLf & _
                          "Stream Order: " & SubsStreamOrder & vbCrLf
        End If
        SummaryLong = SummaryLong & _
                      "Format: " & Format & " (" & UCase(Extension) & ")" & vbCrLf & _
                      "Title: " & SubsTitle & vbCrLf & _
                      "Language: " & SubsLanguage & vbCrLf & _
                      "Lines #: " & SubsLinesNum
    End If

End Property

Public Property Get Extension() As String

    Select Case UCase(SubsFormat)
    Case "VOBSUB"
        Extension = "idx"
    Case "UTF-8", "SUBRIP"
        Extension = "srt"
    Case Else                                           'i.e. ASS, SSA
        Extension = LCase(SubsFormat)
    End Select

End Function

