//Updated December 23rd - Sleep 1 min public static void DownloadTorrentFiles() { List <BasicShow> showsToDownload = TvUtils.GetEpisodesToDownload(); List <Movie> moviesToDownload = MovieUtils.GetMoviesToDownload(); TvUtils.SetShowDownloadLocations(showsToDownload); DownloadShows(showsToDownload); DownloadMovies(moviesToDownload); Thread.Sleep(60000); }
//Updated July 24th public static void DownloadShows(List <BasicShow> showsToDownload) { try { MongoCollection pendingCollection = MongoUtils.GetMongoCollection ( @"mongodb://" + ConfigurationManager.AppSettings["mongoHost"] + @"/", ConfigurationManager.AppSettings["port"], ConfigurationManager.AppSettings["db"], ConfigurationManager.AppSettings["pending_collection"] ); foreach (var s in showsToDownload.Where(s => !TvUtils.IsInPending(s))) { try { //Download torrent file to temp folder first to be able to extract the video DownloadFile(s.DownloadLocation, ConfigurationManager.AppSettings["temp_torrent_download_path"] + @"\" + s.Name + " S" + s.Season.ToString("00") + "E" + s.Episode.ToString("00") + ".torrent"); //Pull video filename out of the torrent file string name = TvUtils.NameFromDownloadString(s.Name, s.Season.ToString("00"), s.Episode.ToString("00")); //int nameIndex = name.IndexOf("FileName"); int nameIndex = name.IndexOf(ConfigurationManager.AppSettings["torrent_filename_marker"]); pendingCollection.Insert(new Pending() { FileName = name.Substring( nameIndex + name.Substring(nameIndex + 4, 4).Split(':')[0].Length + 5, Convert.ToInt32(name.Substring(nameIndex + 4, 4).Split(':')[0])), Name = s.Name, Show = true, Movie = false, Episode = s.Episode, Season = s.Season }); //Move the torrent file from temp into downloads MoveFile(ConfigurationManager.AppSettings["temp_torrent_download_path"] + @"\" + s.Name + " S" + s.Season.ToString("00") + "E" + s.Episode.ToString("00") + ".torrent", ConfigurationManager.AppSettings["torrent_download_path"] + @"\" + s.Name + " S" + s.Season.ToString("00") + "E" + s.Episode.ToString("00") + ".torrent"); break; } catch (Exception e) { Log.AppendToLog(": FATAL download torrent. " + s.Name + " Season: " + s.Season + " Episode: " + s.Episode, ConfigurationManager.AppSettings["log_file"]); } } } catch (Exception e) { Log.AppendToLog(": FATAL download show. " + e, ConfigurationManager.AppSettings["log_file"]); } }
//Updated July 5th public static void MonitorAndMove() { try { List <Pending> pendingList = MongoUtils.GetMongoCollection ( @"mongodb://" + ConfigurationManager.AppSettings["mongoHost"] + @"/", ConfigurationManager.AppSettings["port"], ConfigurationManager.AppSettings["db"], ConfigurationManager.AppSettings["pending_collection"] ).FindAllAs <Pending>().ToList <Pending>(); //Get the names of the files in the downloaded folder to compare against those pending List <string> tempS = Directory.GetFiles(ConfigurationManager.AppSettings["file_download_path"]).ToList(); tempS.AddRange(Directory.GetDirectories(ConfigurationManager.AppSettings["file_download_path"]).ToList()); foreach (var p in pendingList) { foreach (var str in tempS.Where(str => str.Equals(ConfigurationManager.AppSettings["file_download_path"] + @"\" + p.FileName))) { if (p.Movie) { MoveFile(str.Replace(@"\\", @"\"), str.Replace(@"\\", @"\").Replace(ConfigurationManager.AppSettings["file_download_path"], ConfigurationManager.AppSettings["movie_move_path"])); MovieUtils.SetToDownloaded(p.Name); MovieUtils.MoveToDownloaded(p.Name); } else if (p.Show) { MoveFile(str.Replace(@"\\", @"\"), str.Replace(@"\\", @"\").Replace(ConfigurationManager.AppSettings["file_download_path"], ConfigurationManager.AppSettings["show_move_path"])); TvUtils.SetToDownloaded(p.Name, p.Season, p.Episode); TvUtils.MoveToDownloaded(p.Name, p.Season, p.Episode); TvUtils.UpdateCheckMyShow(p.Name, p.Season, p.Episode); } } } } catch (Exception e) { Log.AppendToLog("Error : FATAL monitor and move. " + e, ConfigurationManager.AppSettings["log_file"]); } }
public object Post(ModifyInfoRequest request) { //Handle null objects on the client side code if (request.Show) { if (request.ModType == "delete") { Console.WriteLine("Delete show post: " + DateTime.Now.ToString("M/d/yyyy H:mm:ss:ff")); return(JsonSerializer.SerializeToString(new ReturnClass() { Key = "response", Value = TvUtils.RemoveShowFromMyShow(request.Name) })); } else if (request.ModType == "add") { Console.WriteLine("Add show post: " + DateTime.Now.ToString("M/d/yyyy H:mm:ss:ff")); return(JsonSerializer.SerializeToString(new ReturnClass() { Key = "response", Value = TvUtils.AddShowToMyShows(request.Name, request.Season, request.Episode) })); } else if (request.ModType == "modify") { Console.WriteLine("Modify show post: " + DateTime.Now.ToString("M/d/yyyy H:mm:ss:ff")); return(JsonSerializer.SerializeToString(new ReturnClass() { Key = "response", Value = TvUtils.UpdateMyShow(request.Name, request.Season, request.Episode) })); } else { return(JsonSerializer.SerializeToString(new ReturnClass() { Key = "response", Value = "I don't understand your request" })); } } else { if (request.ModType == "delete") { Console.WriteLine("Delete movie post: " + DateTime.Now.ToString("M/d/yyyy H:mm:ss:ff")); return(JsonSerializer.SerializeToString(new ReturnClass() { Key = "response", Value = MovieUtils.RemoveMovieFromMyMovies(request.Name) })); } else if (request.ModType == "add") { Console.WriteLine("Add movie post: " + DateTime.Now.ToString("M/d/yyyy H:mm:ss:ff")); return(JsonSerializer.SerializeToString(new ReturnClass() { Key = "response", Value = MovieUtils.AddMovieToMyMovies(request.Name, request.ImdbCode, request.Year) })); } else if (request.ModType == "modify") //TODO: build this out... or not? is it needed? { return(JsonSerializer.SerializeToString(new ReturnClass() { Key = "response", Value = "I don't understand your request... yet" })); } else { return(JsonSerializer.SerializeToString(new ReturnClass() { Key = "response", Value = "I don't understand your request" })); } } }