コード例 #1
0
        private static Dictionary <string, object> CreateTagDictionaryFromSerieBasedOnAttributes <TInfluxRow>(
            SeriesResult series,
            IReadOnlyDictionary <string, PropertyExpressionInfo <TInfluxRow> > propertyMap)
        {
            Dictionary <string, object> tags = new Dictionary <string, object>();

            if (series.Tags != null)
            {
                foreach (var kvp in series.Tags)
                {
                    object value;
                    if (!string.IsNullOrEmpty(kvp.Value))
                    {
                        PropertyExpressionInfo <TInfluxRow> property;
                        if (propertyMap.TryGetValue(kvp.Key, out property))
                        {
                            // we know this is either an enum or a string
                            if (property.IsEnum)
                            {
                                Enum valueAsEnum;
                                if (property.StringToEnum.TryGetValue(kvp.Value, out valueAsEnum))
                                {
                                    value = valueAsEnum;
                                }
                                else
                                {
                                    // could not find the value, simply use the string representation
                                    value = kvp.Value;
                                }
                            }
                            else
                            {
                                // since kvp.Value is just a string, so go for it
                                value = Convert.ChangeType(kvp.Value, property.Type, CultureInfo.InvariantCulture);
                            }
                        }
                        else
                        {
                            value = kvp.Value;
                        }
                    }
                    else
                    {
                        value = null;
                    }

                    tags.Add(kvp.Key, value);
                }
            }
            return(tags);
        }
コード例 #2
0
ファイル: TmdbSeriesProvider.cs プロジェクト: zjklee/jellyfin
        internal async Task DownloadSeriesInfo(string id, string preferredMetadataLanguage, CancellationToken cancellationToken)
        {
            SeriesResult mainResult = await FetchMainResult(id, preferredMetadataLanguage, cancellationToken).ConfigureAwait(false);

            if (mainResult == null)
            {
                return;
            }

            var dataFilePath = GetDataFilePath(id, preferredMetadataLanguage);

            Directory.CreateDirectory(Path.GetDirectoryName(dataFilePath));

            _jsonSerializer.SerializeToFile(mainResult, dataFilePath);
        }
コード例 #3
0
        private async Task GetWatchedEpisodes()
        {
            SeriesResult <UserShowWatch> result = await AppGlobal.Db.UserShowWatchListAsync(MyViewModel.MyShow);

            MyViewModel.MyShow.EpisodesWatched = result.ListData;

            foreach (Episode episode in MyViewModel.MyShow.Episodes)
            {
                UserShowWatch watch = MyViewModel.MyShow.EpisodesWatched.SingleOrDefault(x => x.SeasonNo == episode.AiredSeason && x.EpisodeNo == episode.AiredEpisodeNumber);

                if (watch != null)
                {
                    episode.Watched = true;
                }
            }
        }
コード例 #4
0
        protected private IEnumerable <SeriesResult> GetSeriesById(IEnumerable <int> ids, bool debugging)
        {
            foreach (int id in ids)
            {
                SeriesResult sr = base.SendSonarrGet <SeriesResult>(base.FormatWithId(id));
                if (sr != null)
                {
                    if (debugging)
                    {
                        base.WriteFormatDebug("Found series with ID \"{0}\" - {1}", id, sr.CleanTitle);
                    }

                    yield return(sr);
                }
            }
        }
コード例 #5
0
        private async void btn_DeleteAccount_Click(object sender, RoutedEventArgs e)
        {
            if (MessageBox.Show("Are you sure?") == MessageBoxResult.OK)
            {
                SeriesResult <User> result = await AppGlobal.Db.UserDeleteAsync();

                if (result.Result == SQLResult.Success)
                {
                    Properties.Settings.Default.UserRemember = false;
                    Properties.Settings.Default.Save();

                    MessageBox.Show("Your account has been deleted.");

                    DialogResult = true;

                    Close();
                }
                else
                {
                    MessageBox.Show("Something went wrong.");
                }
            }
        }
コード例 #6
0
        private async Task <bool> EpisodeWatchedToggle(int episodeNumber)
        {
            try
            {
                UserShowWatch record = MyViewModel.MyShow
                                       .EpisodesWatched
                                       .SingleOrDefault(x => x.SeasonNo == MyViewModel.ViewingSeason && x.EpisodeNo == episodeNumber);

                if (record == null)
                {
                    UserShowWatch newRecord = new UserShowWatch
                    {
                        UserShowID = MyViewModel.MyShow.UserShowID,
                        SeasonNo   = MyViewModel.ViewingSeason,
                        EpisodeNo  = episodeNumber
                    };
                    SeriesResult <UserShowWatch> result = await AppGlobal.Db.UserShowWatchAddAsync(newRecord);

                    MyViewModel.MyShow.EpisodesWatched.Add(result.Data);
                }
                else
                {
                    SeriesResult <UserShowWatch> result = await AppGlobal.Db.UserShowWatchDeleteAsync(record);

                    MyViewModel.MyShow.EpisodesWatched.Remove(record);
                }

                return(true);
            }
            catch (Exception ex)
            {
                ErrorMethods.LogError(ex.Message);
            }

            return(false);
        }
コード例 #7
0
        private static async Task AddValuesToInfluxSeriesByInterfaceAsync <TInfluxRow, TTimestamp>(
            InfluxSeries <TInfluxRow> influxSerie,
            SeriesResult series,
            InfluxClient client,
            string db,
            bool allowMetadataQuerying,
            InfluxRowTypeInfo <TInfluxRow> propertyMap,
            InfluxQueryOptions options,
            ITimestampParser <TTimestamp> timestampParser)
            where TInfluxRow : IInfluxRow <TTimestamp>, new()
        {
            // Values will be null, if there are no entries in the result set
            if (series.Values != null)
            {
                var precision  = options.Precision;
                var name       = series.Name;
                var columns    = series.Columns;
                var setters    = new Action <TInfluxRow, string, object> [columns.Count];
                var dataPoints = new List <TInfluxRow>();
                // Get metadata information about the measurement we are querying, as we dont know
                // which columns are tags/fields otherwise

                DatabaseMeasurementInfo meta = null;
                if (allowMetadataQuerying)
                {
                    meta = await client.GetMetaInformationAsync(db, name, options.MetadataExpiration).ConfigureAwait(false);
                }

                for (int i = 0; i < columns.Count; i++)
                {
                    var columnName = columns[i];

                    if (!allowMetadataQuerying)
                    {
                        setters[i] = (row, fieldName, value) => row.SetField(fieldName, value);
                    }
                    else if (columnName == InfluxConstants.TimeColumn)
                    {
                        setters[i] = (row, timeName, value) => row.SetTimestamp(timestampParser.ToTimestamp(options.Precision, value));
                    }
                    else if (meta.Tags.Contains(columnName))
                    {
                        setters[i] = (row, tagName, value) => row.SetTag(tagName, (string)value);
                    }
                    else
                    {
                        setters[i] = (row, fieldName, value) => row.SetField(fieldName, value);
                    }
                }

                // constructs the IInfluxRows using the IInfluxRow interface
                foreach (var values in series.Values)
                {
                    var dataPoint = new TInfluxRow();
                    propertyMap.SetMeasurementName(name, dataPoint);

                    // go through all values that are stored as a List<List<object>>
                    for (int i = 0; i < values.Count; i++)
                    {
                        var value = values[i]; // TODO: What about NULL values? Are they treated as empty strings or actual nulls?
                        if (value != null)
                        {
                            setters[i](dataPoint, columns[i], value);
                        }
                    }

                    dataPoints.Add(dataPoint);
                }

                influxSerie.Rows.AddRange(dataPoints);
            }
        }
コード例 #8
0
        private static void AddValuesToInfluxSeriesByAttributes <TInfluxRow, TTimestamp>(
            InfluxSeries <TInfluxRow> influxSerie,
            SeriesResult series,
            InfluxRowTypeInfo <TInfluxRow> propertyMap,
            InfluxQueryOptions options,
            ITimestampParser <TTimestamp> timestampParser)
            where TInfluxRow : new()
        {
            // Values will be null, if there are no entries in the result set
            if (series.Values != null)
            {
                var dataPoints = new List <TInfluxRow>();

                var precision = options.Precision;
                var columns   = series.Columns;
                var name      = series.Name;

                // construct an array of properties based on the same indexing as the columns returned by the query
                var properties = new PropertyExpressionInfo <TInfluxRow> [columns.Count];
                for (int i = 0; i < columns.Count; i++)
                {
                    PropertyExpressionInfo <TInfluxRow> propertyInfo;
                    if (propertyMap.All.TryGetValue(columns[i], out propertyInfo))
                    {
                        properties[i] = propertyInfo;
                    }
                }

                foreach (var values in series.Values)
                {
                    // construct the data points based on the attributes
                    var dataPoint = new TInfluxRow();
                    propertyMap.SetMeasurementName(name, dataPoint);

                    for (int i = 0; i < values.Count; i++)
                    {
                        var value    = values[i]; // TODO: What about NULL values? Are they treated as empty strings or actual nulls?
                        var property = properties[i];

                        // set the value based on the property, if both the value and property is not null
                        if (property != null)
                        {
                            if (value != null)
                            {
                                if (property.Key == InfluxConstants.TimeColumn)
                                {
                                    property.SetValue(dataPoint, timestampParser.ToTimestamp(options.Precision, value));
                                }
                                else if (property.IsDateTime)
                                {
                                    property.SetValue(dataPoint, DateTime.Parse((string)value, CultureInfo.InvariantCulture, OnlyUtcStyles));
                                }
                                else if (property.IsEnum)
                                {
                                    property.SetValue(dataPoint, property.GetEnumValue(value));
                                }
                                else
                                {
                                    // will throw exception if types does not match up
                                    property.SetValue(dataPoint, Convert.ChangeType(value, property.Type, CultureInfo.InvariantCulture));
                                }
                            }
                        }
                    }

                    dataPoints.Add(dataPoint);
                }

                influxSerie.Rows.AddRange(dataPoints);
            }
        }
コード例 #9
0
ファイル: TmdbSeriesProvider.cs プロジェクト: zjklee/jellyfin
        private void ProcessMainInfo(MetadataResult <Series> seriesResult, SeriesResult seriesInfo, string preferredCountryCode, TmdbSettingsResult settings)
        {
            var series = seriesResult.Item;

            series.Name          = seriesInfo.Name;
            series.OriginalTitle = seriesInfo.Original_Name;
            series.SetProviderId(MetadataProvider.Tmdb, seriesInfo.Id.ToString(_usCulture));

            string voteAvg = seriesInfo.Vote_Average.ToString(CultureInfo.InvariantCulture);

            if (float.TryParse(voteAvg, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out float rating))
            {
                series.CommunityRating = rating;
            }

            series.Overview = seriesInfo.Overview;

            if (seriesInfo.Networks != null)
            {
                series.Studios = seriesInfo.Networks.Select(i => i.Name).ToArray();
            }

            if (seriesInfo.Genres != null)
            {
                series.Genres = seriesInfo.Genres.Select(i => i.Name).ToArray();
            }

            series.HomePageUrl = seriesInfo.Homepage;

            series.RunTimeTicks = seriesInfo.Episode_Run_Time.Select(i => TimeSpan.FromMinutes(i).Ticks).FirstOrDefault();

            if (string.Equals(seriesInfo.Status, "Ended", StringComparison.OrdinalIgnoreCase))
            {
                series.Status  = SeriesStatus.Ended;
                series.EndDate = seriesInfo.Last_Air_Date;
            }
            else
            {
                series.Status = SeriesStatus.Continuing;
            }

            series.PremiereDate = seriesInfo.First_Air_Date;

            var ids = seriesInfo.External_Ids;

            if (ids != null)
            {
                if (!string.IsNullOrWhiteSpace(ids.Imdb_Id))
                {
                    series.SetProviderId(MetadataProvider.Imdb, ids.Imdb_Id);
                }

                if (ids.Tvrage_Id > 0)
                {
                    series.SetProviderId(MetadataProvider.TvRage, ids.Tvrage_Id.ToString(_usCulture));
                }

                if (ids.Tvdb_Id > 0)
                {
                    series.SetProviderId(MetadataProvider.Tvdb, ids.Tvdb_Id.ToString(_usCulture));
                }
            }

            var contentRatings = (seriesInfo.Content_Ratings ?? new ContentRatings()).Results ?? new List <ContentRating>();

            var ourRelease     = contentRatings.FirstOrDefault(c => string.Equals(c.Iso_3166_1, preferredCountryCode, StringComparison.OrdinalIgnoreCase));
            var usRelease      = contentRatings.FirstOrDefault(c => string.Equals(c.Iso_3166_1, "US", StringComparison.OrdinalIgnoreCase));
            var minimumRelease = contentRatings.FirstOrDefault();

            if (ourRelease != null)
            {
                series.OfficialRating = ourRelease.Rating;
            }
            else if (usRelease != null)
            {
                series.OfficialRating = usRelease.Rating;
            }
            else if (minimumRelease != null)
            {
                series.OfficialRating = minimumRelease.Rating;
            }

            if (seriesInfo.Videos != null && seriesInfo.Videos.Results != null)
            {
                foreach (var video in seriesInfo.Videos.Results)
                {
                    if ((video.Type.Equals("trailer", StringComparison.OrdinalIgnoreCase) ||
                         video.Type.Equals("clip", StringComparison.OrdinalIgnoreCase)) &&
                        video.Site.Equals("youtube", StringComparison.OrdinalIgnoreCase))
                    {
                        series.AddTrailerUrl($"http://www.youtube.com/watch?v={video.Key}");
                    }
                }
            }

            seriesResult.ResetPeople();
            var tmdbImageUrl = settings.images.GetImageUrl("original");

            if (seriesInfo.Credits != null)
            {
                if (seriesInfo.Credits.Cast != null)
                {
                    foreach (var actor in seriesInfo.Credits.Cast.OrderBy(a => a.Order))
                    {
                        var personInfo = new PersonInfo
                        {
                            Name      = actor.Name.Trim(),
                            Role      = actor.Character,
                            Type      = PersonType.Actor,
                            SortOrder = actor.Order
                        };

                        if (!string.IsNullOrWhiteSpace(actor.Profile_Path))
                        {
                            personInfo.ImageUrl = tmdbImageUrl + actor.Profile_Path;
                        }

                        if (actor.Id > 0)
                        {
                            personInfo.SetProviderId(MetadataProvider.Tmdb, actor.Id.ToString(CultureInfo.InvariantCulture));
                        }

                        seriesResult.AddPerson(personInfo);
                    }
                }

                if (seriesInfo.Credits.Crew != null)
                {
                    var keepTypes = new[]
                    {
                        PersonType.Director,
                        PersonType.Writer,
                        PersonType.Producer
                    };

                    foreach (var person in seriesInfo.Credits.Crew)
                    {
                        // Normalize this
                        var type = TmdbUtils.MapCrewToPersonType(person);

                        if (!keepTypes.Contains(type, StringComparer.OrdinalIgnoreCase) &&
                            !keepTypes.Contains(person.Job ?? string.Empty, StringComparer.OrdinalIgnoreCase))
                        {
                            continue;
                        }

                        seriesResult.AddPerson(new PersonInfo
                        {
                            Name = person.Name.Trim(),
                            Role = person.Job,
                            Type = type
                        });
                    }
                }
            }
        }
コード例 #10
0
        private async void Btn_Register_Click(object sender, RoutedEventArgs e)
        {
            lbl_Register_Info.Foreground = Brushes.Red;
            lbl_Register_Info.Content    = "";

            string Username        = txt_Register_Username.Text.Trim();
            string Email           = txt_Register_Email.Text.Trim();
            string Name            = txt_Register_Name.Text.Trim();
            string Password        = txt_Register_Password.Password;
            string ConfirmPassword = txt_Register_ConfirmPassword.Password;

            // Validation checks
            if (string.IsNullOrEmpty(Username))
            {
                lbl_Register_Info.Content = "Username is required";
                txt_Register_Username.Focus();

                return;
            }
            else if (Username.Contains(' '))
            {
                lbl_Register_Info.Content = "Username is invalid";
                txt_Register_Username.Focus();

                return;
            }
            else if (string.IsNullOrEmpty(Email))
            {
                lbl_Register_Info.Content = "Email is required";
                txt_Register_Email.Focus();

                return;
            }
            else if (!CommonMethods.IsValidEmail(Email))
            {
                lbl_Register_Info.Content = "Email is invalid";
                txt_Register_Email.Focus();

                return;
            }
            else if (string.IsNullOrEmpty(Password))
            {
                lbl_Register_Info.Content = "Password is required";
                txt_Register_Password.Focus();

                return;
            }
            else if (string.IsNullOrEmpty(ConfirmPassword))
            {
                lbl_Register_Info.Content = "Confirm password is required";
                txt_Register_ConfirmPassword.Focus();

                return;
            }
            else if (Password != ConfirmPassword)
            {
                lbl_Register_Info.Content = "Passwords do not match";
                txt_Register_Password.Focus();

                return;
            }

            SeriesResult <User> result = await MethodCollection.UserRegisterAsync(Username, Email, Name, Password);

            if (result.Result == SQLResult.RegistrationSuccessful)
            {
                lbl_Register_Info.Foreground = Brushes.Green;
                lbl_Register_Info.Content    = "Registration successful!";

                MyViewModel.SetLoginStatus(Brushes.Green, "Registration successful!");

                txt_Register_Username.Text            = "";
                txt_Register_Name.Text                = "";
                txt_Register_Email.Text               = "";
                txt_Register_Password.Password        = "";
                txt_Register_ConfirmPassword.Password = "";

                tc.SelectedIndex = 0;
                txt_Login_UsernameOrEmail.Focus();
            }
            else if (result.Result == SQLResult.UsernameAlreadyRegistered)
            {
                lbl_Register_Info.Content = "Username already in use";

                txt_Register_Username.Focus();
                txt_Register_Username.SelectAll();
            }
            else if (result.Result == SQLResult.EmailAlreadyRegistered)
            {
                lbl_Register_Info.Content = "Email already in use";

                txt_Register_Email.Focus();
                txt_Register_Email.SelectAll();
            }
            else if (result.Result == SQLResult.ErrorHasOccured)
            {
                lbl_Register_Info.Content = "An unexpected error has occured";

                txt_Register_Username.Focus();
            }
        }
コード例 #11
0
 protected virtual IEnumerable <Serie> GetSeries(SeriesResult result)
 {
     Validate.IsNotNull(result, "result");
     return(result.Series != null?result.Series.ToList() : new List <Serie>());
 }
コード例 #12
0
        public static SeriesResult ConvertToSeriesResult(JToken jtoken, bool fromSearch = false)
        {
            SeriesResult series = JsonConvert.DeserializeObject <SeriesResult>(JsonConvert.SerializeObject(jtoken, Serializer), Serializer);

            return(series);
        }
コード例 #13
0
        private async void Btn_Accept_Click(object sender, RoutedEventArgs e)
        {
            //ShowOverlay();

            List <string> changes = new List <string>();

            #region General

            if (AppGlobal.Settings.UseListedName != cb_ListedName.IsChecked || AppGlobal.Settings.IgnoreBracketsInNames != cb_IgnoreBrackets.IsChecked)
            {
                changes.Add("ReloadView");
            }

            AppGlobal.Settings.IgnoreBracketsInNames = MyViewModel.IgnoreBrackets;
            AppGlobal.Settings.UseListedName         = MyViewModel.UseListedName;
            AppGlobal.Settings.StartOnWindowsStart   = MyViewModel.StartOnWindowsStart;

            AppGlobal.Settings.DateFormat           = MyViewModel.DateFormat;
            AppGlobal.Settings.DefaultSortColumn    = MyViewModel.DefaultSort;
            AppGlobal.Settings.DefaultSortDirection = MyViewModel.DefaultSortDirection;

            // Theme
            AppGlobal.Settings.Theme.Type    = MyViewModel.Theme;
            AppGlobal.Settings.Theme.IsDark  = MyViewModel.IsDark;
            AppGlobal.Settings.Theme.Primary = MyViewModel.Primary;
            AppGlobal.Settings.Theme.Accent  = MyViewModel.Accent;
            #endregion

            #region Extra
            if (AppGlobal.Settings.LocalSeriesFolder != MyViewModel.LocalSeriesFolder)
            {
                AppGlobal.Settings.LocalSeriesFolder = MyViewModel.LocalSeriesFolder;

                changes.Add("UpdateFolders");
            }

            if (categoriesToAdd.Count > 0 || categoriesToDelete.Count > 0)
            {
                if (categoriesToAdd.Count > 0)
                {
                    SeriesResult <Category> r = await AppGlobal.Db.UserCategoryAddMultipleAsync(categoriesToAdd);

                    if (r.Result == SQLResult.ErrorHasOccured)
                    {
                        MessageBox.Show("Failed to add new categories");
                    }
                }

                if (categoriesToDelete.Count > 0)
                {
                    SeriesResult <Category> r = await AppGlobal.Db.UserCategoryDeleteMutlipleAsync(categoriesToDelete);

                    if (r.Result == SQLResult.ErrorHasOccured)
                    {
                        MessageBox.Show("Failed to delete categories");
                    }
                }

                AppGlobal.User.Categories = MyViewModel.Categories.ToList();
                changes.Add("UpdateCategory");
            }
            #endregion

            AppGlobal.Settings.Save();

            CloseHandler(changes);

            Close();
        }