Beispiel #1
0
 private void aPIToolStripMenuItem_Click(object sender, EventArgs e)
 {
     using (var apiForm = new ApiForm())
     {
         apiForm.ShowDialog(this);
     }
 }
Beispiel #2
0
        private async Task GetNewIDAsync(int movieId)
        {
            if (string.IsNullOrEmpty(Configs.Settings.ApiKey))
            {
                using (var apiForm = new ApiForm())
                {
                    if (apiForm.ShowDialog(this) == DialogResult.OK)
                    {
                        UpdateComboboxMovieId(false);
                    }
                    else
                    {
                        return;
                    }
                }
            }

            // check if still null then return...
            if (string.IsNullOrEmpty(Configs.Settings.ApiKey))
            {
                MessageBox.Show("Api key not found!\r\nPlease sign up https://www.themoviedb.org/account/signup",
                                "Api key", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            //var guest = await _client.AuthenticationCreateGuestSessionAsync();

            _client = _client ?? new TMDbClient(Configs.Settings.ApiKey, true);

            ChangeControlsState(false);

            // invalid movie id
            if (movieId <= 0)
            {
                using (var getMovieID = new GetMovieID(_client))
                {
                    if (getMovieID.ShowDialog(this) == DialogResult.OK)
                    {
                        UpdateComboboxMovieId(true);
                    }
                    else
                    {
                        ChangeControlsState(true);
                    }
                    return;
                }
            }

            string movieIdString = comboBoxMovieID.Text;

            if (string.IsNullOrEmpty(movieIdString))
            {
                ChangeControlsState(true);
                return;
            }

            var movie = await _client.GetMovieAsync(movieId, MovieMethods.Credits).ConfigureAwait(true);

            HashSet <string> names = null;

            foreach (string name in movie.Credits.Cast.SelectMany(cast => cast.Character.Split(' ')))
            {
                names = names ?? new HashSet <string>();

                string tempName = name.Trim();
                tempName = tempName.Trim('\'', '"');
                tempName = tempName.Trim();

                if (string.IsNullOrEmpty(tempName))
                {
                    continue;
                }
                if (tempName.StartsWith('#'))
                {
                    continue;
                }
                if (tempName.Length == 1)
                {
                    continue;
                }
                if (tempName.StartsWith('('))
                {
                    continue;
                }
                // ignore nouns
                if (Configs.Settings.IgnoreWords?.Contains(tempName.ToLower()) == true)
                {
                    continue;
                }
                names.Add(tempName);
            }

            // TODO: Hack MAIN and find way to send these names to casing form

            if (names.Count == 0)
            {
                return;
            }

            UpdateListView(names);

            // invoke SubtitleEdit method for casing
            DoCasingViaAPI(names.ToList());
            ChangeControlsState(true);
        }