public static Movie FetchMovie(String file, String imdbId, bool allowUnpopular) { var imdb = new IMDBClient(); var m = imdb.GetDetails(imdbId); if (!allowUnpopular && m.num_votes < 30) { throw new NoMatchFoundException(); } String cover = null; if (m.image != null && !m.image.url.IsNullOrEmpty()) { cover = Util.CleanFileName(m.image.url); var coverPath = Path.Combine(DM.CoverDir, cover); if (!File.Exists(coverPath)) { if (!Directory.Exists(DM.CoverDir)) { Directory.CreateDirectory(DM.CoverDir); } new WebClient().DownloadFile(m.image.url, coverPath); } } return(new Movie(file, m, cover)); }
public void TestSignUrl() { var sample = new[] { new{ usigned = "http://app.imdb.com/find?q=matrix&appid=android2&device=406642b5-8ee2-4a3b-91ac-5229dc474faf&locale=fr_FR", timestamp = 1307058440, signed = "http://app.imdb.com/find?q=matrix&appid=android2&device=406642b5-8ee2-4a3b-91ac-5229dc474faf&locale=fr_FR×tamp=1307058440&sig=and2-11fd0275e635e91b9a874c61ec7b6a95c455676b" }, new{ usigned = "http://app.imdb.com/title/maindetails?videoformats=H.264%2CCBP&tconst=tt0133093&appid=android2&device=406642b5-8ee2-4a3b-91ac-5229dc474faf&locale=fr_FR", timestamp = 1307058447, signed = "http://app.imdb.com/title/maindetails?videoformats=H.264%2CCBP&tconst=tt0133093&appid=android2&device=406642b5-8ee2-4a3b-91ac-5229dc474faf&locale=fr_FR×tamp=1307058447&sig=and2-d86c575a2cd3fd0cef28697a4818f2deb23029db" }, new{ usigned = "http://app.imdb.com/title/plot?tconst=tt0133093&appid=android2&device=406642b5-8ee2-4a3b-91ac-5229dc474faf&locale=fr_FR", timestamp = 1307058465, signed = "http://app.imdb.com/title/plot?tconst=tt0133093&appid=android2&device=406642b5-8ee2-4a3b-91ac-5229dc474faf&locale=fr_FR×tamp=1307058465&sig=and2-701c6103545a2ba91fa6733fc910c1772ef25ffc" }, }; foreach (var o in sample) { Assert.AreEqual(o.signed, IMDBClient.SignUrl(new UrlBuilder(o.usigned), o.timestamp)); } }
public void TestFind() { var api = new IMDBClient("fr_FR"); var results = api.Find("matrix 2003 "); Assert.Greater(results.Count, 0); var first = results.First(); Assert.That(first.title.ToLower().Contains("matrix")); Assert.AreEqual(2003, first.GetYear()); var detail = api.GetDetails(first.tconst); Assert.AreEqual(first.year, detail.year); Assert.AreEqual(first.title, detail.title); Assert.AreEqual(first.tconst, detail.tconst); }
public static Movie FetchMovie(String file) { var imdb = new IMDBClient(); var f = ParseMovieName(file); if (f.ShouldBeIgnored || f.GuessedTitle.IsNullOrEmpty()) { return(null); } var m = imdb.Find(f.GuessedTitle + " " + f.GuessedYear).FirstOrDefault(); if (m == null) { throw new NoMatchFoundException(); } return(FetchMovie(file, m.tconst, false)); }
static void Main(string[] args) { var curdir = Directory.GetCurrentDirectory(); var movies = Scanner.GetFiles(@"C:\torrent\films").Select(Scanner.ParseMovieName); movies = movies //.Where(m => !TestScanner.Good.Any(g => g.File == m.Path)) .ToList(); foreach (var m in movies) { Console.WriteLine(m.GuessedTitle + " " + m.GuessedYear); var imdb = new IMDBClient("fr_FR").Find(m.GuessedTitle + " " + m.GuessedYear); foreach (var r in imdb.Take(3)) { Console.WriteLine(new[] { "imdb:", r.title, r.year, r.image == null ? null : r.image.url }.Where(s => !s.IsNullOrEmpty()).Join(" ")); } Console.ReadLine(); } Console.Read(); }
public void OnRequest(HttpRequestHead request, IDataProducer requestBody, IHttpResponseDelegate response) { //auth if (Password != null && !request.Headers.Any(kv => (kv.Value ?? "").Contains(Password))) { if (!request.Uri.Contains(Password)) { ReplyText(response, "Pas d'accord !", false, null); return; } Redirect(response, request.Uri, new Dictionary <string, string> { { "Set-Cookie", "auth=" + Password + "; path=/" } }); return; } try { log.Info(new[] { request.Method, request.Uri }.Join("\t")); String url = request.Uri; var parts = url.Split(new[] { '?' }, 2); String path = HttpUtility.UrlDecode(parts[0]); if (path.EndsWith("/")) { path += "index.htm"; } if (ReplyFile(response, QueryPathToFile(path))) { return; } var o = HttpUtility.ParseQueryString(parts.GetOrDefault(1) ?? ""); if (path == "/*movies") { ReplyJson(response, o, DM.Instance.GetJson()); return; } if (path == "/*play") { if (DM.Instance.PlayFile(o["f"])) { ReplyJson(response, o, "{success:true}"); return; } } if (path == "/*searchImdb") { var q = o["q"]; if (q.IsNullOrEmpty()) { var g = Scanner.ParseMovieName(o["f"]); q = g.GuessedTitle + " " + g.GuessedYear; } var results = new IMDBClient().Find(q); ReplyJson(response, o, new Serializer(typeof(SearchImdb)).Serialize(new SearchImdb(q, results))); return; } if (path == "/*setMatch") { var id = o["id"]; var file = o["f"]; if (!id.IsNullOrEmpty() || !file.IsNullOrEmpty()) { if (id.IsNullOrEmpty()) { DM.Instance.AddUnmatched(file); } else if (file.IsNullOrEmpty()) { DM.Instance.UnmatchMovie(id); } else { DM.Instance.AddMovie(Scanner.FetchMovie(file, id, true)); } } ReplyJson(response, o, DM.Instance.GetJson()); return; } if (path == "/*setTag") { var id = o["id"]; var tag = o["tag"]; bool del = o["del"] == "1"; DM.Instance.SetTag(tag, id, del); ReplyJson(response, o, DM.Instance.GetJson()); return; } //TODO: resize image in a thread if (path.StartsWith("/*cover/")) { var p = path.Split('/', 4); if (p.Length != 4) { throw new Exception("invalid scale request"); } var format = RegScaleFormat.Match(p[2]); if (!format.Success) { throw new Exception("Invalid format"); } String img = Path.Combine(DM.CoverDir, p[3]); if (!File.Exists(img)) { img = QueryPathToFile("img/nocover.jpg"); } if (!File.Exists(img)) { throw new Exception("Image not found " + img); } String dir = Path.Combine(ScaledDir, format.Groups[0].Value); Directory.CreateDirectory(dir); String scaledPath = Path.Combine(dir, Path.GetFileName(img)); if (!File.Exists(scaledPath)) { using (var b = new Bitmap(img)) { String w = format.Groups[1].Value; String h = format.Groups[2].Value; String flags = format.Groups[3].Value; using (var scaled = ImgUtil.Scale(b, w.IsNullOrEmpty() ? (int?)null : int.Parse(w), h.IsNullOrEmpty() ? (int?)null : int.Parse(h), flags.Contains('c'), flags.Contains('s'))) { ImgUtil.Compress(scaled, scaledPath, ImageFormat.Jpeg, 90); } } } if (ReplyFile(response, scaledPath)) { return; } } ReplyText(response, "The resource you requested ('" + path + "') could not be found.", false, "404 Not Found"); } catch (Exception e) { log.Error(e.Message); ReplyText(response, e.Message + "\n\n" + e.StackTrace, false, "500 Internal Server Error"); } }