Beispiel #1
0
        //Updated July 24th - TODO: Need to accept download quality from user in config
        public static void DownloadMovies(List <Movie> moviesToDownload)
        {
            try
            {
                MongoCollection pendingCollection = MongoUtils.GetMongoCollection
                                                    (
                    @"mongodb://" + ConfigurationManager.AppSettings["mongoHost"] + @"/",
                    ConfigurationManager.AppSettings["port"],
                    ConfigurationManager.AppSettings["db"],
                    ConfigurationManager.AppSettings["pending_collection"]
                                                    );

                foreach (var m in moviesToDownload.Where(s => !MovieUtils.IsInPending(s) && !MovieUtils.IsInDownloaded(s)))
                {
                    var torURL = "";
                    //Is the preferred download quality avilable?
                    foreach (var t in m.DownloadLogistics)
                    {
                        if (t.Quality == ConfigurationManager.AppSettings["yts_quality_pref"])
                        {
                            torURL = t.TorrentUrl;
                        }
                    }
                    //Preferred quality was not available. Get next.
                    if (torURL == "")
                    {
                        foreach (var t in m.DownloadLogistics)
                        {
                            if (t.Quality != ConfigurationManager.AppSettings["yts_quality_excl"])
                            {
                                torURL = t.TorrentUrl;
                            }
                        }
                    }

                    //Download torrent file to temp folder first to be able to extract the video filename
                    DownloadFile(torURL,
                                 ConfigurationManager.AppSettings["temp_torrent_download_path"] + @"\" + ((m.ImdbTitle == null) ? m.YtsMovieTitle : m.ImdbTitle) + ".torrent");
                    //Pull video filename out of the torrent file
                    string        name         = MovieUtils.NameFromDownloadString(((m.ImdbTitle == null) ? m.YtsMovieTitle : m.ImdbTitle));
                    List <string> fileNameArry = name.Split(':').ToList();
                    foreach (var f in fileNameArry.Where(f => f.Contains("name")))
                    {
                        name = fileNameArry[fileNameArry.IndexOf(f) + 1];
                        name = name.Substring(0, name.Length - 2);
                        break;
                    }

                    pendingCollection.Insert(new Pending()
                    {
                        FileName = name,
                        Name     = m.YtsMovieTitle,
                        Show     = false,
                        Movie    = true
                    });
                    //Move the torrent file from temp into downloads
                    MoveFile(ConfigurationManager.AppSettings["temp_torrent_download_path"] + @"\" + m.YtsMovieTitle + ".torrent",
                             ConfigurationManager.AppSettings["torrent_download_path"] + @"\" + m.YtsMovieTitle + ".torrent");
                    break;
                }
            }
            catch (Exception e)
            { Log.AppendToLog("Error : FATAL download movie. " + e, ConfigurationManager.AppSettings["log_file"]); }
        }