-
Notifications
You must be signed in to change notification settings - Fork 185
/
clsAPINFO.vb
2596 lines (2274 loc) · 139 KB
/
clsAPINFO.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
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
' ################################################################################
' # EMBER MEDIA MANAGER #
' ################################################################################
' ################################################################################
' # This file is part of Ember Media Manager. #
' # #
' # Ember Media Manager is free software: you can redistribute it and/or modify #
' # it under the terms of the GNU General Public License as published by #
' # the Free Software Foundation, either version 3 of the License, or #
' # (at your option) any later version. #
' # #
' # Ember Media Manager is distributed in the hope that it will be useful, #
' # but WITHOUT ANY WARRANTY; without even the implied warranty of #
' # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
' # GNU General Public License for more details. #
' # #
' # You should have received a copy of the GNU General Public License #
' # along with Ember Media Manager. If not, see <http://www.gnu.org/licenses/>. #
' ################################################################################
Imports System.IO
Imports System.Text
Imports System.Text.RegularExpressions
Imports System.Xml
Imports System.Xml.Serialization
Imports NLog
Imports System.Windows.Forms
Public Class NFO
#Region "Fields"
Shared logger As Logger = LogManager.GetCurrentClassLogger()
#End Region
#Region "Methods"
''' <summary>
''' Returns the "merged" result of each data scraper results
''' </summary>
''' <param name="DBMovie">Movie to be scraped</param>
''' <param name="ScrapedList"><c>List(Of MediaContainers.Movie)</c> which contains unfiltered results of each data scraper</param>
''' <returns>The scrape result of movie (after applying various global scraper settings here)</returns>
''' <remarks>
''' This is used to determine the result of data scraping by going through all scraperesults of every data scraper and applying global data scraper settings here!
'''
''' 2014/09/01 Cocotus - First implementation: Moved all global lock settings in various data scrapers to this function, only apply them once and not in every data scraper module! Should be more maintainable!
''' </remarks>
Public Shared Function MergeDataScraperResults_Movie(ByVal DBMovie As Database.DBElement, ByVal ScrapedList As List(Of MediaContainers.Movie), ByVal ScrapeType As Enums.ScrapeType, ByVal ScrapeOptions As Structures.ScrapeOptions) As Database.DBElement
'protects the first scraped result against overwriting
Dim new_Actors As Boolean = False
Dim new_Certification As Boolean = False
Dim new_CollectionID As Boolean = False
Dim new_Collections As Boolean = False
Dim new_Countries As Boolean = False
Dim new_Credits As Boolean = False
Dim new_Directors As Boolean = False
Dim new_Genres As Boolean = False
Dim new_MPAA As Boolean = False
Dim new_OriginalTitle As Boolean = False
Dim new_Outline As Boolean = False
Dim new_Plot As Boolean = False
Dim new_Rating As Boolean = False
Dim new_ReleaseDate As Boolean = False
Dim new_Runtime As Boolean = False
Dim new_Studio As Boolean = False
Dim new_Tagline As Boolean = False
Dim new_Title As Boolean = False
Dim new_Top250 As Boolean = False
Dim new_Trailer As Boolean = False
Dim new_UserRating As Boolean = False
Dim new_Year As Boolean = False
'If "Use Preview Datascraperresults" option is enabled, a preview window which displays all datascraperresults will be opened before showing the Edit Movie page!
If (ScrapeType = Enums.ScrapeType.SingleScrape OrElse ScrapeType = Enums.ScrapeType.SingleField) AndAlso Master.eSettings.MovieScraperUseDetailView AndAlso ScrapedList.Count > 0 Then
PreviewDataScraperResults_Movie(ScrapedList)
End If
For Each scrapedmovie In ScrapedList
'IDs
If scrapedmovie.IMDBSpecified Then
DBMovie.Movie.IMDB = scrapedmovie.IMDB
End If
If scrapedmovie.TMDBSpecified Then
DBMovie.Movie.TMDB = scrapedmovie.TMDB
End If
'Actors
If (Not DBMovie.Movie.ActorsSpecified OrElse Not Master.eSettings.MovieLockActors) AndAlso ScrapeOptions.bMainActors AndAlso
scrapedmovie.ActorsSpecified AndAlso Master.eSettings.MovieScraperCast AndAlso Not new_Actors Then
If Master.eSettings.MovieScraperCastWithImgOnly Then
FilterOnlyPersonsWithImage(scrapedmovie.Actors)
End If
FilterCountLimit(Master.eSettings.MovieScraperCastLimit, scrapedmovie.Actors)
'added check if there's any actors left to add, if not then try with results of following scraper...
If scrapedmovie.ActorsSpecified Then
ReorderPersons(scrapedmovie.Actors)
DBMovie.Movie.Actors = scrapedmovie.Actors
new_Actors = True
End If
ElseIf Master.eSettings.MovieScraperCleanFields AndAlso Not Master.eSettings.MovieScraperCast AndAlso Not Master.eSettings.MovieLockActors Then
DBMovie.Movie.Actors.Clear()
End If
'Certification
If (Not DBMovie.Movie.CertificationsSpecified OrElse Not Master.eSettings.MovieLockCert) AndAlso ScrapeOptions.bMainCertifications AndAlso
scrapedmovie.CertificationsSpecified AndAlso Master.eSettings.MovieScraperCert AndAlso Not new_Certification Then
If Master.eSettings.MovieScraperCertLang = Master.eLang.All Then
DBMovie.Movie.Certifications = scrapedmovie.Certifications
new_Certification = True
Else
Dim CertificationLanguage = APIXML.CertLanguagesXML.Language.FirstOrDefault(Function(l) l.abbreviation = Master.eSettings.MovieScraperCertLang)
If CertificationLanguage IsNot Nothing AndAlso CertificationLanguage.name IsNot Nothing AndAlso Not String.IsNullOrEmpty(CertificationLanguage.name) Then
For Each tCert In scrapedmovie.Certifications
If tCert.StartsWith(CertificationLanguage.name) Then
DBMovie.Movie.Certifications.Clear()
DBMovie.Movie.Certifications.Add(tCert)
new_Certification = True
Exit For
End If
Next
Else
logger.Error("Movie Certification Language (Limit) not found. Please check your settings!")
End If
End If
ElseIf Master.eSettings.MovieScraperCleanFields AndAlso Not Master.eSettings.MovieScraperCert AndAlso Not Master.eSettings.MovieLockCert Then
DBMovie.Movie.Certifications.Clear()
End If
'Credits
If (Not DBMovie.Movie.CreditsSpecified OrElse Not Master.eSettings.MovieLockCredits) AndAlso
scrapedmovie.CreditsSpecified AndAlso Master.eSettings.MovieScraperCredits AndAlso Not new_Credits Then
DBMovie.Movie.Credits = scrapedmovie.Credits
new_Credits = True
ElseIf Master.eSettings.MovieScraperCleanFields AndAlso Not Master.eSettings.MovieScraperCredits AndAlso Not Master.eSettings.MovieLockCredits Then
DBMovie.Movie.Credits.Clear()
End If
'Collection ID
If (Not DBMovie.Movie.TMDBColIDSpecified OrElse Not Master.eSettings.MovieLockCollectionID) AndAlso ScrapeOptions.bMainCollectionID AndAlso
scrapedmovie.TMDBColIDSpecified AndAlso Master.eSettings.MovieScraperCollectionID AndAlso Not new_CollectionID Then
DBMovie.Movie.TMDBColID = scrapedmovie.TMDBColID
new_CollectionID = True
ElseIf Master.eSettings.MovieScraperCleanFields AndAlso Not Master.eSettings.MovieScraperCollectionID AndAlso Not Master.eSettings.MovieLockCollectionID Then
DBMovie.Movie.TMDBColID = String.Empty
End If
'Collections
If (Not DBMovie.Movie.SetsSpecified OrElse Not Master.eSettings.MovieLockCollections) AndAlso
scrapedmovie.SetsSpecified AndAlso Master.eSettings.MovieScraperCollectionsAuto AndAlso Not new_Collections Then
DBMovie.Movie.Sets.Clear()
For Each movieset In scrapedmovie.Sets
If Not String.IsNullOrEmpty(movieset.Title) Then
For Each sett As AdvancedSettingsSetting In AdvancedSettings.GetAllSettings.Where(Function(y) y.Name.StartsWith("MovieSetTitleRenamer:"))
movieset.Title = movieset.Title.Replace(sett.Name.Substring(21), sett.Value)
Next
End If
Next
DBMovie.Movie.Sets.AddRange(scrapedmovie.Sets)
new_Collections = True
End If
'Countries
If (Not DBMovie.Movie.CountriesSpecified OrElse Not Master.eSettings.MovieLockCountry) AndAlso ScrapeOptions.bMainCountries AndAlso
scrapedmovie.CountriesSpecified AndAlso Master.eSettings.MovieScraperCountry AndAlso Not new_Countries Then
FilterCountLimit(Master.eSettings.MovieScraperCountryLimit, scrapedmovie.Countries)
DBMovie.Movie.Countries = scrapedmovie.Countries
new_Countries = True
ElseIf Master.eSettings.MovieScraperCleanFields AndAlso Not Master.eSettings.MovieScraperCountry AndAlso Not Master.eSettings.MovieLockCountry Then
DBMovie.Movie.Countries.Clear()
End If
'Directors
If (Not DBMovie.Movie.DirectorsSpecified OrElse Not Master.eSettings.MovieLockDirector) AndAlso ScrapeOptions.bMainDirectors AndAlso
scrapedmovie.DirectorsSpecified AndAlso Master.eSettings.MovieScraperDirector AndAlso Not new_Directors Then
DBMovie.Movie.Directors = scrapedmovie.Directors
new_Directors = True
ElseIf Master.eSettings.MovieScraperCleanFields AndAlso Not Master.eSettings.MovieScraperDirector AndAlso Not Master.eSettings.MovieLockDirector Then
DBMovie.Movie.Directors.Clear()
End If
'Genres
If (Not DBMovie.Movie.GenresSpecified OrElse Not Master.eSettings.MovieLockGenre) AndAlso ScrapeOptions.bMainGenres AndAlso
scrapedmovie.GenresSpecified AndAlso Master.eSettings.MovieScraperGenre AndAlso Not new_Genres Then
StringUtils.GenreFilter(scrapedmovie.Genres)
FilterCountLimit(Master.eSettings.MovieScraperGenreLimit, scrapedmovie.Genres)
DBMovie.Movie.Genres = scrapedmovie.Genres
new_Genres = True
ElseIf Master.eSettings.MovieScraperCleanFields AndAlso Not Master.eSettings.MovieScraperGenre AndAlso Not Master.eSettings.MovieLockGenre Then
DBMovie.Movie.Genres.Clear()
End If
'MPAA
If (Not DBMovie.Movie.MPAASpecified OrElse Not Master.eSettings.MovieLockMPAA) AndAlso ScrapeOptions.bMainMPAA AndAlso
scrapedmovie.MPAASpecified AndAlso Master.eSettings.MovieScraperMPAA AndAlso Not new_MPAA Then
DBMovie.Movie.MPAA = scrapedmovie.MPAA
new_MPAA = True
ElseIf Master.eSettings.MovieScraperCleanFields AndAlso Not Master.eSettings.MovieScraperMPAA AndAlso Not Master.eSettings.MovieLockMPAA Then
DBMovie.Movie.MPAA = String.Empty
End If
'Originaltitle
If (Not DBMovie.Movie.OriginalTitleSpecified OrElse Not Master.eSettings.MovieLockOriginalTitle) AndAlso ScrapeOptions.bMainOriginalTitle AndAlso
scrapedmovie.OriginalTitleSpecified AndAlso Master.eSettings.MovieScraperOriginalTitle AndAlso Not new_OriginalTitle Then
DBMovie.Movie.OriginalTitle = scrapedmovie.OriginalTitle
new_OriginalTitle = True
ElseIf Master.eSettings.MovieScraperCleanFields AndAlso Not Master.eSettings.MovieScraperOriginalTitle AndAlso Not Master.eSettings.MovieLockOriginalTitle Then
DBMovie.Movie.OriginalTitle = String.Empty
End If
'Outline
If (Not DBMovie.Movie.OutlineSpecified OrElse Not Master.eSettings.MovieLockOutline) AndAlso ScrapeOptions.bMainOutline AndAlso
scrapedmovie.OutlineSpecified AndAlso Master.eSettings.MovieScraperOutline AndAlso Not new_Outline Then
DBMovie.Movie.Outline = scrapedmovie.Outline
new_Outline = True
ElseIf Master.eSettings.MovieScraperCleanFields AndAlso Not Master.eSettings.MovieScraperOutline AndAlso Not Master.eSettings.MovieLockOutline Then
DBMovie.Movie.Outline = String.Empty
End If
'check if brackets should be removed...
If Master.eSettings.MovieScraperCleanPlotOutline Then
DBMovie.Movie.Outline = StringUtils.RemoveBrackets(DBMovie.Movie.Outline)
End If
'Plot
If (Not DBMovie.Movie.PlotSpecified OrElse Not Master.eSettings.MovieLockPlot) AndAlso ScrapeOptions.bMainPlot AndAlso
scrapedmovie.PlotSpecified AndAlso Master.eSettings.MovieScraperPlot AndAlso Not new_Plot Then
DBMovie.Movie.Plot = scrapedmovie.Plot
new_Plot = True
ElseIf Master.eSettings.MovieScraperCleanFields AndAlso Not Master.eSettings.MovieScraperPlot AndAlso Not Master.eSettings.MovieLockPlot Then
DBMovie.Movie.Plot = String.Empty
End If
'check if brackets should be removed...
If Master.eSettings.MovieScraperCleanPlotOutline Then
DBMovie.Movie.Plot = StringUtils.RemoveBrackets(DBMovie.Movie.Plot)
End If
'Rating/Votes
If (Not DBMovie.Movie.RatingSpecified OrElse Not Master.eSettings.MovieLockRating) AndAlso ScrapeOptions.bMainRating AndAlso
scrapedmovie.RatingSpecified AndAlso Master.eSettings.MovieScraperRating AndAlso Not new_Rating Then
DBMovie.Movie.Rating = scrapedmovie.Rating
DBMovie.Movie.Votes = NumUtils.CleanVotes(scrapedmovie.Votes)
new_Rating = True
ElseIf Master.eSettings.MovieScraperCleanFields AndAlso Not Master.eSettings.MovieScraperRating AndAlso Not Master.eSettings.MovieLockRating Then
DBMovie.Movie.Rating = String.Empty
DBMovie.Movie.Votes = String.Empty
End If
'ReleaseDate
If (Not DBMovie.Movie.ReleaseDateSpecified OrElse Not Master.eSettings.MovieLockReleaseDate) AndAlso ScrapeOptions.bMainRelease AndAlso
scrapedmovie.ReleaseDateSpecified AndAlso Master.eSettings.MovieScraperRelease AndAlso Not new_ReleaseDate Then
DBMovie.Movie.ReleaseDate = NumUtils.DateToISO8601Date(scrapedmovie.ReleaseDate)
new_ReleaseDate = True
ElseIf Master.eSettings.MovieScraperCleanFields AndAlso Not Master.eSettings.MovieScraperRelease AndAlso Not Master.eSettings.MovieLockReleaseDate Then
DBMovie.Movie.ReleaseDate = String.Empty
End If
'Studios
If (Not DBMovie.Movie.StudiosSpecified OrElse Not Master.eSettings.MovieLockStudio) AndAlso ScrapeOptions.bMainStudios AndAlso
scrapedmovie.StudiosSpecified AndAlso Master.eSettings.MovieScraperStudio AndAlso Not new_Studio Then
DBMovie.Movie.Studios.Clear()
Dim _studios As New List(Of String)
_studios.AddRange(scrapedmovie.Studios)
If Master.eSettings.MovieScraperStudioWithImgOnly Then
For i = _studios.Count - 1 To 0 Step -1
If APIXML.dStudios.ContainsKey(_studios.Item(i).ToLower) = False Then
_studios.RemoveAt(i)
End If
Next
End If
FilterCountLimit(Master.eSettings.MovieScraperStudioLimit, _studios)
DBMovie.Movie.Studios.AddRange(_studios)
'added check if there's any studios left to add, if not then try with results of following scraper...
If _studios.Count > 0 Then
new_Studio = True
End If
ElseIf Master.eSettings.MovieScraperCleanFields AndAlso Not Master.eSettings.MovieScraperStudio AndAlso Not Master.eSettings.MovieLockStudio Then
DBMovie.Movie.Studios.Clear()
End If
'Tagline
If (Not DBMovie.Movie.TaglineSpecified OrElse Not Master.eSettings.MovieLockTagline) AndAlso ScrapeOptions.bMainTagline AndAlso
scrapedmovie.TaglineSpecified AndAlso Master.eSettings.MovieScraperTagline AndAlso Not new_Tagline Then
DBMovie.Movie.Tagline = scrapedmovie.Tagline
new_Tagline = True
ElseIf Master.eSettings.MovieScraperCleanFields AndAlso Not Master.eSettings.MovieScraperTagline AndAlso Not Master.eSettings.MovieLockTagline Then
DBMovie.Movie.Tagline = String.Empty
End If
'Title
If (Not DBMovie.Movie.TitleSpecified OrElse Not Master.eSettings.MovieLockTitle) AndAlso ScrapeOptions.bMainTitle AndAlso
scrapedmovie.TitleSpecified AndAlso Master.eSettings.MovieScraperTitle AndAlso Not new_Title Then
DBMovie.Movie.Title = scrapedmovie.Title
new_Title = True
ElseIf Master.eSettings.MovieScraperCleanFields AndAlso Not Master.eSettings.MovieScraperTitle AndAlso Not Master.eSettings.MovieLockTitle Then
DBMovie.Movie.Title = String.Empty
End If
'Top250 (special handling: no check if "scrapedmovie.Top250Specified" and only set "new_Top250 = True" if a value over 0 has been set)
If (Not DBMovie.Movie.Top250Specified OrElse Not Master.eSettings.MovieLockTop250) AndAlso ScrapeOptions.bMainTop250 AndAlso
Master.eSettings.MovieScraperTop250 AndAlso Not new_Top250 Then
DBMovie.Movie.Top250 = scrapedmovie.Top250
new_Top250 = If(scrapedmovie.Top250Specified, True, False)
ElseIf Master.eSettings.MovieScraperCleanFields AndAlso Not Master.eSettings.MovieScraperTop250 AndAlso Not Master.eSettings.MovieLockTop250 Then
DBMovie.Movie.Top250 = 0
End If
'Trailer
If (Not DBMovie.Movie.TrailerSpecified OrElse Not Master.eSettings.MovieLockTrailer) AndAlso ScrapeOptions.bMainTrailer AndAlso
scrapedmovie.TrailerSpecified AndAlso Master.eSettings.MovieScraperTrailer AndAlso Not new_Trailer Then
If Master.eSettings.MovieScraperXBMCTrailerFormat AndAlso YouTube.UrlUtils.IsYouTubeUrl(scrapedmovie.Trailer) Then
DBMovie.Movie.Trailer = StringUtils.ConvertFromYouTubeURLToKodiTrailerFormat(scrapedmovie.Trailer)
Else
DBMovie.Movie.Trailer = scrapedmovie.Trailer
End If
new_Trailer = True
ElseIf Master.eSettings.MovieScraperCleanFields AndAlso Not Master.eSettings.MovieScraperTrailer AndAlso Not Master.eSettings.MovieLockTrailer Then
DBMovie.Movie.Trailer = String.Empty
End If
'User Rating
If (Not DBMovie.Movie.UserRatingSpecified OrElse Not Master.eSettings.MovieLockUserRating) AndAlso ScrapeOptions.bMainUserRating AndAlso
scrapedmovie.UserRatingSpecified AndAlso Master.eSettings.MovieScraperUserRating AndAlso Not new_UserRating Then
DBMovie.Movie.UserRating = scrapedmovie.UserRating
new_UserRating = True
ElseIf Master.eSettings.MovieScraperCleanFields AndAlso Not Master.eSettings.MovieScraperUserRating AndAlso Not Master.eSettings.MovieLockUserRating Then
DBMovie.Movie.UserRating = 0
End If
'Year
If (Not DBMovie.Movie.YearSpecified OrElse Not Master.eSettings.MovieLockYear) AndAlso ScrapeOptions.bMainYear AndAlso
scrapedmovie.YearSpecified AndAlso Master.eSettings.MovieScraperYear AndAlso Not new_Year Then
DBMovie.Movie.Year = scrapedmovie.Year
new_Year = True
ElseIf Master.eSettings.MovieScraperCleanFields AndAlso Not Master.eSettings.MovieScraperYear AndAlso Not Master.eSettings.MovieLockYear Then
DBMovie.Movie.Year = String.Empty
End If
'Runtime
If (Not DBMovie.Movie.RuntimeSpecified OrElse Not Master.eSettings.MovieLockRuntime) AndAlso ScrapeOptions.bMainRuntime AndAlso
scrapedmovie.RuntimeSpecified AndAlso Master.eSettings.MovieScraperRuntime AndAlso Not new_Runtime Then
DBMovie.Movie.Runtime = scrapedmovie.Runtime
new_Runtime = True
ElseIf Master.eSettings.MovieScraperCleanFields AndAlso Not Master.eSettings.MovieScraperRuntime AndAlso Not Master.eSettings.MovieLockRuntime Then
DBMovie.Movie.Runtime = String.Empty
End If
Next
'UniqueIDs
DBMovie.Movie.UniqueIDs.Clear()
If DBMovie.Movie.IMDBSpecified Then
DBMovie.Movie.UniqueIDs.Add(New MediaContainers.Uniqueid With {
.IsDefault = True,
.Type = "imdb",
.Value = DBMovie.Movie.IMDB})
End If
If DBMovie.Movie.TMDBSpecified Then
DBMovie.Movie.UniqueIDs.Add(New MediaContainers.Uniqueid With {
.IsDefault = False,
.Type = "tmdb",
.Value = DBMovie.Movie.TMDB})
End If
'Certification for MPAA
If DBMovie.Movie.CertificationsSpecified AndAlso Master.eSettings.MovieScraperCertForMPAA AndAlso
(Not Master.eSettings.MovieScraperCertForMPAAFallback AndAlso (Not DBMovie.Movie.MPAASpecified OrElse Not Master.eSettings.MovieLockMPAA) OrElse
Not new_MPAA AndAlso (Not DBMovie.Movie.MPAASpecified OrElse Not Master.eSettings.MovieLockMPAA)) Then
Dim tmpstring As String = String.Empty
tmpstring = If(Master.eSettings.MovieScraperCertLang = "us", StringUtils.USACertToMPAA(String.Join(" / ", DBMovie.Movie.Certifications.ToArray)), If(Master.eSettings.MovieScraperCertOnlyValue, String.Join(" / ", DBMovie.Movie.Certifications.ToArray).Split(Convert.ToChar(":"))(1), String.Join(" / ", DBMovie.Movie.Certifications.ToArray)))
'only update DBMovie if scraped result is not empty/nothing!
If Not String.IsNullOrEmpty(tmpstring) Then
DBMovie.Movie.MPAA = tmpstring
End If
End If
'MPAA value if MPAA is not available
If Not DBMovie.Movie.MPAASpecified AndAlso Not String.IsNullOrEmpty(Master.eSettings.MovieScraperMPAANotRated) Then
DBMovie.Movie.MPAA = Master.eSettings.MovieScraperMPAANotRated
End If
'OriginalTitle as Title
If (Not DBMovie.Movie.TitleSpecified OrElse Not Master.eSettings.MovieLockTitle) AndAlso Master.eSettings.MovieScraperOriginalTitleAsTitle AndAlso DBMovie.Movie.OriginalTitleSpecified Then
DBMovie.Movie.Title = DBMovie.Movie.OriginalTitle
End If
'Plot for Outline
If ((Not DBMovie.Movie.OutlineSpecified OrElse Not Master.eSettings.MovieLockOutline) AndAlso Master.eSettings.MovieScraperPlotForOutline AndAlso Not Master.eSettings.MovieScraperPlotForOutlineIfEmpty) OrElse
(Not DBMovie.Movie.OutlineSpecified AndAlso Master.eSettings.MovieScraperPlotForOutline AndAlso Master.eSettings.MovieScraperPlotForOutlineIfEmpty) Then
DBMovie.Movie.Outline = StringUtils.ShortenOutline(DBMovie.Movie.Plot, Master.eSettings.MovieScraperOutlineLimit)
End If
'set ListTitle at the end of merging
If DBMovie.Movie.TitleSpecified Then
Dim tTitle As String = StringUtils.SortTokens_Movie(DBMovie.Movie.Title)
If Master.eSettings.MovieDisplayYear AndAlso Not String.IsNullOrEmpty(DBMovie.Movie.Year) Then
DBMovie.ListTitle = String.Format("{0} ({1})", tTitle, DBMovie.Movie.Year)
Else
DBMovie.ListTitle = tTitle
End If
Else
DBMovie.ListTitle = StringUtils.FilterTitleFromPath_Movie(DBMovie.Filename, DBMovie.IsSingle, DBMovie.Source.UseFolderName)
End If
Return DBMovie
End Function
Public Shared Function MergeDataScraperResults_MovieSet(ByVal DBMovieSet As Database.DBElement, ByVal ScrapedList As List(Of MediaContainers.MovieSet), ByVal ScrapeType As Enums.ScrapeType, ByVal ScrapeOptions As Structures.ScrapeOptions) As Database.DBElement
'protects the first scraped result against overwriting
Dim new_Plot As Boolean = False
Dim new_Title As Boolean = False
For Each scrapedmovieset In ScrapedList
'IDs
If scrapedmovieset.TMDBSpecified Then
DBMovieSet.MovieSet.TMDB = scrapedmovieset.TMDB
End If
'Plot
If (Not DBMovieSet.MovieSet.PlotSpecified OrElse Not Master.eSettings.MovieSetLockPlot) AndAlso ScrapeOptions.bMainPlot AndAlso
scrapedmovieset.PlotSpecified AndAlso Master.eSettings.MovieSetScraperPlot AndAlso Not new_Plot Then
DBMovieSet.MovieSet.Plot = scrapedmovieset.Plot
new_Plot = True
'ElseIf Master.eSettings.MovieSetScraperCleanFields AndAlso Not Master.eSettings.MovieSetScraperPlot AndAlso Not Master.eSettings.MovieSetLockPlot Then
' DBMovieSet.MovieSet.Plot = String.Empty
End If
'Title
If (Not DBMovieSet.MovieSet.TitleSpecified OrElse Not Master.eSettings.MovieSetLockTitle) AndAlso ScrapeOptions.bMainTitle AndAlso
scrapedmovieset.TitleSpecified AndAlso Master.eSettings.MovieSetScraperTitle AndAlso Not new_Title Then
DBMovieSet.MovieSet.Title = scrapedmovieset.Title
new_Title = True
'ElseIf Master.eSettings.MovieSetScraperCleanFields AndAlso Not Master.eSettings.MovieSetScraperTitle AndAlso Not Master.eSettings.MovieSetLockTitle Then
' DBMovieSet.MovieSet.Title = String.Empty
End If
Next
'set Title
For Each sett As AdvancedSettingsSetting In AdvancedSettings.GetAllSettings.Where(Function(y) y.Name.StartsWith("MovieSetTitleRenamer:"))
DBMovieSet.MovieSet.Title = DBMovieSet.MovieSet.Title.Replace(sett.Name.Substring(21), sett.Value)
Next
'set ListTitle at the end of merging
If DBMovieSet.MovieSet.TitleSpecified Then
Dim tTitle As String = StringUtils.SortTokens_MovieSet(DBMovieSet.MovieSet.Title)
DBMovieSet.ListTitle = tTitle
Else
'If FileUtils.Common.isVideoTS(DBMovie.Filename) Then
' DBMovie.ListTitle = StringUtils.FilterName_Movie(Directory.GetParent(Directory.GetParent(DBMovie.Filename).FullName).Name)
'ElseIf FileUtils.Common.isBDRip(DBMovie.Filename) Then
' DBMovie.ListTitle = StringUtils.FilterName_Movie(Directory.GetParent(Directory.GetParent(Directory.GetParent(DBMovie.Filename).FullName).FullName).Name)
'Else
' If DBMovie.UseFolder AndAlso DBMovie.IsSingle Then
' DBMovie.ListTitle = StringUtils.FilterName_Movie(Directory.GetParent(DBMovie.Filename).Name)
' Else
' DBMovie.ListTitle = StringUtils.FilterName_Movie(Path.GetFileNameWithoutExtension(DBMovie.Filename))
' End If
'End If
End If
Return DBMovieSet
End Function
''' <summary>
''' Returns the "merged" result of each data scraper results
''' </summary>
''' <param name="DBTV">TV Show to be scraped</param>
''' <param name="ScrapedList"><c>List(Of MediaContainers.TVShow)</c> which contains unfiltered results of each data scraper</param>
''' <returns>The scrape result of movie (after applying various global scraper settings here)</returns>
''' <remarks>
''' This is used to determine the result of data scraping by going through all scraperesults of every data scraper and applying global data scraper settings here!
'''
''' 2014/09/01 Cocotus - First implementation: Moved all global lock settings in various data scrapers to this function, only apply them once and not in every data scraper module! Should be more maintainable!
''' </remarks>
Public Shared Function MergeDataScraperResults_TV(ByVal DBTV As Database.DBElement, ByVal ScrapedList As List(Of MediaContainers.TVShow), ByVal ScrapeType As Enums.ScrapeType, ByVal ScrapeOptions As Structures.ScrapeOptions, ByVal withEpisodes As Boolean) As Database.DBElement
'protects the first scraped result against overwriting
Dim new_Actors As Boolean = False
Dim new_Certification As Boolean = False
Dim new_Creators As Boolean = False
Dim new_Collections As Boolean = False
Dim new_ShowCountries As Boolean = False
Dim new_Credits As Boolean = False
Dim new_Directors As Boolean = False
Dim new_Genres As Boolean = False
Dim new_MPAA As Boolean = False
Dim new_Outline As Boolean = False
Dim new_Plot As Boolean = False
Dim new_Rating As Boolean = False
Dim new_Premiered As Boolean = False
Dim new_Runtime As Boolean = False
Dim new_Status As Boolean = False
Dim new_Studio As Boolean = False
Dim new_Tagline As Boolean = False
Dim new_Title As Boolean = False
Dim new_OriginalTitle As Boolean = False
Dim new_Trailer As Boolean = False
Dim new_UserRating As Boolean = False
Dim KnownEpisodesIndex As New List(Of KnownEpisode)
Dim KnownSeasonsIndex As New List(Of Integer)
''If "Use Preview Datascraperresults" option is enabled, a preview window which displays all datascraperresults will be opened before showing the Edit Movie page!
'If (ScrapeType = Enums.ScrapeType_Movie_MovieSet_TV.SingleScrape OrElse ScrapeType = Enums.ScrapeType_Movie_MovieSet_TV.SingleField) AndAlso Master.eSettings.MovieScraperUseDetailView AndAlso ScrapedList.Count > 0 Then
' PreviewDataScraperResults(ScrapedList)
'End If
For Each scrapedshow In ScrapedList
'IDs
If scrapedshow.TVDBSpecified Then
DBTV.TVShow.TVDB = scrapedshow.TVDB
End If
If scrapedshow.IMDBSpecified Then
DBTV.TVShow.IMDB = scrapedshow.IMDB
End If
If scrapedshow.TMDBSpecified Then
DBTV.TVShow.TMDB = scrapedshow.TMDB
End If
'Actors
If (Not DBTV.TVShow.ActorsSpecified OrElse Not Master.eSettings.TVLockShowActors) AndAlso ScrapeOptions.bMainActors AndAlso
scrapedshow.ActorsSpecified AndAlso Master.eSettings.TVScraperShowActors AndAlso Not new_Actors Then
If Master.eSettings.TVScraperCastWithImgOnly Then
FilterOnlyPersonsWithImage(scrapedshow.Actors)
End If
FilterCountLimit(Master.eSettings.TVScraperShowActorsLimit, scrapedshow.Actors)
'added check if there's any actors left to add, if not then try with results of following scraper...
If scrapedshow.ActorsSpecified Then
ReorderPersons(scrapedshow.Actors)
DBTV.TVShow.Actors = scrapedshow.Actors
new_Actors = True
End If
ElseIf Master.eSettings.TVScraperCleanFields AndAlso Not Master.eSettings.TVScraperShowActors AndAlso Not Master.eSettings.TVLockShowActors Then
DBTV.TVShow.Actors.Clear()
End If
'Certification
If (Not DBTV.TVShow.CertificationsSpecified OrElse Not Master.eSettings.TVLockShowCert) AndAlso ScrapeOptions.bMainCertifications AndAlso
scrapedshow.CertificationsSpecified AndAlso Master.eSettings.TVScraperShowCert AndAlso Not new_Certification Then
If Master.eSettings.TVScraperShowCertLang = Master.eLang.All Then
DBTV.TVShow.Certifications = scrapedshow.Certifications
new_Certification = True
Else
Dim CertificationLanguage = APIXML.CertLanguagesXML.Language.FirstOrDefault(Function(l) l.abbreviation = Master.eSettings.TVScraperShowCertLang)
If CertificationLanguage IsNot Nothing AndAlso CertificationLanguage.name IsNot Nothing AndAlso Not String.IsNullOrEmpty(CertificationLanguage.name) Then
For Each tCert In scrapedshow.Certifications
If tCert.StartsWith(CertificationLanguage.name) Then
DBTV.TVShow.Certifications.Clear()
DBTV.TVShow.Certifications.Add(tCert)
new_Certification = True
Exit For
End If
Next
Else
logger.Error("TV Show Certification Language (Limit) not found. Please check your settings!")
End If
End If
ElseIf Master.eSettings.TVScraperCleanFields AndAlso Not Master.eSettings.TVScraperShowCert AndAlso Not Master.eSettings.TVLockShowCert Then
DBTV.TVShow.Certifications.Clear()
End If
'Creators
If (Not DBTV.TVShow.CreatorsSpecified OrElse Not Master.eSettings.TVLockShowCreators) AndAlso ScrapeOptions.bMainCreators AndAlso
scrapedshow.CreatorsSpecified AndAlso Master.eSettings.TVScraperShowCreators AndAlso Not new_Creators Then
DBTV.TVShow.Creators = scrapedshow.Creators
new_Creators = True
ElseIf Master.eSettings.TVScraperCleanFields AndAlso Not Master.eSettings.TVScraperShowCreators AndAlso Not Master.eSettings.TVLockShowCreators Then
DBTV.TVShow.Creators.Clear()
End If
'Countries
If (Not DBTV.TVShow.CountriesSpecified OrElse Not Master.eSettings.TVLockShowCountry) AndAlso ScrapeOptions.bMainCountries AndAlso
scrapedshow.CountriesSpecified AndAlso Master.eSettings.TVScraperShowCountry AndAlso Not new_ShowCountries Then
FilterCountLimit(Master.eSettings.TVScraperShowCountryLimit, scrapedshow.Countries)
DBTV.TVShow.Countries = scrapedshow.Countries
new_ShowCountries = True
ElseIf Master.eSettings.TVScraperCleanFields AndAlso Not Master.eSettings.TVScraperShowCountry AndAlso Not Master.eSettings.TVLockShowCountry Then
DBTV.TVShow.Countries.Clear()
End If
'EpisodeGuideURL
If ScrapeOptions.bMainEpisodeGuide AndAlso scrapedshow.EpisodeGuideSpecified AndAlso Master.eSettings.TVScraperShowEpiGuideURL Then
DBTV.TVShow.EpisodeGuide = scrapedshow.EpisodeGuide
ElseIf Master.eSettings.TVScraperCleanFields AndAlso Not Master.eSettings.TVScraperShowEpiGuideURL Then
DBTV.TVShow.EpisodeGuide.Clear()
End If
'Genres
If (Not DBTV.TVShow.GenresSpecified OrElse Not Master.eSettings.TVLockShowGenre) AndAlso ScrapeOptions.bMainGenres AndAlso
scrapedshow.GenresSpecified AndAlso Master.eSettings.TVScraperShowGenre AndAlso Not new_Genres Then
StringUtils.GenreFilter(scrapedshow.Genres)
FilterCountLimit(Master.eSettings.TVScraperShowGenreLimit, scrapedshow.Genres)
DBTV.TVShow.Genres = scrapedshow.Genres
new_Genres = True
ElseIf Master.eSettings.TVScraperCleanFields AndAlso Not Master.eSettings.TVScraperShowGenre AndAlso Not Master.eSettings.TVLockShowGenre Then
DBTV.TVShow.Genres.Clear()
End If
'MPAA
If (Not DBTV.TVShow.MPAASpecified OrElse Not Master.eSettings.TVLockShowMPAA) AndAlso ScrapeOptions.bMainMPAA AndAlso
scrapedshow.MPAASpecified AndAlso Master.eSettings.TVScraperShowMPAA AndAlso Not new_MPAA Then
DBTV.TVShow.MPAA = scrapedshow.MPAA
new_MPAA = True
ElseIf Master.eSettings.TVScraperCleanFields AndAlso Not Master.eSettings.TVScraperShowMPAA AndAlso Not Master.eSettings.TVLockShowMPAA Then
DBTV.TVShow.MPAA = String.Empty
End If
'Originaltitle
If (Not DBTV.TVShow.OriginalTitleSpecified OrElse Not Master.eSettings.TVLockShowOriginalTitle) AndAlso ScrapeOptions.bMainOriginalTitle AndAlso
scrapedshow.OriginalTitleSpecified AndAlso Master.eSettings.TVScraperShowOriginalTitle AndAlso Not new_OriginalTitle Then
DBTV.TVShow.OriginalTitle = scrapedshow.OriginalTitle
new_OriginalTitle = True
ElseIf Master.eSettings.TVScraperCleanFields AndAlso Not Master.eSettings.TVScraperShowOriginalTitle AndAlso Not Master.eSettings.TVLockShowOriginalTitle Then
DBTV.TVShow.OriginalTitle = String.Empty
End If
'Plot
If (Not DBTV.TVShow.PlotSpecified OrElse Not Master.eSettings.TVLockShowPlot) AndAlso ScrapeOptions.bMainPlot AndAlso
scrapedshow.PlotSpecified AndAlso Master.eSettings.TVScraperShowPlot AndAlso Not new_Plot Then
DBTV.TVShow.Plot = scrapedshow.Plot
new_Plot = True
ElseIf Master.eSettings.TVScraperCleanFields AndAlso Not Master.eSettings.TVScraperShowPlot AndAlso Not Master.eSettings.TVLockShowPlot Then
DBTV.TVShow.Plot = String.Empty
End If
'Premiered
If (Not DBTV.TVShow.PremieredSpecified OrElse Not Master.eSettings.TVLockShowPremiered) AndAlso ScrapeOptions.bMainPremiered AndAlso
scrapedshow.PremieredSpecified AndAlso Master.eSettings.TVScraperShowPremiered AndAlso Not new_Premiered Then
DBTV.TVShow.Premiered = NumUtils.DateToISO8601Date(scrapedshow.Premiered)
new_Premiered = True
ElseIf Master.eSettings.TVScraperCleanFields AndAlso Not Master.eSettings.TVScraperShowPremiered AndAlso Not Master.eSettings.TVLockShowPremiered Then
DBTV.TVShow.Premiered = String.Empty
End If
'Rating/Votes
If (Not DBTV.TVShow.RatingSpecified OrElse Not Master.eSettings.TVLockShowRating) AndAlso ScrapeOptions.bMainRating AndAlso
scrapedshow.RatingSpecified AndAlso Master.eSettings.TVScraperShowRating AndAlso Not new_Rating Then
DBTV.TVShow.Rating = scrapedshow.Rating
DBTV.TVShow.Votes = NumUtils.CleanVotes(scrapedshow.Votes)
new_Rating = True
ElseIf Master.eSettings.TVScraperCleanFields AndAlso Not Master.eSettings.TVScraperShowRating AndAlso Not Master.eSettings.TVLockShowRating Then
DBTV.TVShow.Rating = String.Empty
DBTV.TVShow.Votes = String.Empty
End If
'Runtime
If (Not DBTV.TVShow.RuntimeSpecified OrElse Not Master.eSettings.TVLockShowRuntime) AndAlso ScrapeOptions.bMainRuntime AndAlso
scrapedshow.RuntimeSpecified AndAlso Master.eSettings.TVScraperShowRuntime AndAlso Not new_Runtime Then
DBTV.TVShow.Runtime = scrapedshow.Runtime
new_Runtime = True
ElseIf Master.eSettings.TVScraperCleanFields AndAlso Not Master.eSettings.TVScraperShowRuntime AndAlso Not Master.eSettings.TVLockShowRuntime Then
DBTV.TVShow.Runtime = String.Empty
End If
'Status
If (DBTV.TVShow.StatusSpecified OrElse Not Master.eSettings.TVLockShowStatus) AndAlso ScrapeOptions.bMainStatus AndAlso
scrapedshow.StatusSpecified AndAlso Master.eSettings.TVScraperShowStatus AndAlso Not new_Status Then
DBTV.TVShow.Status = scrapedshow.Status
new_Status = True
ElseIf Master.eSettings.TVScraperCleanFields AndAlso Not Master.eSettings.TVScraperShowStatus AndAlso Not Master.eSettings.TVLockShowStatus Then
DBTV.TVShow.Status = String.Empty
End If
'Studios
If (Not DBTV.TVShow.StudiosSpecified OrElse Not Master.eSettings.TVLockShowStudio) AndAlso ScrapeOptions.bMainStudios AndAlso
scrapedshow.StudiosSpecified AndAlso Master.eSettings.TVScraperShowStudio AndAlso Not new_Studio Then
FilterCountLimit(Master.eSettings.TVScraperShowStudioLimit, scrapedshow.Studios)
DBTV.TVShow.Studios = scrapedshow.Studios
new_Studio = True
ElseIf Master.eSettings.TVScraperCleanFields AndAlso Not Master.eSettings.TVScraperShowStudio AndAlso Not Master.eSettings.TVLockShowStudio Then
DBTV.TVShow.Studios.Clear()
End If
'Title
If (Not DBTV.TVShow.TitleSpecified OrElse Not Master.eSettings.TVLockShowTitle) AndAlso ScrapeOptions.bMainTitle AndAlso
scrapedshow.TitleSpecified AndAlso Master.eSettings.TVScraperShowTitle AndAlso Not new_Title Then
DBTV.TVShow.Title = scrapedshow.Title
new_Title = True
ElseIf Master.eSettings.TVScraperCleanFields AndAlso Not Master.eSettings.TVScraperShowTitle AndAlso Not Master.eSettings.TVLockShowTitle Then
DBTV.TVShow.Title = String.Empty
End If
'User Rating
If (Not DBTV.TVShow.UserRatingSpecified OrElse Not Master.eSettings.TVLockShowUserRating) AndAlso ScrapeOptions.bMainUserRating AndAlso
scrapedshow.UserRatingSpecified AndAlso Master.eSettings.TVScraperShowUserRating AndAlso Not new_UserRating Then
DBTV.TVShow.UserRating = scrapedshow.UserRating
new_UserRating = True
ElseIf Master.eSettings.TVScraperCleanFields AndAlso Not Master.eSettings.TVScraperShowUserRating AndAlso Not Master.eSettings.TVLockShowUserRating Then
DBTV.TVShow.UserRating = 0
End If
'Create KnowSeasons index
For Each kSeason As MediaContainers.SeasonDetails In scrapedshow.KnownSeasons
If Not KnownSeasonsIndex.Contains(kSeason.Season) Then
KnownSeasonsIndex.Add(kSeason.Season)
End If
Next
'Create KnownEpisodes index (season and episode number)
If withEpisodes Then
For Each kEpisode As MediaContainers.EpisodeDetails In scrapedshow.KnownEpisodes
Dim nKnownEpisode As New KnownEpisode With {.AiredDate = kEpisode.Aired,
.Episode = kEpisode.Episode,
.EpisodeAbsolute = kEpisode.EpisodeAbsolute,
.EpisodeCombined = kEpisode.EpisodeCombined,
.EpisodeDVD = kEpisode.EpisodeDVD,
.Season = kEpisode.Season,
.SeasonCombined = kEpisode.SeasonCombined,
.SeasonDVD = kEpisode.SeasonDVD}
If KnownEpisodesIndex.Where(Function(f) f.Episode = nKnownEpisode.Episode AndAlso f.Season = nKnownEpisode.Season).Count = 0 Then
KnownEpisodesIndex.Add(nKnownEpisode)
'try to get an episode information with more numbers
ElseIf KnownEpisodesIndex.Where(Function(f) f.Episode = nKnownEpisode.Episode AndAlso f.Season = nKnownEpisode.Season AndAlso
((nKnownEpisode.EpisodeAbsolute > -1 AndAlso Not f.EpisodeAbsolute = nKnownEpisode.EpisodeAbsolute) OrElse
(nKnownEpisode.EpisodeCombined > -1 AndAlso Not f.EpisodeCombined = nKnownEpisode.EpisodeCombined) OrElse
(nKnownEpisode.EpisodeDVD > -1 AndAlso Not f.EpisodeDVD = nKnownEpisode.EpisodeDVD) OrElse
(nKnownEpisode.SeasonCombined > -1 AndAlso Not f.SeasonCombined = nKnownEpisode.SeasonCombined) OrElse
(nKnownEpisode.SeasonDVD > -1 AndAlso Not f.SeasonDVD = nKnownEpisode.SeasonDVD))).Count = 1 Then
Dim toRemove As KnownEpisode = KnownEpisodesIndex.FirstOrDefault(Function(f) f.Episode = nKnownEpisode.Episode AndAlso f.Season = nKnownEpisode.Season)
KnownEpisodesIndex.Remove(toRemove)
KnownEpisodesIndex.Add(nKnownEpisode)
End If
Next
End If
Next
'UniqueIDs
DBTV.TVShow.UniqueIDs.Clear()
If DBTV.TVShow.TVDBSpecified Then
DBTV.TVShow.UniqueIDs.Add(New MediaContainers.Uniqueid With {
.IsDefault = True,
.Type = "tvdb",
.Value = DBTV.TVShow.TVDB})
End If
If DBTV.TVShow.IMDBSpecified Then
DBTV.TVShow.UniqueIDs.Add(New MediaContainers.Uniqueid With {
.IsDefault = False,
.Type = "imdb",
.Value = DBTV.TVShow.IMDB})
End If
If DBTV.TVShow.TMDBSpecified Then
DBTV.TVShow.UniqueIDs.Add(New MediaContainers.Uniqueid With {
.IsDefault = False,
.Type = "tmdb",
.Value = DBTV.TVShow.TMDB})
End If
'Certification for MPAA
If DBTV.TVShow.CertificationsSpecified AndAlso Master.eSettings.TVScraperShowCertForMPAA AndAlso
(Not Master.eSettings.MovieScraperCertForMPAAFallback AndAlso (Not DBTV.TVShow.MPAASpecified OrElse Not Master.eSettings.TVLockShowMPAA) OrElse
Not new_MPAA AndAlso (Not DBTV.TVShow.MPAASpecified OrElse Not Master.eSettings.TVLockShowMPAA)) Then
Dim tmpstring As String = String.Empty
tmpstring = If(Master.eSettings.TVScraperShowCertLang = "us", StringUtils.USACertToMPAA(String.Join(" / ", DBTV.TVShow.Certifications.ToArray)), If(Master.eSettings.TVScraperShowCertOnlyValue, String.Join(" / ", DBTV.TVShow.Certifications.ToArray).Split(Convert.ToChar(":"))(1), String.Join(" / ", DBTV.TVShow.Certifications.ToArray)))
'only update DBMovie if scraped result is not empty/nothing!
If Not String.IsNullOrEmpty(tmpstring) Then
DBTV.TVShow.MPAA = tmpstring
End If
End If
'MPAA value if MPAA is not available
If Not DBTV.TVShow.MPAASpecified AndAlso Not String.IsNullOrEmpty(Master.eSettings.TVScraperShowMPAANotRated) Then
DBTV.TVShow.MPAA = Master.eSettings.TVScraperShowMPAANotRated
End If
'OriginalTitle as Title
If (Not DBTV.TVShow.TitleSpecified OrElse Not Master.eSettings.TVLockShowTitle) AndAlso Master.eSettings.TVScraperShowOriginalTitleAsTitle AndAlso DBTV.TVShow.OriginalTitleSpecified Then
DBTV.TVShow.Title = DBTV.TVShow.OriginalTitle
End If
'set ListTitle at the end of merging
If DBTV.TVShow.TitleSpecified Then
DBTV.ListTitle = StringUtils.SortTokens_TV(DBTV.TVShow.Title)
End If
'Seasons
For Each aKnownSeason As Integer In KnownSeasonsIndex
'create a list of specified episode informations from all scrapers
Dim ScrapedSeasonList As New List(Of MediaContainers.SeasonDetails)
For Each nShow As MediaContainers.TVShow In ScrapedList
For Each nSeasonDetails As MediaContainers.SeasonDetails In nShow.KnownSeasons.Where(Function(f) f.Season = aKnownSeason)
ScrapedSeasonList.Add(nSeasonDetails)
Next
Next
'check if we have already saved season information for this scraped season
Dim lSeasonList = DBTV.Seasons.Where(Function(f) f.TVSeason.Season = aKnownSeason)
If lSeasonList IsNot Nothing AndAlso lSeasonList.Count > 0 Then
For Each nSeason As Database.DBElement In lSeasonList
MergeDataScraperResults_TVSeason(nSeason, ScrapedSeasonList, ScrapeOptions)
Next
Else
'no existing season found -> add it as "missing" season
Dim mSeason As New Database.DBElement(Enums.ContentType.TVSeason) With {.TVSeason = New MediaContainers.SeasonDetails With {.Season = aKnownSeason}}
mSeason = Master.DB.AddTVShowInfoToDBElement(mSeason, DBTV)
DBTV.Seasons.Add(MergeDataScraperResults_TVSeason(mSeason, ScrapedSeasonList, ScrapeOptions))
End If
Next
'add all season informations to TVShow (for saving season informations to tv show NFO)
DBTV.TVShow.Seasons.Seasons.Clear()
For Each kSeason As Database.DBElement In DBTV.Seasons.OrderBy(Function(f) f.TVSeason.Season)
DBTV.TVShow.Seasons.Seasons.Add(kSeason.TVSeason)
Next
'Episodes
If withEpisodes Then
'update the tvshow information for each local episode
For Each lEpisode In DBTV.Episodes
lEpisode = Master.DB.AddTVShowInfoToDBElement(lEpisode, DBTV)
Next
For Each aKnownEpisode As KnownEpisode In KnownEpisodesIndex.OrderBy(Function(f) f.Episode).OrderBy(Function(f) f.Season)
'convert the episode and season number if needed
Dim iEpisode As Integer = -1
Dim iSeason As Integer = -1
Dim strAiredDate As String = aKnownEpisode.AiredDate
If DBTV.Ordering = Enums.EpisodeOrdering.Absolute Then
iEpisode = aKnownEpisode.EpisodeAbsolute
iSeason = 1
ElseIf DBTV.Ordering = Enums.EpisodeOrdering.DVD Then
iEpisode = CInt(aKnownEpisode.EpisodeDVD)
iSeason = aKnownEpisode.SeasonDVD
ElseIf DBTV.Ordering = Enums.EpisodeOrdering.Standard Then
iEpisode = aKnownEpisode.Episode
iSeason = aKnownEpisode.Season
End If
If Not iEpisode = -1 AndAlso Not iSeason = -1 Then
'create a list of specified episode informations from all scrapers
Dim ScrapedEpisodeList As New List(Of MediaContainers.EpisodeDetails)
For Each nShow As MediaContainers.TVShow In ScrapedList
For Each nEpisodeDetails As MediaContainers.EpisodeDetails In nShow.KnownEpisodes.Where(Function(f) f.Episode = aKnownEpisode.Episode AndAlso f.Season = aKnownEpisode.Season)
ScrapedEpisodeList.Add(nEpisodeDetails)
Next
Next
'check if we have a local episode file for this scraped episode
Dim lEpisodeList = DBTV.Episodes.Where(Function(f) Not String.IsNullOrEmpty(f.Filename) AndAlso f.TVEpisode.Episode = iEpisode AndAlso f.TVEpisode.Season = iSeason)
If lEpisodeList IsNot Nothing AndAlso lEpisodeList.Count > 0 Then
For Each nEpisode As Database.DBElement In lEpisodeList
MergeDataScraperResults_TVEpisode(nEpisode, ScrapedEpisodeList, ScrapeOptions)
Next
Else
'try to get the episode by AiredDate
Dim dEpisodeList = DBTV.Episodes.Where(Function(f) f.FilenameSpecified AndAlso
f.TVEpisode.Episode = -1 AndAlso
f.TVEpisode.AiredSpecified AndAlso
f.TVEpisode.Aired = strAiredDate)
If dEpisodeList IsNot Nothing AndAlso dEpisodeList.Count > 0 Then
For Each nEpisode As Database.DBElement In dEpisodeList
MergeDataScraperResults_TVEpisode(nEpisode, ScrapedEpisodeList, ScrapeOptions)
'we have to add the proper season and episode number if the episode was found by AiredDate
nEpisode.TVEpisode.Episode = iEpisode
nEpisode.TVEpisode.Season = iSeason
Next
Else
'no local episode found -> add it as "missing" episode
Dim mEpisode As New Database.DBElement(Enums.ContentType.TVEpisode) With {.TVEpisode = New MediaContainers.EpisodeDetails With {.Episode = iEpisode, .Season = iSeason}}
mEpisode = Master.DB.AddTVShowInfoToDBElement(mEpisode, DBTV)
MergeDataScraperResults_TVEpisode(mEpisode, ScrapedEpisodeList, ScrapeOptions)
If mEpisode.TVEpisode.TitleSpecified Then
DBTV.Episodes.Add(mEpisode)
Else
logger.Warn(String.Format("Missing Episode Ignored | {0} - S{1}E{2} | No Episode Title found", mEpisode.TVShow.Title, mEpisode.TVEpisode.Season, mEpisode.TVEpisode.Episode))
End If
End If
End If
Else
logger.Warn("No valid episode or season number found")
End If
Next
End If
'create the "* All Seasons" entry if needed
Dim tmpAllSeasons As Database.DBElement = DBTV.Seasons.FirstOrDefault(Function(f) f.TVSeason.IsAllSeasons)
If tmpAllSeasons Is Nothing OrElse tmpAllSeasons.TVSeason Is Nothing Then
tmpAllSeasons = New Database.DBElement(Enums.ContentType.TVSeason)
tmpAllSeasons.TVSeason = New MediaContainers.SeasonDetails With {.Season = -1}
tmpAllSeasons = Master.DB.AddTVShowInfoToDBElement(tmpAllSeasons, DBTV)
DBTV.Seasons.Add(tmpAllSeasons)
End If
'cleanup seasons they don't have any episode
Dim iIndex As Integer = 0
While iIndex <= DBTV.Seasons.Count - 1
Dim iSeason As Integer = DBTV.Seasons.Item(iIndex).TVSeason.Season
If Not iSeason = -1 AndAlso DBTV.Episodes.Where(Function(f) f.TVEpisode.Season = iSeason).Count = 0 Then
DBTV.Seasons.RemoveAt(iIndex)
Else
iIndex += 1
End If
End While
Return DBTV
End Function
Public Shared Function MergeDataScraperResults_TVSeason(ByRef DBTVSeason As Database.DBElement, ByVal ScrapedList As List(Of MediaContainers.SeasonDetails), ByVal ScrapeOptions As Structures.ScrapeOptions) As Database.DBElement
'protects the first scraped result against overwriting
Dim new_Aired As Boolean = False
Dim new_Plot As Boolean = False
Dim new_Season As Boolean = False
Dim new_Title As Boolean = False
For Each scrapedseason In ScrapedList
'IDs
If scrapedseason.TMDBSpecified Then
DBTVSeason.TVSeason.TMDB = scrapedseason.TMDB
End If
If scrapedseason.TVDBSpecified Then
DBTVSeason.TVSeason.TVDB = scrapedseason.TVDB
End If
'Season number
If scrapedseason.SeasonSpecified AndAlso Not new_Season Then
DBTVSeason.TVSeason.Season = scrapedseason.Season
new_Season = True
End If
'Aired
If (Not DBTVSeason.TVSeason.AiredSpecified OrElse Not Master.eSettings.TVLockEpisodeAired) AndAlso ScrapeOptions.bSeasonAired AndAlso
scrapedseason.AiredSpecified AndAlso Master.eSettings.TVScraperEpisodeAired AndAlso Not new_Aired Then
DBTVSeason.TVSeason.Aired = scrapedseason.Aired
new_Aired = True
ElseIf Master.eSettings.TVScraperCleanFields AndAlso Not Master.eSettings.TVScraperEpisodeAired AndAlso Not Master.eSettings.TVLockEpisodeAired Then
DBTVSeason.TVSeason.Aired = String.Empty
End If
'Plot
If (Not DBTVSeason.TVSeason.PlotSpecified OrElse Not Master.eSettings.TVLockEpisodePlot) AndAlso ScrapeOptions.bSeasonPlot AndAlso
scrapedseason.PlotSpecified AndAlso Master.eSettings.TVScraperEpisodePlot AndAlso Not new_Plot Then
DBTVSeason.TVSeason.Plot = scrapedseason.Plot
new_Plot = True
ElseIf Master.eSettings.TVScraperCleanFields AndAlso Not Master.eSettings.TVScraperEpisodePlot AndAlso Not Master.eSettings.TVLockEpisodePlot Then
DBTVSeason.TVSeason.Plot = String.Empty
End If
'Title
If (Not DBTVSeason.TVSeason.TitleSpecified OrElse Not Master.eSettings.TVLockSeasonTitle) AndAlso ScrapeOptions.bSeasonTitle AndAlso
scrapedseason.TitleSpecified AndAlso Master.eSettings.TVScraperSeasonTitle AndAlso Not new_Title Then
DBTVSeason.TVSeason.Title = scrapedseason.Title
new_Title = True
ElseIf Master.eSettings.TVScraperCleanFields AndAlso Not Master.eSettings.TVScraperSeasonTitle AndAlso Not Master.eSettings.TVLockSeasonTitle Then
DBTVSeason.TVSeason.Title = String.Empty
End If
Next
Return DBTVSeason
End Function
''' <summary>
''' Returns the "merged" result of each data scraper results
''' </summary>
''' <param name="DBTVEpisode">Episode to be scraped</param>
''' <param name="ScrapedList"><c>List(Of MediaContainers.EpisodeDetails)</c> which contains unfiltered results of each data scraper</param>
''' <returns>The scrape result of episode (after applying various global scraper settings here)</returns>
''' <remarks>
''' This is used to determine the result of data scraping by going through all scraperesults of every data scraper and applying global data scraper settings here!
'''
''' 2014/09/01 Cocotus - First implementation: Moved all global lock settings in various data scrapers to this function, only apply them once and not in every data scraper module! Should be more maintainable!
''' </remarks>
Private Shared Function MergeDataScraperResults_TVEpisode(ByRef DBTVEpisode As Database.DBElement, ByVal ScrapedList As List(Of MediaContainers.EpisodeDetails), ByVal ScrapeOptions As Structures.ScrapeOptions) As Database.DBElement
'protects the first scraped result against overwriting
Dim new_Actors As Boolean = False
Dim new_Aired As Boolean = False
Dim new_Countries As Boolean = False
Dim new_Credits As Boolean = False
Dim new_Directors As Boolean = False
Dim new_Episode As Boolean = False
Dim new_GuestStars As Boolean = False
Dim new_OriginalTitle As Boolean = False