Exemplo n.º 1
0
        public ActionResult EditFolder(ImportFolder folder)
        {
            if (!String.IsNullOrEmpty(folder.ImportFolderLocation) && folder.ImportFolderID != 0)
            {
                try
                {
                    // TODO Do this correctly without calling APIv1
                    if (folder.IsDropDestination == 1 && folder.IsDropSource == 1)
                    {
                        return(new APIMessage(409, "The Import Folder can't be both Destination and Source"));
                    }

                    if (folder.ImportFolderID == 0)
                    {
                        return(new APIMessage(409, "The Import Folder must have an ID"));
                    }
                    CL_Response <ImportFolder> response =
                        new ShokoServiceImplementation().SaveImportFolder(folder);

                    if (!string.IsNullOrEmpty(response.ErrorMessage))
                    {
                        return(new APIMessage(500, response.ErrorMessage));
                    }

                    return(APIStatus.OK());
                }
                catch
                {
                    return(APIStatus.InternalError());
                }
            }
            return(new APIMessage(400, "ImportFolderLocation and ImportFolderID missing"));
        }
Exemplo n.º 2
0
        public ActionResult AddFolder(ImportFolder folder)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (folder.ImportFolderLocation != string.Empty)
            {
                try
                {
                    // TODO Do this correctly without calling APIv1
                    CL_Response <ImportFolder> response = new ShokoServiceImplementation().SaveImportFolder(folder);

                    if (string.IsNullOrEmpty(response.ErrorMessage))
                    {
                        return(APIStatus.OK());
                    }
                    return(new APIMessage(500, response.ErrorMessage));
                }
                catch
                {
                    return(APIStatus.InternalError());
                }
            }
            return(new APIMessage(400, "Bad Request: The Folder path must not be Empty"));
        }
Exemplo n.º 3
0
        public ActionResult <Dictionary <string, object> > GetTraktCode()
        {
            var code = new ShokoServiceImplementation().GetTraktDeviceCode();

            if (code.UserCode == string.Empty)
            {
                return(APIStatus.InternalError("Trakt code doesn't exist on the server"));
            }

            Dictionary <string, object> result = new Dictionary <string, object>();

            result.Add("usercode", code.UserCode);
            result.Add("url", code.VerificationUrl);
            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Get Trakt code and url
        /// </summary>
        /// <returns></returns>
        private object GetTraktCode()
        {
            var code = new ShokoServiceImplementation().GetTraktDeviceCode();

            if (code.UserCode == string.Empty)
            {
                return(APIStatus.InternalError());
            }

            Dictionary <string, object> result = new Dictionary <string, object>();

            result.Add("usercode", code.UserCode);
            result.Add("url", code.VerificationUrl);
            return(result);
        }
Exemplo n.º 5
0
        void btnSave_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // An import folder cannot be both the drop source and the drop destination
                if (chkDropDestination.IsChecked.HasValue && chkDropSource.IsChecked.HasValue &&
                    chkDropDestination.IsChecked.Value &&
                    chkDropSource.IsChecked.Value)
                {
                    MessageBox.Show(Shoko.Commons.Properties.Resources.ImportFolders_SameFolder,
                                    Shoko.Commons.Properties.Resources.Error,
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                // The import folder location cannot be blank. Enter a valid path on OMM Server
                if (string.IsNullOrEmpty(txtImportFolderLocation.Text))
                {
                    MessageBox.Show(Shoko.Commons.Properties.Resources.ImportFolders_BlankImport,
                                    Shoko.Commons.Properties.Resources.Error,
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                    txtImportFolderLocation.Focus();
                    return;
                }

                ImportFolder contract = new ImportFolder();
                contract.ImportFolderID   = importFldr.ImportFolderID;
                contract.ImportFolderType = (int)(importFldr.CloudID.HasValue
                    ? ImportFolderType.Cloud
                    : ImportFolderType.HDD);
                contract.ImportFolderName     = "NA";
                contract.ImportFolderLocation = txtImportFolderLocation.Text.Trim();
                contract.IsDropDestination    = chkDropDestination.IsChecked.Value ? 1 : 0;
                contract.IsDropSource         = chkDropSource.IsChecked.Value ? 1 : 0;
                contract.IsWatched            = chkIsWatched.IsChecked.Value ? 1 : 0;
                if (comboProvider.SelectedIndex == 0)
                {
                    contract.CloudID = null;
                }
                else
                {
                    contract.CloudID = ((SVR_CloudAccount)comboProvider.SelectedItem).CloudID;
                }
                ShokoServiceImplementation imp      = new ShokoServiceImplementation();
                CL_Response <ImportFolder> response = imp.SaveImportFolder(contract);
                if (!string.IsNullOrEmpty(response.ErrorMessage))
                {
                    MessageBox.Show(response.ErrorMessage, Shoko.Commons.Properties.Resources.Error,
                                    MessageBoxButton.OK,
                                    MessageBoxImage.Error);
                }
                importFldr = null;
                ServerInfo.Instance.RefreshImportFolders();
            }
            catch (Exception ex)
            {
                Utils.ShowErrorMessage(ex);
            }

            this.DialogResult = true;
            this.Close();
        }
Exemplo n.º 6
0
        public static Video GenerateFromAnimeGroup(SVR_AnimeGroup grp, int userid, List <SVR_AnimeSeries> allSeries,
                                                   ISessionWrapper session = null)
        {
            CL_AnimeGroup_User cgrp = grp.GetUserContract(userid);
            int subgrpcnt           = grp.GetAllChildGroups().Count;

            if ((cgrp.Stat_SeriesCount == 1) && (subgrpcnt == 0))
            {
                SVR_AnimeSeries     ser    = ShokoServiceImplementation.GetSeriesForGroup(grp.AnimeGroupID, allSeries);
                CL_AnimeSeries_User cserie = ser?.GetUserContract(userid);
                if (cserie == null)
                {
                    return(null);
                }
                Video v = GenerateFromSeries(cserie, ser, ser.GetAnime(), userid, session);
                v.AirDate   = ser.AirDate;
                v.UpdatedAt = ser.LatestEpisodeAirDate.HasValue
                    ? ser.LatestEpisodeAirDate.Value.ToUnixTime()
                    : null;
                v.Group = cgrp;
                return(v);
            }
            else
            {
                SVR_AnimeSeries ser = grp.DefaultAnimeSeriesID.HasValue
                    ? allSeries.FirstOrDefault(a => a.AnimeSeriesID == grp.DefaultAnimeSeriesID.Value)
                    : allSeries.Find(a => a.AirDate != DateTime.MinValue);
                if (ser == null && allSeries.Count > 0)
                {
                    ser = allSeries[0];
                }
                CL_AnimeSeries_User cserie = ser?.GetUserContract(userid);
                Video v = FromGroup(cgrp, cserie, userid, subgrpcnt);
                v.Group     = cgrp;
                v.AirDate   = cgrp.Stat_AirDate_Min ?? DateTime.MinValue;
                v.UpdatedAt = cgrp.LatestEpisodeAirDate?.ToUnixTime();
                v.Rating    = (int)Math.Round((grp.AniDBRating / 100), 1);
                List <Tag> newTags = new List <Tag>();
                foreach (AniDB_Tag tag in grp.Tags)
                {
                    Tag      newTag   = new Tag();
                    TextInfo textInfo = new CultureInfo("en-US", false).TextInfo;
                    newTag.Value = textInfo.ToTitleCase(tag.TagName.Trim());
                    if (!newTags.Contains(newTag))
                    {
                        newTags.Add(newTag);
                    }
                }
                v.Genres = newTags;
                if (ser == null)
                {
                    return(v);
                }
                List <AnimeTitle> newTitles = ser.GetAnime()
                                              .GetTitles()
                                              .Select(title => new AnimeTitle
                {
                    Title    = title.Title,
                    Language = title.Language,
                    Type     = title.TitleType
                })
                                              .ToList();
                v.Titles = newTitles;

                v.Roles = new List <RoleTag>();

                //TODO Character implementation is limited in JMM, One Character, could have more than one Seiyuu
                if (ser.GetAnime()?.Contract?.AniDBAnime?.Characters != null)
                {
                    foreach (CL_AniDB_Character c in ser.GetAnime().Contract.AniDBAnime.Characters)
                    {
                        string       ch     = c?.CharName;
                        AniDB_Seiyuu seiyuu = c?.Seiyuu;
                        if (String.IsNullOrEmpty(ch))
                        {
                            continue;
                        }
                        RoleTag t = new RoleTag
                        {
                            Value = seiyuu?.SeiyuuName
                        };
                        if (seiyuu != null)
                        {
                            t.TagPicture = ConstructSeiyuuImage(null, seiyuu.AniDB_SeiyuuID);
                        }
                        t.Role            = ch;
                        t.RoleDescription = c?.CharDescription;
                        t.RolePicture     = ConstructCharacterImage(null, c.CharID);
                        v.Roles.Add(t);
                    }
                }
                if (cserie?.AniDBAnime?.AniDBAnime?.Fanarts != null)
                {
                    v.Fanarts = new List <Contract_ImageDetails>();
                    cserie?.AniDBAnime?.AniDBAnime?.Fanarts.ForEach(
                        a =>
                        v.Fanarts.Add(new Contract_ImageDetails
                    {
                        ImageID   = a.AniDB_Anime_DefaultImageID,
                        ImageType = a.ImageType
                    }));
                }
                if (cserie?.AniDBAnime?.AniDBAnime?.Banners == null)
                {
                    return(v);
                }
                v.Banners = new List <Contract_ImageDetails>();
                cserie?.AniDBAnime?.AniDBAnime?.Banners.ForEach(
                    a =>
                    v.Banners.Add(new Contract_ImageDetails
                {
                    ImageID   = a.AniDB_Anime_DefaultImageID,
                    ImageType = a.ImageType
                }));
                return(v);
            }
        }