|
10 | 10 | using Shoko.Models.Enums;
|
11 | 11 | using Shoko.Server.Extensions;
|
12 | 12 | using Shoko.Server.ImageDownload;
|
| 13 | +using Shoko.Server.Models; |
13 | 14 | using Shoko.Server.Repositories;
|
14 | 15 | using Shoko.Server.Utilities;
|
15 | 16 |
|
@@ -65,6 +66,13 @@ public class Image
|
65 | 66 | /// </summary>
|
66 | 67 | public bool Disabled { get; set; }
|
67 | 68 |
|
| 69 | + /// <summary> |
| 70 | + /// Series info for the image, currently only set when sending a random |
| 71 | + /// image. |
| 72 | + /// </summary> |
| 73 | + [JsonProperty(NullValueHandling = NullValueHandling.Ignore)] |
| 74 | + public ImageSeriesInfo? Series { get; set; } = null; |
| 75 | + |
68 | 76 | public Image(int id, ImageEntityType type, bool preferred = false, bool disabled = false) : this(id.ToString(),
|
69 | 77 | type, preferred, disabled)
|
70 | 78 | {
|
@@ -537,6 +545,97 @@ internal static ImageSource GetRandomImageSource(ImageType imageType)
|
537 | 545 | };
|
538 | 546 | }
|
539 | 547 |
|
| 548 | + internal static SVR_AnimeSeries? GetFirstSeriesForImage(ImageEntityType imageType, int imageID) |
| 549 | + { |
| 550 | + switch (imageType) |
| 551 | + { |
| 552 | + case ImageEntityType.AniDB_Cover: |
| 553 | + return RepoFactory.AnimeSeries.GetByAnimeID(imageID); |
| 554 | + case ImageEntityType.TvDB_Banner: |
| 555 | + { |
| 556 | + var tvdbWideBanner = RepoFactory.TvDB_ImageWideBanner.GetByID(imageID); |
| 557 | + if (tvdbWideBanner == null) |
| 558 | + return null; |
| 559 | + |
| 560 | + var xref = RepoFactory.CrossRef_AniDB_TvDB.GetByTvDBID(tvdbWideBanner.SeriesID) |
| 561 | + .FirstOrDefault(); |
| 562 | + if (xref == null) |
| 563 | + return null; |
| 564 | + |
| 565 | + return RepoFactory.AnimeSeries.GetByAnimeID(xref.AniDBID); |
| 566 | + } |
| 567 | + case ImageEntityType.TvDB_Cover: |
| 568 | + { |
| 569 | + var tvdbPoster = RepoFactory.TvDB_ImagePoster.GetByID(imageID); |
| 570 | + if (tvdbPoster == null) |
| 571 | + return null; |
| 572 | + |
| 573 | + var xref = RepoFactory.CrossRef_AniDB_TvDB.GetByTvDBID(tvdbPoster.SeriesID) |
| 574 | + .FirstOrDefault(); |
| 575 | + if (xref == null) |
| 576 | + return null; |
| 577 | + |
| 578 | + return RepoFactory.AnimeSeries.GetByAnimeID(xref.AniDBID); |
| 579 | + } |
| 580 | + case ImageEntityType.TvDB_FanArt: |
| 581 | + { |
| 582 | + var tvdbFanart = RepoFactory.TvDB_ImageFanart.GetByID(imageID); |
| 583 | + if (tvdbFanart == null) |
| 584 | + return null; |
| 585 | + |
| 586 | + var xref = RepoFactory.CrossRef_AniDB_TvDB.GetByTvDBID(tvdbFanart.SeriesID) |
| 587 | + .FirstOrDefault(); |
| 588 | + if (xref == null) |
| 589 | + return null; |
| 590 | + |
| 591 | + return RepoFactory.AnimeSeries.GetByAnimeID(xref.AniDBID); |
| 592 | + } |
| 593 | + case ImageEntityType.TvDB_Episode: |
| 594 | + { |
| 595 | + var tvdbEpisode = RepoFactory.TvDB_Episode.GetByID(imageID); |
| 596 | + if (tvdbEpisode == null) |
| 597 | + return null; |
| 598 | + |
| 599 | + var xref = RepoFactory.CrossRef_AniDB_TvDB.GetByTvDBID(tvdbEpisode.SeriesID) |
| 600 | + .FirstOrDefault(); |
| 601 | + if (xref == null) |
| 602 | + return null; |
| 603 | + |
| 604 | + return RepoFactory.AnimeSeries.GetByAnimeID(xref.AniDBID); |
| 605 | + } |
| 606 | + case ImageEntityType.MovieDB_FanArt: |
| 607 | + { |
| 608 | + var tmdbFanart = RepoFactory.MovieDB_Fanart.GetByID(imageID); |
| 609 | + if (tmdbFanart == null) |
| 610 | + return null; |
| 611 | + |
| 612 | + // This will be slow as HELL. Why don't we have a lookup? |
| 613 | + var xref = RepoFactory.CrossRef_AniDB_Other.GetAll() |
| 614 | + .FirstOrDefault(xref => xref.CrossRefType == (int)CrossRefType.MovieDB && int.Parse(xref.CrossRefID) == tmdbFanart.MovieId); |
| 615 | + if (xref == null) |
| 616 | + return null; |
| 617 | + |
| 618 | + return RepoFactory.AnimeSeries.GetByAnimeID(xref.AnimeID); |
| 619 | + } |
| 620 | + case ImageEntityType.MovieDB_Poster: |
| 621 | + { |
| 622 | + var tmdbPoster = RepoFactory.MovieDB_Poster.GetByID(imageID); |
| 623 | + if (tmdbPoster == null) |
| 624 | + return null; |
| 625 | + |
| 626 | + // This will be slow as HELL. Why don't we have a lookup? |
| 627 | + var xref = RepoFactory.CrossRef_AniDB_Other.GetAll() |
| 628 | + .FirstOrDefault(xref => xref.CrossRefType == (int)CrossRefType.MovieDB && int.Parse(xref.CrossRefID) == tmdbPoster.MovieId); |
| 629 | + if (xref == null) |
| 630 | + return null; |
| 631 | + |
| 632 | + return RepoFactory.AnimeSeries.GetByAnimeID(xref.AnimeID); |
| 633 | + } |
| 634 | + default: |
| 635 | + return null; |
| 636 | + }; |
| 637 | + } |
| 638 | + |
540 | 639 | /// <summary>
|
541 | 640 | /// Image source.
|
542 | 641 | /// </summary>
|
@@ -606,6 +705,25 @@ public enum ImageType
|
606 | 705 | Static = 100
|
607 | 706 | }
|
608 | 707 |
|
| 708 | + public class ImageSeriesInfo |
| 709 | + { |
| 710 | + /// <summary> |
| 711 | + /// The shoko series id. |
| 712 | + /// </summary> |
| 713 | + public int ID { get; set; } |
| 714 | + |
| 715 | + /// <summary> |
| 716 | + /// The preferred series name for the user. |
| 717 | + /// </summary> |
| 718 | + public string Name { get; set; } |
| 719 | + |
| 720 | + public ImageSeriesInfo(int id, string name) |
| 721 | + { |
| 722 | + ID = id; |
| 723 | + Name = name; |
| 724 | + } |
| 725 | + } |
| 726 | + |
609 | 727 | /// <summary>
|
610 | 728 | /// Input models.
|
611 | 729 | /// </summary>
|
|
0 commit comments