-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDVRMSItem.vb
484 lines (440 loc) · 13.7 KB
/
DVRMSItem.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
#Region "Import Declaratives"
Imports System
Imports Toub.MediaCenter.Dvrms.Metadata
#End Region
Public Class DVRMSItem
Implements IDisposable
#Region "Private Variables"
Private _filename As String
Private _meta As IDictionary = Nothing
Private _IsDirty As Boolean = False
Private _Genre As New List(Of String)
Private _Credits As New List(Of String)
Private _Actors As New List(Of String)
Private _Directors As New List(Of String)
Private _Other As New List(Of String)
Private _Crew As New List(Of String)
#End Region
''' <summary>
'''
''' </summary>
''' <param name="filename"></param>
''' <remarks></remarks>
Public Sub New(ByVal filename As String)
_filename = filename
Using _editor As New DvrmsMetadataEditor(filename)
_meta = _editor.GetAttributes
End Using
Dim genre As String = Genres
If Not String.IsNullOrEmpty(genre) Then _Genre.AddRange(genre.Split(","))
Dim cast As String = Credits + ";;;;"
_Credits.AddRange(cast.Split(";"c))
If _Credits.Count > 4 Then _Credits.RemoveRange(4, _Credits.Count - 4)
If Not String.IsNullOrEmpty(_Credits(0)) Then _Actors.AddRange(_Credits(0).Split("/"c))
If Not String.IsNullOrEmpty(_Credits(1)) Then _Directors.AddRange(_Credits(1).Split("/"c))
If Not String.IsNullOrEmpty(_Credits(2)) Then _Other.AddRange(_Credits(2).Split("/"c))
If Not String.IsNullOrEmpty(_Credits(3)) Then _Crew.AddRange(_Credits(3).Split("/"c))
End Sub
''' <summary>
'''
''' </summary>
''' <returns></returns>
''' <remarks></remarks>
Public Overrides Function ToString() As String
Return IO.Path.GetFileNameWithoutExtension(_filename)
End Function
''' <summary>
'''
''' </summary>
''' <remarks></remarks>
Public Sub Save()
If _IsDirty Then
Try
Using _editor As New DvrmsMetadataEditor(filename)
_editor.SetAttributes(_meta)
End Using
_IsDirty = False
Catch ex As Exception
End Try
End If
End Sub
#Region "Properties"
''' <summary>
'''
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property IsDirty() As Boolean
Get
Return _IsDirty
End Get
Set(ByVal value As Boolean)
_IsDirty = value
End Set
End Property
''' <summary>
'''
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property filename() As String
Get
Return _filename
End Get
Set(ByVal value As String)
_filename = value
End Set
End Property
''' <summary>
'''
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property IsMovie() As Boolean
Get
Return GetMetaData("WM/MediaIsMovie")
End Get
Set(ByVal value As Boolean)
SetMetaData("WM/MediaIsMovie", value, MetadataItemType.Boolean)
End Set
End Property
''' <summary>
'''
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property ReleaseDate() As DateTime
Get
Dim dt As DateTime, sDT As String = GetMetaData(DvrmsMetadataEditor.MediaOriginalBroadcastDateTime)
If DateTime.TryParse(sDT, dt) Then
Return dt
Else
Return DateTime.MinValue
End If
End Get
Set(ByVal value As DateTime)
Dim sDT As String = value.ToString("yyyy-MM-ddThh:mm:ssZ")
SetMetaData(DvrmsMetadataEditor.MediaOriginalBroadcastDateTime, sDT, MetadataItemType.String)
End Set
End Property
''' <summary>
'''
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property RunningTime() As Integer
Get
Dim runtime As Long = GetMetaData(DvrmsMetadataEditor.Duration)
runtime = CLng(runtime / (60 * 10000000))
Return runtime
End Get
Set(ByVal value As Integer)
Dim runtime As Long = value
runtime = runtime * 60 * 10000000
SetMetaData(DvrmsMetadataEditor.Duration, runtime, MetadataItemType.Qword)
End Set
End Property
''' <summary>
'''
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property Station() As String
Get
Return GetMetaData(DvrmsMetadataEditor.StationName)
End Get
Set(ByVal value As String)
SetMetaData(DvrmsMetadataEditor.StationName, value, MetadataItemType.String)
End Set
End Property
''' <summary>
'''
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property Synopsis() As String
Get
Return GetMetaData(DvrmsMetadataEditor.SubtitleDescription)
End Get
Set(ByVal value As String)
SetMetaData(DvrmsMetadataEditor.SubtitleDescription, value, MetadataItemType.String)
End Set
End Property
''' <summary>
'''
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property ParentalRating() As String
Get
Return GetMetaData(DvrmsMetadataEditor.ParentalRating, "--")
End Get
Set(ByVal value As String)
SetMetaData(DvrmsMetadataEditor.ParentalRating, value, MetadataItemType.String)
End Set
End Property
''' <summary>
'''
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property Subtitle() As String
Get
Return GetMetaData(DvrmsMetadataEditor.Subtitle)
End Get
Set(ByVal value As String)
SetMetaData(DvrmsMetadataEditor.Subtitle, value, MetadataItemType.String)
End Set
End Property
''' <summary>
'''
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property Title() As String
Get
Return GetMetaData(DvrmsMetadataEditor.Title)
End Get
Set(ByVal value As String)
SetMetaData(DvrmsMetadataEditor.Title, value, MetadataItemType.String)
End Set
End Property
''' <summary>
'''
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property Genres() As String
Get
Return GetMetaData(DvrmsMetadataEditor.Genre, "")
End Get
Set(ByVal value As String)
SetMetaData(DvrmsMetadataEditor.Genre, value, MetadataItemType.String)
End Set
End Property
''' <summary>
'''
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property Credits() As String
Get
Return GetMetaData(DvrmsMetadataEditor.Credits, "")
End Get
Set(ByVal value As String)
SetMetaData(DvrmsMetadataEditor.Credits, value, MetadataItemType.String)
End Set
End Property
#End Region
''' <summary>
'''
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public ReadOnly Property Genre() As IList(Of String)
Get
Return _Genre
End Get
End Property
''' <summary>
'''
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public ReadOnly Property Actors() As IList(Of String)
Get
Return _Actors
End Get
End Property
''' <summary>
'''
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public ReadOnly Property Directors() As IList(Of String)
Get
Return _Directors
End Get
End Property
''' <summary>
'''
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public ReadOnly Property Other() As IList(Of String)
Get
Return _Other
End Get
End Property
''' <summary>
'''
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public ReadOnly Property Crew() As IList(Of String)
Get
Return _Crew
End Get
End Property
''' <summary>
'''
''' </summary>
''' <param name="theList"></param>
''' <param name="separator"></param>
''' <returns></returns>
''' <remarks></remarks>
Private Function ArrayToString(ByVal theList As List(Of String), ByVal separator As String) As String
Dim sList As String = ""
For Each a As String In theList
sList += a + separator
Next
Return sList.TrimEnd(separator.ToCharArray)
End Function
''' <summary>
'''
''' </summary>
''' <param name="Actor"></param>
''' <remarks></remarks>
Public Sub AddActor(ByVal Actor As String)
If _Actors.Contains(Actor) Then Exit Sub
IsDirty = True
_Actors.Add(Actor)
_Credits(0) = ArrayToString(_Actors, "/")
Credits = ArrayToString(_Credits, ";")
End Sub
''' <summary>
'''
''' </summary>
''' <param name="Director"></param>
''' <remarks></remarks>
Public Sub AddDirector(ByVal Director As String)
If _Directors.Contains(Director) Then Exit Sub
IsDirty = True
_Directors.Add(Director)
_Credits(1) = ArrayToString(_Directors, "/")
Credits = ArrayToString(_Credits, ";")
End Sub
Public Sub ClearGenre()
IsDirty = True
_Genre.Clear()
Genres = ArrayToString(_Genre, ",")
End Sub
''' <summary>
'''
''' </summary>
''' <param name="Genre"></param>
''' <remarks></remarks>
Public Sub AddGenre(ByVal Genre As String)
If String.IsNullOrEmpty(Genre) Then Exit Sub
If _Genre.Contains(Genre) Then Exit Sub
IsDirty = True
_Genre.Add(Genre)
Genres = ArrayToString(_Genre, ",")
End Sub
''' <summary>
'''
''' </summary>
''' <param name="key"></param>
''' <returns></returns>
''' <remarks></remarks>
Private Function GetMetaData(ByVal key As String) As Object
Return GetMetaData(key, Nothing)
End Function
''' <summary>
'''
''' </summary>
''' <param name="key"></param>
''' <param name="default"></param>
''' <returns></returns>
''' <remarks></remarks>
Private Function GetMetaData(ByVal key As String, ByVal [default] As Object) As Object
If Not _meta.Contains(key) Then Return [default]
Dim item As MetadataItem = _meta(key)
If item IsNot Nothing Then
If String.IsNullOrEmpty(CStr(item.Value)) Then
Return [default]
Else
Return item.Value
End If
End If
Return [default]
End Function
''' <summary>
'''
''' </summary>
''' <param name="key"></param>
''' <param name="value"></param>
''' <param name="type"></param>
''' <remarks></remarks>
Private Sub SetMetaData(ByVal key As String, ByVal value As Object, ByVal type As MetadataItemType)
_IsDirty = True
If Not _meta.Contains(key) Then
Dim item As MetadataItem = New MetadataItem(key, value, type)
_meta.Add(item.Name, item)
Else
CType(_meta(key), MetadataItem).Value = value
End If
End Sub
''' <summary>
'''
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property meta() As IDictionary
Get
If _meta Is Nothing Then
Using _editor As New DvrmsMetadataEditor(filename)
_meta = _editor.GetAttributes
End Using
End If
Return _meta
End Get
Set(ByVal value As IDictionary)
_meta = value
End Set
End Property
Private disposedValue As Boolean = False ' To detect redundant calls
' IDisposable
Protected Overridable Sub Dispose(ByVal disposing As Boolean)
If Not Me.disposedValue Then
If disposing Then
' TODO: free managed resources when explicitly called
_meta = Nothing
_Genre = Nothing
_Credits = Nothing
_Actors = Nothing
_Directors = Nothing
_Other = Nothing
_Crew = Nothing
End If
' TODO: free shared unmanaged resources
End If
Me.disposedValue = True
End Sub
#Region " IDisposable Support "
' This code added by Visual Basic to correctly implement the disposable pattern.
Public Sub Dispose() Implements IDisposable.Dispose
' Do not change this code. Put cleanup code in Dispose(ByVal disposing As Boolean) above.
Dispose(True)
GC.SuppressFinalize(Me)
End Sub
#End Region
End Class