public bool beginDownLoad() { while (!CMDUtil.checkPort(85)) { if (!doStartApache) { doStartApache = true; CMDUtil.startApache(); } } while (isDownloading || stopDownloadFlag) { Thread.Sleep(1000); } using (var context = new NTVideoEntities()) { var infoDownloadQuery = from m in context.movies from v in context.victims where m.movieId == v.movieId && v.downloadStatus != "completed" && v.downloadStatus != "pending" && m.countries.Any(c => c.alias != "my") orderby m.publishYear descending, m.isMultiEpisode ascending select new { m, v }; var movieInfo = infoDownloadQuery.FirstOrDefault(); if (movieInfo.m != null) { string movieAlias = movieInfo.m.alias; var episodes = BaseVictim.instance().getEpisodes(movieInfo.v.movieHref, true); var totalEpisode = episodes.Count(); var downloadedInfo = getEpisodesDownloadedInfo(movieInfo.v.victimId); var episodeIndex = 0; foreach (var episode in episodes) { var typeDownload = getTypeDownload(episode, downloadedInfo); if (typeDownload == "none") { episodeIndex++; continue; } var typeMovieFolder = (movieInfo.m.isMultiEpisode == 1) ? "multi-episode" : "one-episode"; var countryFolder = movieInfo.m.countries.ToList <country>()[0].alias; var savePath = rootSavePath + "/" + typeMovieFolder + "/" + countryFolder + "/" + movieAlias; if (!Directory.Exists(savePath)) { Directory.CreateDirectory(savePath); } fileName = episode.alias + ".mp4"; isDownloading = true; string status = downLoad(movieAlias, episodeIndex, savePath, fileName); if (episodeIndex == (totalEpisode - 1) && status != "error" && status != "pending") { status = "completed"; } saveDownloadInfoToDB((typeDownload == "update") ? getDownloadedByName(episode.name, downloadedInfo) : null, episode.alias, savePath, status, movieInfo.m, movieInfo.v, context); episodeIndex++; isDownloading = false; } } } return(true); }
public bool beginUpLoad() { while (!CMDUtil.checkPort(85)) { if (!doStartApache) { doStartApache = true; CMDUtil.startApache(); } } while (isUploading || stopUploadFlag) { Thread.Sleep(1000); } using (var context = new NTVideoEntities()) { var infoUploadQuery = from m in context.movies from v in context.victims from d in context.downloads where m.movieId == v.movieId && d.victimId == v.victimId && m.countries.Any(c => c.alias != "my") && v.downloadStatus == "completed" && v.uploadStatus != "completed" orderby m.publishYear, m.isMultiEpisode select new { m, v, d }; var movieInfo = infoUploadQuery.FirstOrDefault(); if (movieInfo.m != null) { string movieAlias = movieInfo.m.alias; var episodesDownloaded = movieInfo.v.downloads; var episodeUploaded = movieInfo.v.uploads; var episodeIndex = 0; foreach (var episodeDownloaded in episodesDownloaded) { isUploading = true; var title = movieInfo.m.name1 + "-" + movieInfo.m.name2 + ((movieInfo.m.isMultiEpisode == 1) ? (" - Tập " + episodeDownloaded.name) : ""); var description = HtmlUtil.StripHTML(movieInfo.v.description); var file = episodeDownloaded.name + ".mp4"; string status = upLoad(title, description, episodeDownloaded.savePath, file); if (episodeIndex == (episodesDownloaded.Count() - 1) && status != "error" && status != "pending") { status = "completed"; } //saveDownloadInfoToDB(episodeDownloaded.alias, savePath, status, movieInfo.m, movieInfo.v, context); episodeIndex++; isUploading = false; } } } return(true); }