-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApiController.cs
More file actions
818 lines (719 loc) · 37.8 KB
/
ApiController.cs
File metadata and controls
818 lines (719 loc) · 37.8 KB
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
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Collections;
using MediaBrowser.Model.Services;
using MediaBrowser.Model.Logging;
using MediaBrowser.Common.Configuration;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace StudioDashboard
{
[Route("/emby/StudioDashboard/Test", "GET", Summary = "Test-Endpoint")]
[AllowAnonymous]
public class TestRequest : IReturn<object> {}
[Route("/emby/StudioDashboard/Studios", "GET", Summary = "Liste der Studios")]
[AllowAnonymous]
public class GetStudios : IReturn<List<StudioDto>> {}
[Route("/emby/StudioDashboard/StudiosWithLogos", "GET", Summary = "Studios mit Logo-Informationen")]
[AllowAnonymous]
public class GetStudiosWithLogos : IReturn<List<StreamingStudioDto>>
{
public int? Top { get; set; }
public string Q { get; set; }
public string Filter { get; set; }
}
[Route("/emby/StudioDashboard/StudiosNormalized", "GET", Summary = "Normalisierte Studios für Home-Page")]
[AllowAnonymous]
public class GetStudiosNormalized : IReturn<List<StreamingStudioDto>>
{
public int? Top { get; set; }
public string Q { get; set; }
}
[Route("/emby/StudioDashboard/ExportJson", "GET", Summary = "Studios als JSON")]
[AllowAnonymous]
public class ExportJsonRequest : IReturn<List<StudioDto>> {}
[Route("/emby/StudioDashboard/ExportCsv", "GET", Summary = "Studios als CSV")]
[AllowAnonymous]
public class ExportCsvRequest : IReturn<string> {}
[Route("/emby/StudioDashboard/SaveExport", "POST", Summary = "Speichert Studios serverseitig")]
[AllowAnonymous]
public class SaveExportRequest : IReturn<object>
{
public string Format { get; set; }
}
[Route("/emby/StudioDashboard/SyncCollections", "POST", Summary = "Startet Collections-Sync")]
[AllowAnonymous]
public class SyncCollectionsRequest : IReturn<object> {}
public class ApiController : IService
{
private readonly ILibraryManager _libraryManager;
private readonly IApplicationPaths _appPaths;
private readonly ICollectionManager _collectionManager;
private readonly ILogger _logger;
private static readonly object _lock = new object();
private static List<StudioDto> _cachedStudios;
private static DateTime _lastUpdate = DateTime.MinValue;
private static readonly Dictionary<string, StreamingServiceInfo> ServiceInfo =
new Dictionary<string, StreamingServiceInfo>(StringComparer.OrdinalIgnoreCase)
{
{ "Netflix", new StreamingServiceInfo
{
LogoUrl = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAwIiBoZWlnaHQ9IjQwIiB2aWV3Qm94PSIwIDAgMTAwIDQwIiBmaWxsPSJub25lIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxyZWN0IHdpZHRoPSIxMDAiIGhlaWdodD0iNDAiIGZpbGw9IiNlNTA5MTQiLz48dGV4dCB4PSI1MCIgeT0iMjUiIGZvbnQtZmFtaWx5PSJBcmlhbCwgc2Fucy1zZXJpZiIgZm9udC1zaXplPSIxNiIgZm9udC13ZWlnaHQ9ImJvbGQiIGZpbGw9IiNmZmZmZmYiIHRleHQtYW5jaG9yPSJtaWRkbGUiPk5FVEZMSVg8L3RleHQ+PC9zdmc+",
BackgroundColor = "#e50914",
TextColor = "#ffffff",
IsStreamingService = true
}
},
{ "Apple", new StreamingServiceInfo
{
LogoUrl = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAwIiBoZWlnaHQ9IjQwIiB2aWV3Qm94PSIwIDAgMTAwIDQwIiBmaWxsPSJub25lIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxyZWN0IHdpZHRoPSIxMDAiIGhlaWdodD0iNDAiIGZpbGw9IjAwMDAwMCIvPjx0ZXh0IHg9IjUwIiB5PSIyNSIgZm9udC1mYW1pbHk9IkFyaWFsLCBzYW5zLXNlcmlmIiBmb250LXNpemU9IjEzIiBmb250LXdlaWdodD0iYm9sZCIgZmlsbD0iI2ZmZmZmZiIgdGV4dC1hbmNob3I9Im1pZGRsZSI+QXBwbGUgVFYrPC90ZXh0Pjwvc3ZnPg==",
BackgroundColor = "#000000",
TextColor = "#ffffff",
IsStreamingService = true
}
},
{ "Amazon", new StreamingServiceInfo
{
LogoUrl = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAwIiBoZWlnaHQ9IjQwIiB2aWV3Qm94PSIwIDAgMTAwIDQwIiBmaWxsPSJub25lIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxyZWN0IHdpZHRoPSIxMDAiIGhlaWdodD0iNDAiIGZpbGw9IjAwYThlMSIvPjx0ZXh0IHg9IjUwIiB5PSIyNSIgZm9udC1mYW1pbHk9IkFyaWFsLCBzYW5zLXNlcmlmIiBmb250LXNpemU9IjEyIiBmb250LXdlaWdodD0iYm9sZCIgZmlsbD0iI2ZmZmZmZiIgdGV4dC1hbmNob3I9Im1pZGRsZSI+UHJpbWUgVmlkZW88L3RleHQ+PC9zdmc+",
BackgroundColor = "#00a8e1",
TextColor = "#ffffff",
IsStreamingService = true
}
},
{ "Disney", new StreamingServiceInfo
{
LogoUrl = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAwIiBoZWlnaHQ9IjQwIiB2aWV3Qm94PSIwIDAgMTAwIDQwIiBmaWxsPSJub25lIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxyZWN0IHdpZHRoPSIxMDAiIGhlaWdodD0iNDAiIGZpbGw9IjExM2NjZSIvPjx0ZXh0IHg9IjUwIiB5PSIyNSIgZm9udC1mYW1pbHk9IkFyaWFsLCBzYW5zLXNlcmlmIiBmb250LXNpemU9IjE0IiBmb250LXdlaWdodD0iYm9sZCIgZmlsbD0iI2ZmZmZmZiIgdGV4dC1hbmNob3I9Im1pZGRsZSI+RElTTkVZKzwvdGV4dD48L3N2Zz4=",
BackgroundColor = "#113cce",
TextColor = "#ffffff",
IsStreamingService = true
}
},
{ "HBO", new StreamingServiceInfo
{
LogoUrl = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAwIiBoZWlnaHQ9IjQwIiB2aWV3Qm94PSIwIDAgMTAwIDQwIiBmaWxsPSJub25lIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxyZWN0IHdpZHRoPSIxMDAiIGhlaWdodD0iNDAiIGZpbGw9IjlhNDRjNyIvPjx0ZXh0IHg9IjUwIiB5PSIyNSIgZm9udC1mYW1pbHk9IkFyaWFsLCBzYW5zLXNlcmlmIiBmb250LXNpemU9IjE2IiBmb250LXdlaWdodD0iYm9sZCIgZmlsbD0iI2ZmZmZmZiIgdGV4dC1hbmNob3I9Im1pZGRsZSI+SEJPIE1BWDwvdGV4dD48L3N2Zz4=",
BackgroundColor = "#9a44c7",
TextColor = "#ffffff",
IsStreamingService = true
}
},
{ "Sony", new StreamingServiceInfo
{
LogoUrl = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAwIiBoZWlnaHQ9IjQwIiB2aWV3Qm94PSIwIDAgMTAwIDQwIiBmaWxsPSJub25lIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxyZWN0IHdpZHRoPSIxMDAiIGhlaWdodD0iNDAiIGZpbGw9IjAwMDAwMCIvPjx0ZXh0IHg9IjUwIiB5PSIyNSIgZm9udC1mYW1pbHk9IkFyaWFsLCBzYW5zLXNlcmlmIiBmb250LXNpemU9IjE0IiBmb250LXdlaWdodD0iYm9sZCIgZmlsbD0iI2ZmZmZmZiIgdGV4dC1hbmNob3I9Im1pZGRsZSI+U09OWSBQSUNUVVJFU1wvdGV4dD48L3N2Zz4=",
BackgroundColor = "#000000",
TextColor = "#ffffff",
IsStreamingService = true
}
},
{ "Paramount", new StreamingServiceInfo
{
LogoUrl = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAwIiBoZWlnaHQ9IjQwIiB2aWV3Qm94PSIwIDAgMTAwIDQwIiBmaWxsPSJub25lIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxyZWN0IHdpZHRoPSIxMDAiIGhlaWdodD0iNDAiIGZpbGw9IjAwNjRmZiIvPjx0ZXh0IHg9IjUwIiB5PSIyNSIgZm9udC1mYW1pbHk9IkFyaWFsLCBzYW5zLXNlcmlmIiBmb250LXNpemU9IjEyIiBmb250LXdlaWdodD0iYm9sZCIgZmlsbD0iI2ZmZmZmZiIgdGV4dC1hbmNob3I9Im1pZGRsZSI+UEFSQU1PVU5UKzwvdGV4dD48L3N2Zz4=",
BackgroundColor = "#0064ff",
TextColor = "#ffffff",
IsStreamingService = true
}
},
{ "Peacock", new StreamingServiceInfo
{
LogoUrl = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAwIiBoZWlnaHQ9IjQwIiB2aWV3Qm94PSIwIDAgMTAwIDQwIiBmaWxsPSJub25lIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxyZWN0IHdpZHRoPSIxMDAiIGhlaWdodD0iNDAiIGZpbGw9IzAwYjNhNiIvPjx0ZXh0IHg9IjUwIiB5PSIyNSIgZm9udC1mYW1pbHk9IkFyaWFsLCBzYW5zLXNlcmlmIiBmb250LXNpemU9IjE0IiBmb250LXdlaWdodD0iYm9sZCIgZmlsbD0iI2ZmZmZmZiIgdGV4dC1hbmNob3I9Im1pZGRsZSI+UEVBQ09DSzwvdGV4dD48L3N2Zz4=",
BackgroundColor = "#00b3a6",
TextColor = "#ffffff",
IsStreamingService = true
}
},
{ "Hulu", new StreamingServiceInfo
{
LogoUrl = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAwIiBoZWlnaHQ9IjQwIiB2aWV3Qm94PSIwIDAgMTAwIDQwIiBmaWxsPSJub25lIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxyZWN0IHdpZHRoPSIxMDAiIGhlaWdodD0iNDAiIGZpbGw9IjNkYjg0OCIvPjx0ZXh0IHg9IjUwIiB5PSIyNSIgZm9udC1mYW1pbHk9IkFyaWFsLCBzYW5zLXNlcmlmIiBmb250LXNpemU9IjE2IiBmb250LXdlaWdodD0iYm9sZCIgZmlsbD0iI2ZmZmZmZiIgdGV4dC1hbmNob3I9Im1pZGRsZSI+SFVMVTwvdGV4dD48L3N2Zz4=",
BackgroundColor = "#3db848",
TextColor = "#ffffff",
IsStreamingService = true
}
},
{ "Showtime", new StreamingServiceInfo
{
LogoUrl = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAwIiBoZWlnaHQ9IjQwIiB2aWV3Qm94PSIwIDAgMTAwIDQwIiBmaWxsPSJub25lIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxyZWN0IHdpZHRoPSIxMDAiIGhlaWdodD0iNDAiIGZpbGw9ImQ1MDA1NiIvPjx0ZXh0IHg9IjUwIiB5PSIyNSIgZm9udC1mYW1pbHk9IkFyaWFsLCBzYW5zLXNlcmlmIiBmb250LXNpemU9IjEzIiBmb250LXdlaWdodD0iYm9sZCIgZmlsbD0iI2ZmZmZmZiIgdGV4dC1hbmNob3I9Im1pZGRsZSI+U0hPV1RJTUVcL3RleHQ+PC9zdmc+",
BackgroundColor = "#d50056",
TextColor = "#ffffff",
IsStreamingService = true
}
},
{ "Starz", new StreamingServiceInfo
{
LogoUrl = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAwIiBoZWlnaHQ9IjQwIiB2aWV3Qm94PSIwIDAgMTAwIDQwIiBmaWxsPSJub25lIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxyZWN0IHdpZHRoPSIxMDAiIGhlaWdodD0iNDAiIGZpbGw9IjAwMDAwMCIvPjx0ZXh0IHg9IjUwIiB5PSIyNSIgZm9udC1mYW1pbHk9IkFyaWFsLCBzYW5zLXNlcmlmIiBmb250LXNpemU9IjE2IiBmb250LXdlaWdodD0iYm9sZCIgZmlsbD0iI2ZmZmZmZiIgdGV4dC1hbmNob3I9Im1pZGRsZSI+U1RBUlo8L3RleHQ+PC9zdmc+",
BackgroundColor = "#000000",
TextColor = "#ffffff",
IsStreamingService = true
}
},
{ "Warner Bros", new StreamingServiceInfo
{
LogoUrl = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAwIiBoZWlnaHQ9IjQwIiB2aWV3Qm94PSIwIDAgMTAwIDQwIiBmaWxsPSJub25lIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxyZWN0IHdpZHRoPSIxMDAiIGhlaWdodD0iNDAiIGZpbGw9IjAwNDBhNSIvPjx0ZXh0IHg9IjUwIiB5PSIyNSIgZm9udC1mYW1pbHk9IkFyaWFsLCBzYW5zLXNlcmlmIiBmb250LXNpemU9IjEwIiBmb250LXdlaWdodD0iYm9sZCIgZmlsbD0iI2ZmZmZmZiIgdGV4dC1hbmNob3I9Im1pZGRsZSI+V0FSTkVSIEJST1MuPC90ZXh0Pjwvc3ZnPg==",
BackgroundColor = "#0040a5",
TextColor = "#ffffff",
IsStreamingService = false
}
},
{ "Universal", new StreamingServiceInfo
{
LogoUrl = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAwIiBoZWlnaHQ9IjQwIiB2aWV3Qm94PSIwIDAgMTAwIDQwIiBmaWxsPSJub25lIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxyZWN0IHdpZHRoPSIxMDAiIGhlaWdodD0iNDAiIGZpbGw9IjMzMzMzMyIvPjx0ZXh0IHg9IjUwIiB5PSIyNSIgZm9udC1mYW1pbHk9IkFyaWFsLCBzYW5zLXNlcmlmIiBmb250LXNpemU9IjEyIiBmb250LXdlaWdodD0iYm9sZCIgZmlsbD0iI2ZmZmZmZiIgdGV4dC1hbmNob3I9Im1pZGRsZSI+VU5JVkVSU0FMPC90ZXh0Pjwvc3ZnPg==",
BackgroundColor = "#333333",
TextColor = "#ffffff",
IsStreamingService = false
}
}
};
private class StreamingServiceInfo
{
public string LogoUrl { get; set; }
public string BackgroundColor { get; set; }
public string TextColor { get; set; }
public bool IsStreamingService { get; set; }
}
private static readonly Dictionary<string, string> AliasMap =
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
// Netflix
{ "Netflix", "Netflix" },
{ "Netflix Studios", "Netflix" },
// Apple
{ "Apple Studios", "Apple" },
{ "Apple TV+", "Apple" },
{ "Apple TV Plus", "Apple" },
{ "Apple Original Films", "Apple" },
// Amazon
{ "Amazon MGM Studios", "Amazon" },
{ "Amazon Studios", "Amazon" },
{ "Prime Video", "Amazon" },
{ "Amazon Prime Video", "Amazon" },
{ "MGM", "Amazon" },
// Disney
{ "Disney+", "Disney" },
{ "Disney Plus", "Disney" },
{ "Walt Disney Studios", "Disney" },
{ "Walt Disney Pictures", "Disney" },
{ "Disney Studios", "Disney" },
{ "Pixar", "Disney" },
{ "Marvel Studios", "Disney" },
{ "Lucasfilm", "Disney" },
{ "20th Century Studios", "Disney" },
{ "20th Century Fox", "Disney" },
// HBO
{ "HBO", "HBO" },
{ "HBO Max", "HBO" },
{ "HBO Films", "HBO" },
{ "HBO Entertainment", "HBO" },
{ "Home Box Office", "HBO" },
{ "Warner Media", "HBO" },
// Sony
{ "Sony Pictures Television", "Sony" },
{ "Sony Pictures", "Sony" },
{ "Sony Pictures Studios", "Sony" },
{ "PlayStation Productions", "Sony" },
{ "Columbia Pictures", "Sony" },
{ "TriStar Pictures", "Sony" },
{ "Screen Gems", "Sony" },
// Paramount
{ "Paramount+", "Paramount" },
{ "Paramount Plus", "Paramount" },
{ "Paramount Pictures", "Paramount" },
{ "Paramount Studios", "Paramount" },
{ "CBS Studios", "Paramount" },
{ "MTV Studios", "Paramount" },
{ "Nickelodeon", "Paramount" },
// Peacock/NBCUniversal
{ "Peacock", "Peacock" },
{ "NBC", "Peacock" },
{ "NBC Studios", "Peacock" },
{ "NBCUniversal", "Peacock" },
{ "Universal Television", "Peacock" },
// Hulu
{ "Hulu", "Hulu" },
{ "Hulu Originals", "Hulu" },
// Showtime
{ "Showtime", "Showtime" },
{ "Showtime Networks", "Showtime" },
// Starz
{ "Starz", "Starz" },
{ "Starz Entertainment", "Starz" },
// Warner Bros
{ "Warner Bros.", "Warner Bros" },
{ "Warner Bros", "Warner Bros" },
{ "Warner Brothers", "Warner Bros" },
{ "Warner Bros. Pictures", "Warner Bros" },
{ "Warner Bros Television", "Warner Bros" },
{ "DC Studios", "Warner Bros" },
{ "New Line Cinema", "Warner Bros" },
// Universal
{ "Universal Pictures", "Universal" },
{ "Universal Studios", "Universal" },
{ "Universal Television", "Universal" },
{ "Focus Features", "Universal" },
{ "DreamWorks", "Universal" }
};
public ApiController(
ILibraryManager libraryManager,
IApplicationPaths appPaths,
ICollectionManager collectionManager,
ILogger logger)
{
_libraryManager = libraryManager;
_appPaths = appPaths;
_collectionManager = collectionManager;
_logger = logger;
}
private List<StreamingStudioDto> QueryStudiosWithLogosNow()
{
try
{
_logger.Info("[StudioDashboard] Starting QueryStudiosWithLogosNow");
var items = _libraryManager.GetItemList(new InternalItemsQuery
{
IncludeItemTypes = new[] { typeof(Movie).Name, typeof(Series).Name },
Recursive = true
});
if (items == null)
{
_logger.Warn("[StudioDashboard] GetItemList returned null, returning empty list");
return new List<StreamingStudioDto>();
}
var itemsList = items?.ToList() ?? new List<BaseItem>();
_logger.Info("[StudioDashboard] Found {0} total items", itemsList.Count);
var itemsWithStudios = itemsList.Where(i => i.Studios != null && i.Studios.Any()).ToList();
_logger.Info("[StudioDashboard] Found {0} items with studios", itemsWithStudios.Count);
if (!itemsWithStudios.Any())
{
_logger.Warn("[StudioDashboard] No items with studios found, returning test data");
return new List<StreamingStudioDto>
{
new StreamingStudioDto
{
Studio = "Test Studio",
Count = 1,
LogoUrl = "",
BackgroundColor = "#555555",
TextColor = "#ffffff",
IsStreamingService = false
}
};
}
var studiosQuery = itemsWithStudios
.SelectMany(i => i.Studios)
.Select(NormalizeStudioName)
.Where(s => !string.IsNullOrWhiteSpace(s))
.GroupBy(s => s)
.Select(g => {
var studio = g.Key;
var serviceInfo = ServiceInfo.ContainsKey(studio) ? ServiceInfo[studio] : null;
return new StreamingStudioDto
{
Studio = studio,
Count = g.Count(),
LogoUrl = serviceInfo?.LogoUrl ?? "",
BackgroundColor = serviceInfo?.BackgroundColor ?? "#555555",
TextColor = serviceInfo?.TextColor ?? "#ffffff",
IsStreamingService = serviceInfo?.IsStreamingService ?? false
};
});
bool sortByCount = true;
try
{
if (Plugin.Instance?.Configuration != null)
sortByCount = Plugin.Instance.Configuration.SortByCount;
}
catch (Exception configEx)
{
_logger.Warn("[StudioDashboard] Could not load configuration: {0}", configEx.Message);
}
var list = sortByCount
? studiosQuery.OrderByDescending(x => x.Count).ThenBy(x => x.Studio).ToList()
: studiosQuery.OrderBy(x => x.Studio).ToList();
_logger.Info("[StudioDashboard] Returning {0} studios", list.Count);
return list;
}
catch (Exception ex)
{
_logger.Error("[StudioDashboard] Error in QueryStudiosWithLogosNow: {0}", ex);
return new List<StreamingStudioDto>();
}
}
private List<StudioDto> QueryStudiosNow()
{
var items = _libraryManager.GetItemList(new InternalItemsQuery
{
IncludeItemTypes = new[] { typeof(Movie).Name, typeof(Series).Name },
Recursive = true
});
var studiosQuery = items
.Where(i => i.Studios != null && i.Studios.Any())
.SelectMany(i => i.Studios)
.Select(NormalizeStudioName)
.Where(s => !string.IsNullOrWhiteSpace(s))
.GroupBy(s => s)
.Select(g => new StudioDto { Studio = g.Key, Count = g.Count() });
bool sortByCount = true;
try { sortByCount = Plugin.Instance.Configuration.SortByCount; } catch { }
var list = sortByCount
? studiosQuery.OrderByDescending(x => x.Count).ThenBy(x => x.Studio).ToList()
: studiosQuery.OrderBy(x => x.Studio).ToList();
return list;
}
private List<StudioDto> GetStudiosCached()
{
lock (_lock)
{
if (_cachedStudios != null && (DateTime.UtcNow - _lastUpdate).TotalMinutes < 10)
return _cachedStudios;
var fresh = QueryStudiosNow();
_cachedStudios = fresh;
_lastUpdate = DateTime.UtcNow;
return fresh;
}
}
private static string NormalizeStudioName(string name)
{
if (string.IsNullOrWhiteSpace(name)) return null;
var s = name.Trim().TrimEnd('.');
string mapped;
if (AliasMap.TryGetValue(s, out mapped))
return mapped;
while (s.IndexOf(" ", StringComparison.Ordinal) >= 0)
s = s.Replace(" ", " ");
return s;
}
public object Get(TestRequest _)
{
try
{
_logger.Info("[StudioDashboard] Test endpoint called successfully");
return new {
Status = "OK",
Message = "StudioDashboard API is working",
Timestamp = DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss UTC"),
PluginVersion = "1.0.0"
};
}
catch (Exception ex)
{
_logger.Error("[StudioDashboard] Error in Test endpoint: {0}", ex);
return new { Status = "Error", Message = ex.Message };
}
}
public object Get(GetStudios _)
{
try
{
_logger.Info("[StudioDashboard] GetStudios called");
var result = GetStudiosCached();
_logger.Info("[StudioDashboard] Returning {0} cached studios", result.Count);
return result;
}
catch (Exception ex)
{
_logger.Error("[StudioDashboard] Error in GetStudios: {0}", ex);
return new List<StudioDto>();
}
}
public object Get(GetStudiosWithLogos req)
{
try
{
_logger.Info("[StudioDashboard] GetStudiosWithLogos called with Filter={0}, Q={1}, Top={2}",
req.Filter ?? "null", req.Q ?? "null", req.Top?.ToString() ?? "null");
var allStudios = QueryStudiosWithLogosNow();
_logger.Info("[StudioDashboard] Got {0} studios from query", allStudios.Count);
if (!string.IsNullOrWhiteSpace(req.Filter))
{
switch (req.Filter.ToLower())
{
case "streaming":
allStudios = allStudios.Where(s => s.IsStreamingService).ToList();
_logger.Info("[StudioDashboard] Filtered to {0} streaming services", allStudios.Count);
break;
case "traditional":
allStudios = allStudios.Where(s => !s.IsStreamingService).ToList();
_logger.Info("[StudioDashboard] Filtered to {0} traditional studios", allStudios.Count);
break;
}
}
if (!string.IsNullOrWhiteSpace(req.Q))
{
var query = req.Q.ToLower();
allStudios = allStudios.Where(s => s.Studio.ToLower().Contains(query)).ToList();
_logger.Info("[StudioDashboard] Filtered by query '{0}' to {1} studios", req.Q, allStudios.Count);
}
if (req.Top.HasValue && req.Top.Value > 0)
{
allStudios = allStudios.Take(req.Top.Value).ToList();
_logger.Info("[StudioDashboard] Limited to top {0} studios", req.Top.Value);
}
_logger.Info("[StudioDashboard] Returning {0} studios", allStudios.Count);
return allStudios;
}
catch (Exception ex)
{
_logger.Error("[StudioDashboard] Error in GetStudiosWithLogos: {0}", ex);
return new List<StreamingStudioDto>();
}
}
public object Get(GetStudiosNormalized req)
{
try
{
_logger.Info("[StudioDashboard] GetStudiosNormalized called with Q={0}, Top={1}",
req.Q ?? "null", req.Top?.ToString() ?? "null");
var allStudios = QueryStudiosWithLogosNow();
if (!string.IsNullOrWhiteSpace(req.Q))
{
var query = req.Q.ToLower();
allStudios = allStudios.Where(s => s.Studio.ToLower().Contains(query)).ToList();
_logger.Info("[StudioDashboard] Filtered by query '{0}' to {1} studios", req.Q, allStudios.Count);
}
if (req.Top.HasValue && req.Top.Value > 0)
{
allStudios = allStudios.Take(req.Top.Value).ToList();
_logger.Info("[StudioDashboard] Limited to top {0} studios", req.Top.Value);
}
_logger.Info("[StudioDashboard] Returning {0} normalized studios", allStudios.Count);
return allStudios;
}
catch (Exception ex)
{
_logger.Error("[StudioDashboard] Error in GetStudiosNormalized: {0}", ex);
return new List<StreamingStudioDto>();
}
}
public object Get(ExportJsonRequest _)
{
return GetStudiosCached();
}
public string Get(ExportCsvRequest _)
{
var rows = GetStudiosCached();
var result = new System.Text.StringBuilder();
result.AppendLine("Studio,Count");
foreach (var r in rows)
{
var studio = (r.Studio ?? "").Replace("\"", "\"\"");
result.Append('"');
result.Append(studio);
result.Append('"');
result.Append(',');
result.Append(r.Count);
result.AppendLine();
}
return result.ToString();
}
public object Post(SaveExportRequest req)
{
string baseDir = "";
try { baseDir = Plugin.Instance.Configuration.ExportDirectory; } catch { baseDir = ""; }
if (string.IsNullOrWhiteSpace(baseDir))
{
baseDir = System.IO.Path.Combine(_appPaths.DataPath, "plugins", "StudioDashboard", "exports");
}
Directory.CreateDirectory(baseDir);
var rows = GetStudiosCached();
var ts = DateTime.Now.ToString("yyyyMMdd-HHmmss");
if (string.Equals(req.Format, "csv", StringComparison.OrdinalIgnoreCase))
{
var path = System.IO.Path.Combine(baseDir, "studios-" + ts + ".csv");
var csvContent = new System.Text.StringBuilder();
csvContent.AppendLine("Studio,Count");
foreach (var r in rows)
{
var studio = (r.Studio ?? "").Replace("\"", "\"\"");
csvContent.Append('"');
csvContent.Append(studio);
csvContent.Append('"');
csvContent.Append(',');
csvContent.Append(r.Count);
csvContent.AppendLine();
}
File.WriteAllText(path, csvContent.ToString());
return new { Saved = true, Path = path };
}
else
{
var path = System.IO.Path.Combine(baseDir, "studios-" + ts + ".json");
var jsonContent = new System.Text.StringBuilder();
jsonContent.Append('[');
for (int i = 0; i < rows.Count; i++)
{
var r = rows[i];
var studio = (r.Studio ?? "").Replace("\\", "\\\\").Replace("\"", "\\\"");
jsonContent.Append("{\"Studio\":\"");
jsonContent.Append(studio);
jsonContent.Append("\",\"Count\":");
jsonContent.Append(r.Count);
jsonContent.Append("}");
if (i < rows.Count - 1) jsonContent.Append(',');
}
jsonContent.Append(']');
File.WriteAllText(path, jsonContent.ToString());
return new { Saved = true, Path = path };
}
}
public object Post(SyncCollectionsRequest _)
{
try
{
_logger.Info("[StudioDashboard] Manueller Collections-Sync gestartet");
var task = new CreateStudioCollectionsTask(_libraryManager, _collectionManager, _logger);
Task.Run(() => task.Execute(CancellationToken.None, new Progress<double>(d => { })));
_logger.Info("[StudioDashboard] Collections-Sync gestartet (asynchron)");
return new { Started = true, Message = "Collections-Synchronisation gestartet." };
}
catch (Exception ex)
{
_logger.Error("[StudioDashboard] Fehler beim manuellen Collections-Sync: {0}", ex);
return new { Started = false, Message = "Fehler: " + ex.Message };
}
}
}
public class CreateStudioCollectionsTask
{
private readonly ILibraryManager _libraryManager;
private readonly ICollectionManager _collectionManager;
private readonly ILogger _logger;
public CreateStudioCollectionsTask(ILibraryManager libraryManager, ICollectionManager collectionManager, ILogger logger)
{
_libraryManager = libraryManager;
_collectionManager = collectionManager;
_logger = logger;
}
public Task Execute(CancellationToken cancellationToken, IProgress<double> progress)
{
return Task.Run(() => ExecuteSync(cancellationToken, progress));
}
private void ExecuteSync(CancellationToken cancellationToken, IProgress<double> progress)
{
try
{
_logger.Info("[StudioDashboard] Starte Studio-Collections Erstellung...");
var items = _libraryManager.GetItemList(new InternalItemsQuery
{
IncludeItemTypes = new[] { typeof(Movie).Name, typeof(Series).Name },
Recursive = true
});
var config = Plugin.Instance?.Configuration;
bool enableCollections = config?.EnableStudioCollections ?? true;
bool includeStreaming = config?.ShowStreamingServicesOnly ?? false;
int maxStudios = config?.TopStudiosForCollections ?? 20;
if (!enableCollections)
{
_logger.Info("[StudioDashboard] Studio-Collections sind deaktiviert");
return;
}
// Streaming Services die wir unterstützen
var supportedServices = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
"Netflix", "Apple", "Amazon", "Disney", "HBO", "Sony", "Paramount",
"Peacock", "Hulu", "Showtime", "Starz"
};
var studiosWithItems = items
.Where(i => i.Studios != null && i.Studios.Any())
.SelectMany(i => i.Studios.Select(s => new { Studio = NormalizeStudioName(s), Item = i }))
.Where(x => !string.IsNullOrWhiteSpace(x.Studio))
.GroupBy(x => x.Studio)
.Where(g => includeStreaming ? supportedServices.Contains(g.Key) : true)
.OrderByDescending(g => g.Count())
.Take(maxStudios)
.ToList();
progress?.Report(10);
int processedCount = 0;
foreach (var studioGroup in studiosWithItems)
{
if (cancellationToken.IsCancellationRequested) break;
try
{
var studioName = studioGroup.Key;
var studioItems = studioGroup.Select(x => x.Item).ToList();
var collectionName = $"{config?.CollectionPrefix ?? ""}{studioName}".Trim();
// Prüfe ob Collection bereits existiert
var existingCollection = _libraryManager.GetItemList(new InternalItemsQuery
{
IncludeItemTypes = new[] { "BoxSet" },
Name = collectionName
}).FirstOrDefault();
if (existingCollection != null)
{
_logger.Debug("[StudioDashboard] Collection '{0}' bereits vorhanden, überspringe", collectionName);
}
else
{
// Vereinfachte Collection-Erstellung
try
{
// Nutze die einfachste verfügbare API
_logger.Info("[StudioDashboard] Collection '{0}' wird erstellt mit {1} Items", collectionName, studioItems.Count);
// Erstelle Collection über Library Manager falls verfügbar
if (_libraryManager.GetType().GetMethods().Any(m => m.Name == "CreateCollection"))
{
var collection = (BaseItem)_libraryManager.GetType()
.GetMethod("CreateCollection")
?.Invoke(_libraryManager, new object[] { collectionName, studioItems.ToArray() });
if (collection != null)
{
_logger.Info("[StudioDashboard] Collection '{0}' erfolgreich erstellt", collectionName);
}
}
else
{
_logger.Debug("[StudioDashboard] Collection-API nicht verfügbar für '{0}'", collectionName);
}
}
catch (Exception collEx)
{
_logger.Error("[StudioDashboard] Fehler beim Erstellen der Collection '{0}': {1}", collectionName, collEx.Message);
}
}
}
catch (Exception ex)
{
_logger.Error("[StudioDashboard] Fehler beim Verarbeiten des Studios '{0}': {1}", studioGroup.Key, ex.Message);
}
processedCount++;
progress?.Report(10 + (80.0 * processedCount / studiosWithItems.Count));
}
progress?.Report(100);
_logger.Info("[StudioDashboard] Collections-Erstellung abgeschlossen. {0} Studios verarbeitet", processedCount);
}
catch (Exception ex)
{
_logger.Error("[StudioDashboard] Fehler bei Collections-Erstellung: {0}", ex);
throw;
}
}
private static string NormalizeStudioName(string name)
{
if (string.IsNullOrWhiteSpace(name)) return null;
var aliasMap = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
{
{ "Apple Studios", "Apple" },
{ "Apple TV+", "Apple" },
{ "Apple TV Plus", "Apple" },
{ "Amazon MGM Studios", "Amazon" },
{ "Prime Video", "Amazon" },
{ "Netflix", "Netflix" },
{ "Disney+", "Disney" },
{ "Walt Disney Pictures", "Disney" },
{ "HBO Max", "HBO" },
{ "Sony Pictures", "Sony" },
{ "Paramount+", "Paramount" },
{ "Paramount Pictures", "Paramount" }
};
var s = name.Trim().TrimEnd('.');
if (aliasMap.TryGetValue(s, out string mapped))
return mapped;
while (s.IndexOf(" ", StringComparison.Ordinal) >= 0)
s = s.Replace(" ", " ");
return s;
}
}
}