Esempio n. 1
0
        private void downloadInternal(string url, string path, string filename, MultiDownloader multiDownloader)
        {
            p = new LixProcess();

            p.StartInfo.Arguments =
                " -d \"" + path + "\"" +
                (string.IsNullOrEmpty(filename) ? "" : " -o \"" + filename + "\"") +
                " -c" +
                //" --enable-rpc=true" +
                " --file-allocation=none" +
                //" -j" + Download_Connections +
                " -x" + multiDownloader.Download_Connections +
                " -s" + multiDownloader.Download_Connections +
                " -k10M" +
                " \"" + url + "\"";
            p.StartInfo.FileName               = "aria2c.exe";
            p.StartInfo.CreateNoWindow         = true;
            p.StartInfo.UseShellExecute        = false;
            p.StartInfo.RedirectStandardOutput = true;
            //p.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
            p.Start();
            while (!p.StandardOutput.EndOfStream)
            {
                if (multiDownloader.IsStopped)
                {
                    SeriesLoader.KillProcessAndChildrens(p.Id);
                    break;
                }
                try
                {
                    var ps = p.StandardOutput.ReadLine();
                    if (!string.IsNullOrWhiteSpace(ps))
                    {
                        ps = ps.Trim();
                        int.TryParse(ps.GetBetweenN("(", "%)"), out int perc);

                        CurrentSize = (long)convert(ps.GetBetweenN(" ", "/"));
                        FullSize    = (long)convert(ps.GetBetweenN("/", "("));
                        Speed       = (long)convert(ps.GetBetween("DL", " "));

                        if (perc > 0)
                        {
                            Percentage = perc;
                        }
                        if (!ps.StartsWith("-"))
                        {
                            DownloadInfo = (ps.Contains("#") ? ("[" + ps.Substring(ps.IndexOf(" ", ps.IndexOf("#")) + 1)) : ps);
                        }
                    }
                }
                catch (Exception x)
                {
                }
            }
        }
Esempio n. 2
0
        public void Download(MultiDownloader multiDownloader)
        {
            try
            {
                IsRunning  = true;
                IsFinished = false;
                IsSuccess  = false;
                string url = Language.Direct_Video_Url;
                if (!string.IsNullOrEmpty(url))
                {
                    var item = Language;//.GetBest().GetBest();
                    var path = Language.Hoster.Episode.Season.Series.Directory;

                    var filename = item.CreateFileNameSync();

                    if (multiDownloader.UseAria2c)
                    {
                        downloadInternal(url, path, filename, multiDownloader);
                    }
                    else
                    {
                        downloadInternal1(url, path, filename, multiDownloader);
                    }
                    var fpath = Path.GetFullPath(Path.Combine(path, filename));
                    var apath = Path.GetFullPath(Path.Combine(path, filename + ".aria2"));
                    if (File.Exists(fpath) && !File.Exists(apath))
                    {
                        FileInfo fas = new FileInfo(fpath);
                        if (fas.Length > LiXMath.MIBIBYTE)
                        {
                            item.FilePath = fpath;
                            IsSuccess     = true;
                        }
                        else
                        {
                            File.Delete(fpath);
                        }
                    }
                    else
                    {
                        item.FilePath = string.Empty;
                    }
                    IsFinished   = true;
                    DownloadInfo = "";
                }
            }
            catch (Exception x)
            {
                DownloadInfo = x.Message;
                IsSuccess    = false;
            }
            IsRunning = false;
        }
Esempio n. 3
0
        private void downloadInternal1(string url, string path, string filename, MultiDownloader multiDownloader)
        {
            try
            {
                var httpWebRequest = HttpWebRequest.CreateHttp(url);
                //httpWebRequest.Method = "GET";
                var filePath = Path.Combine(path, filename);
                var fi       = new FileInfo(filePath);
                FullSize = GetLength(url);
                if (fi.Exists)
                {
                    if (fi.Length >= FullSize)
                    {
                        return;
                    }
                    httpWebRequest.AddRange(fi.Length);
                }
                using (var fileStream = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.ReadWrite))//, FileShare.ReadWrite))
                {
                    using (var httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse)
                    {
                        using (var stream = httpWebResponse.GetResponseStream())
                        {
                            var dt       = DateTime.UtcNow;
                            var buffsize = LiXMath.MIBIBYTE;
                            var buffer   = new byte[buffsize];
                            var speed    = 0;
                            while (!multiDownloader.IsStopped)
                            {
                                if (IsPaused)
                                {
                                    buffsize = 1000;
                                    Task.Delay(1000).Wait();
                                }
                                else
                                {
                                    buffsize = buffer.Length;
                                }
                                var l = stream.Read(buffer, 0, buffsize);
                                if (l <= 0 || multiDownloader.IsStopped)
                                {
                                    break;
                                }
                                fileStream.Write(buffer, 0, l);
                                //if (fileStream.Position >= FullSize)
                                //    break;
                                speed += l;
                                if (DateTime.UtcNow.Subtract(dt).TotalMilliseconds >= 1000)
                                {
                                    CurrentSize = fileStream.Length;
                                    Speed       = speed;

                                    Percentage   = (int)(fileStream.Length / (float)FullSize * 100f);
                                    DownloadInfo = "[" +
                                                   fileStream.Length.SizeSuffix(0) + "/" + FullSize.SizeSuffix(0) +
                                                   "(" + Percentage + "%) " +
                                                   "CN:" + multiDownloader.Download_Connections +
                                                   " DL:" + speed.SizeSuffix(1) +
                                                   " ETA: " + TimeSpan.FromSeconds((FullSize - fileStream.Length) / speed).ToString(@"hh\:mm\:ss") +
                                                   "]";
                                    speed = 0;
                                    dt    = DateTime.UtcNow;
                                }
                            }
                        }//.CopyTo(fileStream);
                    }
                }
            }
            catch (Exception x)
            {
            }
        }
Esempio n. 4
0
 public void Start(MultiDownloader multiDownloader)
 {
     Task.Run(() => Download(multiDownloader));
 }