private static bool PromptForSubtitle(IList<Subtitle> subtitles, ref Subtitle selectedSubtitle) { Console.WriteLine("I found multiple subtitles for your movie. Please chose one from the list:"); DisplayChoices(subtitles, selectedSubtitle); string input; int choice = 0; bool validOption = false; do { Console.Write("Your choice? (avaible options: '1'-'{0}', 'c', 'l') [{1}]:", subtitles.Count, subtitles.IndexOf(selectedSubtitle) + 1); input = Console.ReadLine(); if (int.TryParse(input, out choice)) { if (choice > 0 || choice <= subtitles.Count) { validOption = true; } } if (!validOption) { if (string.Compare(input, "l", StringComparison.InvariantCultureIgnoreCase) == 0) { DisplayChoices(subtitles, selectedSubtitle); } else if (string.Compare(input, "c", StringComparison.InvariantCultureIgnoreCase) == 0) { return false; } else { Console.WriteLine("Invalid option. Please chose one of the index numbers from the list, 'c' to cancel or 'l' to show the list again."); } } } while (!validOption); selectedSubtitle = subtitles[choice - 1]; return true; }
public string DownloadSubtitleToPath(string path, Subtitle subtitle) { if (string.IsNullOrEmpty(path)) { throw new ArgumentNullException("path"); } if (null == subtitle) { throw new ArgumentNullException("subtitle"); } if (!Directory.Exists(path)) { throw new ArgumentException("path should point to a valid location"); } string destinationfile = Path.Combine(path, subtitle.SubtitleFileName); string tempZipName = Path.GetTempFileName(); try { WebClient webClient = new WebClient(); webClient.DownloadFile(subtitle.SubTitleDownloadLink, tempZipName); UnZipSubtitleFileToFile(tempZipName, destinationfile); } finally { File.Delete(tempZipName); } return destinationfile; }
/// <summary> /// Converts the specified subtitle. /// </summary> /// <param name="subtitle">The subtitle.</param> /// <returns>The subtitle.</returns> private Subtitle Convert(OSDBnet.Subtitle subtitle) { Rating rating = Rating.Neutral; double ratingFigure; if (double.TryParse(subtitle.Rating, NumberStyles.Any, CultureInfo.InvariantCulture, out ratingFigure)) { if (ratingFigure < 0.1) { rating = Rating.Neutral; } else if (ratingFigure < 5.0) { rating = Rating.Negative; } else if (ratingFigure > 5.0) { rating = Rating.Positive; } } return(new Subtitle(Path.GetFileNameWithoutExtension(subtitle.SubtitleFileName), subtitle.SubtitleFileName + " [OpenSubtitles.org]", subtitle.SubTitleDownloadLink.AbsoluteUri, rating, this)); }
public OpenSubtitleSearchResult(OpenSubtitleDownloader service, Subtitle subtitle) { _service = service; _subtitle = subtitle; }
protected static Subtitle BuildSubtitleObject(SearchSubtitlesInfo info) { var sub = new Subtitle { SubtitleId = info.IDSubtitle, SubtitleHash = info.SubHash, SubtitleFileName = info.SubFileName, SubTitleDownloadLink = new Uri(info.SubDownloadLink), SubtitlePageLink = new Uri(info.SubtitlesLink), LanguageId = info.SubLanguageID, LanguageName = info.LanguageName, Rating = info.SubRating, Bad = info.SubBad, ImdbId = info.IDMovieImdb, MovieId = info.IDMovie, MovieName = info.MovieName, OriginalMovieName = info.MovieNameEng, MovieYear = int.Parse(info.MovieYear) }; return sub; }
private static void DisplayChoices(IList<Subtitle> subtitles, Subtitle defaultSubtitle) { int choice = 1; foreach (var subtitle in subtitles) { Console.WriteLine("{0}[{1}] {2}", subtitle.Equals(defaultSubtitle)? "*": " ", choice++, subtitle.MovieName); Console.WriteLine("\tFile:{0}", subtitle.SubtitleFileName); Console.WriteLine("\tLanguage:{0}", subtitle.LanguageName); Console.WriteLine(); } }
public string DownloadSubtitleToPath(string path, Subtitle subtitle) { return DownloadSubtitleToPath(path, subtitle, null); }
public OpenSubtitleResult(Subtitle subtitle, CultureInfo language, IAnonymousClient client) { _subtitle = subtitle; _language = language; _client = client; }