예제 #1
0
        public async Task AddMovieToTheDownloadQueueAsync()
        {
            Console.WriteLine("Check If there are movies for downloads");
            if (!CheckIfThereAreMoviesInTheQueue())
            {
                Console.WriteLine("THERE IS NO MOVIES IN THE QUEUE");
                return;
            }


            //Check if theres internet connection
            Console.WriteLine("CEHCK THE INTERNET CONNECTION");
            if (!CheckForInternetConnection())
            {
                Console.WriteLine("NO INTERNET CONNECTION");
                return;
            }

            try
            {
                await _aria2Client.TellActive();
            }
            catch (Exception ex)
            {
                Console.WriteLine("ARIA2 is not running");
                return;
            }

            //----------------------------------------------------//
            //Please notice that those functions are run in order!//
            //----------------------------------------------------//


            //Restart the download if the Aria2 Crash or restart
            //this will restart all the download file, and set the status to waiting again and increase the retry
            //[THIS WILL CHECK THE ARIA2]
            Console.WriteLine("CheckIfTheAriaHasBeenRestartAsync");
            await CheckIfTheAriaHasBeenRestartAsync();


            //Change the status of the download file to error when the file errored
            //[THIS WILL CHECK THE ARIA2]
            Console.WriteLine("CheckIfTheDownloadFileIfGetErrored");
            await CheckIfTheDownloadFileIfGetErrored();


            //Restart the error download
            //if for some reason the download file get errored, it will resatrted and increased the retry
            //[THIS WILL CHECK THE DATABASE]
            Console.WriteLine("RestartErrorDownloadFiles");
            //await RestartErrorDownloadFiles();


            //Change the status of the download file to complete when the file finished
            //[THIS WILL CHECK THE ARIA2]
            Console.WriteLine("CheckIfTheDownloadFileComplete");
            await CheckIfTheDownloadFileComplete();



            Console.WriteLine("Total Active Files IN the DATABASE => " + _movieContextDownloadQueue
                              .Movies.Where(q => q.DownloadStatus == CinemaMaxFeeder.Database.Model.MovieDownloadStatus.Started)
                              .Count());

            Console.WriteLine("Total ERROR Files IN the DATABASE => " + _movieContextDownloadQueue
                              .Movies.Where(q => q.DownloadStatus == CinemaMaxFeeder.Database.Model.MovieDownloadStatus.Error)
                              .Count());

            Console.WriteLine("Config: Max Downloading Files In the Same Time: " + (Config.MaxDownloadItemsIntheSameTime).ToString());

            if (_movieContextDownloadQueue
                .Movies.Where(q => q.DownloadStatus == CinemaMaxFeeder.Database.Model.MovieDownloadStatus.Started)
                .Count() <= Config.MaxDownloadItemsIntheSameTime - 1)
            {
                Console.WriteLine("AddWaitingMovieAsync");
                await AddWaitingMovieAsync();
            }
        }
예제 #2
0
        private Action UpdateUserWithInfo()
        {
            return(async() =>
            {
                var downloadsModel = new List <DownloadProgressModel>();

                try {
                    foreach (var downloadFile in await _aria2Client.TellActive())
                    {
                        var downloadsModelItem = new DownloadProgressModel();
                        downloadsModelItem.Name = downloadFile.Files[0].Path;

                        try
                        {
                            var currentDownloadLink = _movieContextReadOnly.Movies
                                                      .Where(Q => Q.DownloadId == downloadFile.GID)
                                                      .Include(In => In.TranscoddedFiles)
                                                      .First();

                            downloadsModelItem.GID = currentDownloadLink.ArTitle;
                            downloadsModelItem.logo = currentDownloadLink.ImgThumbObjUrl;

                            downloadsModelItem.StartDownloadAt = HelperFunctions.GetElapsedTime(currentDownloadLink.StartDownloadAt);
                        }
                        catch (Exception ex)
                        {
                            downloadsModelItem.GID = "Error - the information is not in the database";
                            downloadsModelItem.StartDownloadAt = "Error - the information is not in the database";
                        }


                        downloadsModelItem.DownloadSpeed = downloadFile.DownloadSpeed;
                        downloadsModelItem.DownloadSpeedHuman = HelperFunctions.BytesToString((long)downloadFile.DownloadSpeed);
                        downloadsModelItem.CompletedLength = downloadFile.CompletedLength;

                        downloadsModelItem.Status = downloadFile.Status;
                        downloadsModelItem.Dir = downloadFile.Dir;
                        downloadsModelItem.downloadSizeHuman = HelperFunctions.BytesToString((long)downloadFile.TotalLength);
                        downloadsModelItem.TotalLength = downloadFile.TotalLength;
                        downloadsModelItem.downloadStatus = downloadFile.Status;


                        downloadsModelItem.Percent = Math.Round(((double)downloadFile.CompletedLength / (double)downloadFile.TotalLength) * 100, 2);
                        downloadsModel.Add(downloadsModelItem);
                    }
                    foreach (var downloadFile in await _aria2Client.TellStopped())
                    {
                        var downloadsModelItem = new DownloadProgressModel();
                        downloadsModelItem.Name = downloadFile.Files[0].Path;

                        try
                        {
                            var currentDownloadLink = _movieContextReadOnly.Movies
                                                      .Where(Q => Q.DownloadId == downloadFile.GID)
                                                      .Include(In => In.TranscoddedFiles)
                                                      .First();

                            downloadsModelItem.GID = currentDownloadLink.ArTitle;
                            downloadsModelItem.logo = currentDownloadLink.ImgThumbObjUrl;
                            downloadsModelItem.StartDownloadAt = HelperFunctions.GetElapsedTime(currentDownloadLink.StartDownloadAt);
                        }
                        catch (Exception ex)
                        {
                            downloadsModelItem.GID = "Error - the information is not in the database";
                            downloadsModelItem.StartDownloadAt = "Error - the information is not in the database";
                        }



                        downloadsModelItem.DownloadSpeed = 0;
                        downloadsModelItem.DownloadSpeedHuman = "";
                        downloadsModelItem.CompletedLength = 0;

                        downloadsModelItem.Status = downloadFile.Status;
                        downloadsModelItem.Dir = downloadFile.Dir;
                        downloadsModelItem.downloadSizeHuman = "";
                        downloadsModelItem.TotalLength = 0;
                        downloadsModelItem.downloadStatus = downloadFile.Status;


                        if (downloadFile.Status == "complete")
                        {
                            downloadsModelItem.Percent = 100;
                        }

                        if (downloadFile.Status == "error")
                        {
                            downloadsModelItem.Percent = 0;
                        }

                        downloadsModel.Add(downloadsModelItem);
                    }



                    if (downloadsModel.Count == 0)
                    {
                    }
                    else
                    {
                        await _downloadProgressHub.Clients.All.SendAsync("items", downloadsModel);
                    }
                } catch (Exception e) {
                }
            });
        }