private void SetMovieDetails(string responseFromServer) { MediaDetails mediaDetails; string jsonString; try { jsonString = responseFromServer; mediaDetails = JsonConvert.DeserializeObject <MediaDetails>(jsonString); } catch (Exception) { mediaDetails = new MediaDetails(); mediaDetails.error = "Server returned an Error"; } if (!String.IsNullOrEmpty(mediaDetails.error)) { SetErrorDetailsView(mediaDetails); } else { SetSuccessDetailsView(mediaDetails); } btnOk.Enabled = EnableDisableApplyMovie() || EnableDisableApplyEpisode(); }
private void btnSearch_Click(object sender, EventArgs e) { var mediaDetails = new MediaDetails(); PopulateMediaDetails(mediaDetails); string responseFromServer = GetDetailsFromWeb(Settings.OmdbUrl + mediaDetails.BuildUrlParams(true)); SetMoviesList(responseFromServer); }
private void lvMovies_SelectedIndexChanged(object sender, EventArgs e) { if (lvMovies.SelectedItems.Count > 0) { var item = lvMovies.SelectedItems[0]; var mediaDetails = new MediaDetails(); mediaDetails.imdbID = (string)item.Tag; string responseFromServer = GetDetailsFromWeb(Settings.OmdbUrl + mediaDetails.BuildUrlParamsById()); SetMovieDetails(responseFromServer); } }
private void GetMovieDetails(bool shortPlot) { var mediaDetails = new MediaDetails(); PopulateMediaDetails(mediaDetails); string responseFromServer = GetDetailsFromWeb(Settings.OmdbUrl + mediaDetails.BuildUrlParams(false, shortPlot)); lvMovies.Items.Clear(); SetMovieDetails(responseFromServer); lvMovies.Visible = false; }
private void SetErrorDetailsView(MediaDetails mediaDetails) { lblMessage.Text = mediaDetails.error; pbPoster.Image = null; pbPoster.ImageLocation = ""; if (!String.IsNullOrEmpty(helper.MediaPath)) { mediaDetails = new MediaDetails(helper.MediaPath, helper.ShowsConversionTable); tbTitle.Text = mediaDetails.title; tbYear.Text = mediaDetails.year; DisplayEpisodeDetails(); } }
public void ApplyEpisodeToFileSystem(string TitleText, string SeasonText, string EpisodeText) { try { string newFilePath; if (Settings.MoveEpisode && Directory.Exists(Settings.SeriesPath)) { string episodeFolder = Path.Combine(Settings.SeriesPath, TitleText); if (!Directory.Exists(episodeFolder)) { Directory.CreateDirectory(episodeFolder); } string seasonFolder = String.Format("Season {0}", SeasonText); string seasonPath = Path.Combine(episodeFolder, seasonFolder); if (!Directory.Exists(seasonPath)) { Directory.CreateDirectory(seasonPath); } newFilePath = Path.Combine(seasonPath, MediaDetails.GetNormalizedEpisodeName(MediaPath, SeasonText, EpisodeText)); } else { string mediaDirectory = Path.GetDirectoryName(MediaPath); newFilePath = Path.Combine(mediaDirectory, MediaDetails.GetNormalizedEpisodeName(MediaPath, SeasonText, EpisodeText)); } if (!Path.GetFullPath(MediaPath).Equals(Path.GetFullPath(newFilePath))) { File.Move(MediaPath, newFilePath); } Applied = true; if (Settings.DownloadSubtitles) { DownloadSubtitles(newFilePath, TitleText); } if (Settings.MoveEpisode && Directory.Exists(Settings.SeriesPath) && OpenDestinationFolder()) { Process.Start("explorer.exe", Directory.GetParent(newFilePath).FullName); } } catch (Exception ex) { DialogResult result = MessageBox.Show("Failed to apply chenges to file system. See error details?", "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error); if (result == System.Windows.Forms.DialogResult.Yes) { throw ex; } } }
private void SearchFromFile(string initialSearchTxt) { helper.Applied = false; helper.MediaPath = initialSearchTxt; helper.IsDirectory = Directory.Exists(helper.MediaPath); helper.IsFile = File.Exists(helper.MediaPath); var mediaDetails = new MediaDetails(helper.MediaPath, helper.ShowsConversionTable); helper.IsEpisode = mediaDetails.IsEpisode; helper.SeasonNumber = mediaDetails.Season.ToString(); helper.EpisodeNumber = mediaDetails.Episode.ToString(); GetDetailsFromWebAsync(Settings.OmdbUrl + mediaDetails.BuildUrlParams(false)); lvMovies.Visible = false; }
private void SetSuccessDetailsView(MediaDetails mediaDetails) { lblMessage.Text = ""; tbTitle.Text = mediaDetails.CleanTitle(); tbCast.Text = mediaDetails.actors; string year = Regex.Replace(mediaDetails.year, "[^0-9]", ""); if (year.Length > 4) { year = year.Substring(0, year.Length - 4); } tbYear.Text = year; lblLanguage.Text = mediaDetails.language; cbType.SelectedIndex = cbType.FindString(mediaDetails.type); tbPlot.Text = mediaDetails.plot; lblGenre.Text = mediaDetails.genre; lblDirector.Text = mediaDetails.director; lbliDBRating.Text = mediaDetails.imdbRating; helper.ImdbId = mediaDetails.imdbID.Replace("tt", ""); DisplayEpisodeDetails(); double rating; bool hasRating = Double.TryParse(mediaDetails.imdbRating, out rating); m_starRatingControl.SelectedStar = hasRating ? (int)Math.Round(rating /* / 2*/, 0) : 0; m_starRatingControl.Refresh(); pbPoster.Tag = mediaDetails.imdbID; if (mediaDetails.poster.Contains("http")) { pbPoster.Load(mediaDetails.poster); lblMessage.Text = ""; pbPoster.Cursor = Cursors.Hand; lblMessage.Cursor = Cursors.Default; } else { pbPoster.Image = null; pbPoster.ImageLocation = ""; lblMessage.Text = "Poster not available"; pbPoster.Cursor = Cursors.Default; lblMessage.Cursor = Cursors.Hand; } }
private void PopulateMediaDetails(MediaDetails mediaDetails) { mediaDetails.title = tbTitle.Text; mediaDetails.year = tbYear.Text; mediaDetails.type = (string)cbType.SelectedItem; }
public void ApplyMovieToFileSystem(bool isTvSeries, string posterUrl, string TitleText, string YearText) { try { WebClient webClient = new WebClient(); string downloadPath = ""; string newFolderPath = ""; string newFolderName; if (isTvSeries) { newFolderName = TitleText; } else { newFolderName = String.Format("{0} ({1})", TitleText, YearText); } if (IsDirectory) { var parentDirectoryInfo = Directory.GetParent(MediaPath); newFolderPath = Path.Combine(parentDirectoryInfo.FullName, newFolderName); if (!Path.GetFullPath(MediaPath).Equals(Path.GetFullPath(newFolderPath))) { Directory.Move(MediaPath, newFolderPath); } MediaPath = newFolderName; } else if (IsFile) { newFolderPath = Path.Combine(Path.GetDirectoryName(MediaPath), newFolderName); if (!Directory.Exists(newFolderPath)) { Directory.CreateDirectory(newFolderPath); string mediaFileNewPath = Path.Combine(newFolderPath, MediaDetails.GetNormalizedMovieName(MediaPath)); File.Move(MediaPath, mediaFileNewPath); if (Settings.DownloadSubtitles) { DownloadSubtitles(mediaFileNewPath, TitleText); } } } else { return; } downloadPath = Path.Combine(newFolderPath, "folder.jpg"); File.Delete(downloadPath); webClient.DownloadFile(posterUrl, downloadPath); File.SetAttributes(downloadPath, File.GetAttributes(downloadPath) | FileAttributes.Hidden); if (!isTvSeries && Settings.MoveMovie && Directory.Exists(Settings.MoviesPath)) { string movieFolderName = Path.GetFileName(newFolderPath); var folderInMoviePath = Path.Combine(Settings.MoviesPath, movieFolderName); if (!Path.GetFullPath(newFolderPath).Equals(Path.GetFullPath(folderInMoviePath))) { Utils.CopyFolder(newFolderPath, folderInMoviePath); Utils.Empty(new DirectoryInfo(newFolderPath)); Directory.Delete(newFolderPath); } newFolderPath = folderInMoviePath; } Applied = true; if (!isTvSeries && Settings.MoveMovie && Directory.Exists(Settings.MoviesPath) && OpenDestinationFolder()) { Process.Start("explorer.exe", newFolderPath); } } catch (Exception ex) { DialogResult result = MessageBox.Show("Failed to apply chenges to file system. See error details?", "Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error); if (result == System.Windows.Forms.DialogResult.Yes) { throw ex; } } }