Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,038

HOME > .NET Framework > Forum > ช่วยหาแนวทางให้หน่อยครับ ผมอยากให้มันทำงาน รอบเดียวจบ ครับ


 

[.NET] ช่วยหาแนวทางให้หน่อยครับ ผมอยากให้มันทำงาน รอบเดียวจบ ครับ

 
Topic : 135688



โพสกระทู้ ( 4,440 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook


โค้ด ต้นฉบับ นะครับ
https://github.com/bertyhell/PlaylistDownloader/blob/master/PlaylistDownloader/PlaylistDownloader/Downloader.cs


ผมอยากให้รัน YoutubeDl แล้ว ต่อด้วย Ffmpeg ให้เสร็จก่อน แล้วจึงค่อยรันไฟล์ใหม่ ครับ
โค้ดต้นฉบับ รันทุกไฟล์พร้อมๆกันทั้งหมดทำให้เครื่องช้า ครับ



Tag : .NET, Win (Windows App), C#

Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2020-11-03 16:32:32 By : lamaka.tor View : 685 Reply : 7
 

 

No. 1



โพสกระทู้ ( 9,590 )
บทความ ( 2 )



สถานะออฟไลน์


Code (C#)
01.int count_run_1 = 0;
02.int count_run_2 = 0;
03.function run1(id){
04.  // do something
05.  count_run_1--;
06.  if( count_run_1<1){
07.    loop_run2();
08.  }
09.}
10.function loop_run2(){
11.  for( i = 0 ; i < 10 ; i++){
12.    count_run_1++;
13.    async run1( i );
14.  }
15.}
16.for( i = 0 ; i < 10 ; i++){
17.  count_run_1++;
18.  async run1( i );
19.}


แค่ตัวอย่าง ง่ายๆ ของ การกำหนด การ run แบบ asyn เป็นชุด syn
ไม่ต้องสนไวยกรณ์ นะครับ ลืมหมดแล้ว ช่วงไม่มีงาน visual ก็ส่งกลับเข้า หนังสือ เข้าเวป หมด 5555
ไว้ต้องเขียน ค่อยรื้อมาใหม่
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2020-11-04 11:32:18 By : Chaidhanan
 

 

No. 2



โพสกระทู้ ( 4,440 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

ตอบความคิดเห็นที่ : 1 เขียนโดย : Chaidhanan เมื่อวันที่ 2020-11-04 11:32:18
รายละเอียดของการตอบ ::
ผมลองดักทุกทาง แล้วก็ไม่ช่วยอะไรได้เลยครับ

ปัญหามันอยู่ที่การทำงานร่วมกับไฟล์ YoutubeDl และ Ffmpeg มันส่งค่ากลับมาเพื่อให้เช็คว่างานเสร็จ หรือไม่เสร็จ แล้วมันไม่ตรง ครับ
มันจึงกลายเป็นว่า ถึงแม้ งานจะไม่เสร็จ 100 % แต่มันก็ยังทำงานอื่นต่อไปอีก ครับ


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2020-11-04 14:51:32 By : lamaka.tor
 

 

No. 3



โพสกระทู้ ( 9,590 )
บทความ ( 2 )



สถานะออฟไลน์


ถ้าจำเป็น ต้องเสร็จ เพื่อ ทำงานต่อ ก็ต้อง ใช้ promise await แล้วล่ะครับ

จะให้มัน ทำงานแบบ asyncronize คงไม่ได้
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2020-11-04 19:01:39 By : Chaidhanan
 

 

No. 4



โพสกระทู้ ( 4,440 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

ตอบความคิดเห็นที่ : 3 เขียนโดย : Chaidhanan เมื่อวันที่ 2020-11-04 19:01:39
รายละเอียดของการตอบ ::
ตัวนี้ผมก็ทำไปแล้วเช่นกันครับ
อย่างที่ผมบอกครับ

ปัญหามันอยู่ที่การทำงานร่วมกับไฟล์ YoutubeDl และ Ffmpeg มันส่งค่ากลับมาเพื่อให้เช็คว่างานเสร็จ หรือไม่เสร็จ แล้วมันไม่ตรง ครับ
มันจึงกลายเป็นว่า ถึงแม้ งานจะไม่เสร็จ 100 % แต่มันก็ยังทำงานอื่นต่อไปอีก ครับ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2020-11-04 19:56:56 By : lamaka.tor
 

 

No. 5



โพสกระทู้ ( 9,590 )
บทความ ( 2 )



สถานะออฟไลน์


https://stackoverflow.com/questions/10788982/is-there-any-async-equivalent-of-process-start
เพื่อจะได้ประโยชน์
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2020-11-05 02:03:09 By : Chaidhanan
 

 

No. 6



โพสกระทู้ ( 4,440 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

ตอบความคิดเห็นที่ : 5 เขียนโดย : Chaidhanan เมื่อวันที่ 2020-11-05 02:03:09
รายละเอียดของการตอบ ::
ในโค้ดเดิม มันมีอยู่แล้วครับ
แล้วมันก็มีปัญหาตั้งแต่โค้ดเดิม เลยครับ
สั่งดาวน์โหลดปุ๊บ มันโหลดทั้งหมดในเวลาเดียวกันเลยครับ

ตอนนี้ผมเอามันออก แล้วใช้ task คุมทั้ง หมด ก็ค่อยยังชั่วขึ้นบ้าง
โหลดทีละไฟล์ ได้ แต่มันก็ยังมีบ้างที่ เหมือนว่า มัน รันไปใกล้จะครบ 100 % แล้ว
ไฟล์อื่นก็ทำงานต่อ แล้วก็ ทำงานต่อๆ กันไปอีก มากกว่า 2 ไฟล์ ทำให้เครื่องค้างเช่นกัน ครับ



แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2020-11-05 07:57:13 By : lamaka.tor
 

 

No. 7



โพสกระทู้ ( 4,440 )
บทความ ( 23 )



สถานะออฟไลน์
Facebook

โค้ดเดิม มันจะได้แบบนี้ครับ
1

Code (C#)
001.using System;
002.using System.Collections.Generic;
003.using System.ComponentModel;
004.using System.Configuration;
005.using System.Diagnostics;
006.using System.IO;
007.using System.Linq;
008.using System.Text.RegularExpressions;
009.using System.Threading;
010.using System.Threading.Tasks;
011.using NLog;
012. 
013.namespace PlaylistDownloader
014.{
015.    public class Downloader : BackgroundWorker
016.    {
017. 
018.        private readonly ICollection<PlaylistItem> _playlist;
019.        private readonly RunSettings _runSettings;
020.        public double progressValue = 0d;
021.        private int _progress;
022.        private readonly int _totalSongs;
023.        private CancellationTokenSource _cts;
024.        private static Logger logger = LogManager.GetCurrentClassLogger();
025. 
026.        public Downloader(RunSettings settings, ICollection<PlaylistItem> playlist)
027.        {
028.            _playlist = playlist;
029.            _totalSongs = _playlist.Count;
030. 
031.            _cts = new CancellationTokenSource();
032. 
033.            _runSettings = settings;
034.        }
035. 
036.        protected override void OnDoWork(DoWorkEventArgs args)
037.        {
038.            _progress = 0;
039. 
040.            //setup cancelation
041.            ParallelOptions po = new ParallelOptions
042.            {
043.                CancellationToken = _cts.Token,
044.                MaxDegreeOfParallelism = Environment.ProcessorCount
045.            };
046. 
047.            try
048.            {
049.                // Parallal execution
050.                try
051.                {
052.                    Parallel.ForEach(_playlist, po, async item =>
053.                    {
054.                        try
055.                        {
056.                            po.CancellationToken.ThrowIfCancellationRequested();
057.                            await DownloadPlaylistItem(item);
058.                        }
059.                        catch (InvalidOperationException) { } //ignore exceptions when aborting download
060.                        catch (Win32Exception) { } //ignore process exception if killed during process exiting
061.                    });
062.                }
063.                catch (OperationCanceledException) { }
064.                finally
065.                {
066.                    if (_cts != null)
067.                    {
068.                        _cts.Dispose();
069.                        _cts = null;
070.                    }
071.                }
072.                // Serial execution
073.                //foreach (PlaylistItem item in _playlist)
074.                //{
075.                //    try
076.                //    {
077.                //        DownloadPlaylistItem(item, po);
078.                //        //ConvertPlaylistItem(item, po);
079.                //    }
080.                //    catch (InvalidOperationException) { } //ignore exceptions when aborting download
081.                //    catch (Win32Exception) { } //ignore process exception if killed during process exiting
082.                //}
083.            }
084.            catch (OperationCanceledException) { } //ignore exceptions caused by canceling paralel.foreach loop
085.        }
086. 
087.        public async Task<string> DownloadPlaylistItem(PlaylistItem item)
088.        {
089.            string destinationFilePathWithoutExtension = null;
090.            string tempFilePathWithoutExtension = null;
091. 
092.            item.DownloadProgress = 5;
093.            if (!string.IsNullOrWhiteSpace(item.FileName))
094.            {
095. 
096.                
097.                var workingFolder = Path.GetTempPath();
098.                tempFilePathWithoutExtension = Path.Combine(Path.GetTempPath(), item.FileName);
099.                destinationFilePathWithoutExtension = Path.Combine(_runSettings.SongsFolder, item.FileName);
100. 
101.                if (!File.Exists(destinationFilePathWithoutExtension + ".mp3"))
102.                {
103.                    item.DownloadProgress = 10;
104. 
105.                    
106.                        // Download videoand extract the mp3 file
107.                        await StartProcess(
108.                            _runSettings.YoutubeDlPath,
109.                            string.Format(" --ffmpeg-location \"{0}\"" +
110.                                          " --format bestaudio[ext=mp3]/best" +
111.                                          " --audio-quality 0" +
112.                                          " --no-part" +
113.                                          " --extract-audio" +
114.                                          " --audio-format mp3" +
115.                                          " --output \"{1}\"" +
116.                                          " {2}", _runSettings.FfmpegPath, tempFilePathWithoutExtension + "-raw.%(ext)s", item.Link),
117.                            item,
118.                            ParseYoutubeDlProgress);
119.                        // -o "c:\Users\Julian\Music\PlaylistDownloader\\%(title)s.%(ext)s"
120. 
121.                        // Normalize audio file after the youtube-dl process has exited
122.                        await StartProcess(_runSettings.FfmpegPath,
123.                            string.Format(" -i \"{0}\"" +
124.                                          " -af loudnorm=I=-16:TP=-1.5:LRA=11" +
125.                                          //" -ar 48k" +
126.                                          " -y" +
127.                                          " \"{1}\"", tempFilePathWithoutExtension + "-raw.mp3", tempFilePathWithoutExtension + _runSettings.NormalizedSuffix + ".mp3"),
128.                            item,
129.                            ParseYoutubeDlProgress);
130. 
131.                        // move to destination
132.                        File.Move(tempFilePathWithoutExtension + _runSettings.NormalizedSuffix + ".mp3",
133.                            destinationFilePathWithoutExtension + _runSettings.NormalizedSuffix + ".mp3");
134. 
135.                        // Delete the non normalized file after completion if not in debug mode
136.                        File.Delete(Path.Combine(_runSettings.SongsFolder, item.FileName + "-raw.mp3"));
137.                     
138. 
139. 
140.                }
141.            }
142. 
143.            item.DownloadProgress = 100;
144.            _progress++;
145.            OnProgressChanged(new ProgressChangedEventArgs(_progress * 100 / _totalSongs, null));
146.            progressValue = Convert.ToDouble(((double)_progress * 100d / (double)_totalSongs).ToString("N2"));
147. 
148. 
149.            return destinationFilePathWithoutExtension;
150.        }
151. 
152.        private void ParseYoutubeDlProgress(string consoleLine, PlaylistItem item)
153.        {
154.            // [download]   0.0% of 4.66MiB at 336.14KiB/s ETA 00:14
155.            Regex extractDownloadProgress = new Regex(@"\[download\][\s]*([0-9\.]+)%");
156.            Match match = extractDownloadProgress.Match(consoleLine);
157.            if (match.Length > 0 && match.Groups.Count >= 2)
158.            {
159.                if (double.TryParse(match.Groups[1].Value, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out double downloadProgress))
160.                {
161.                    logger.Info("[download + convert progress] " + downloadProgress);
162.                    if (downloadProgress > 100 || _progress > 100)
163.                    {
164.                        Debugger.Break();
165.                    }
166.                    item.DownloadProgress = (int)(10.0 + downloadProgress / 100 * 60);
167.                    OnProgressChanged(new ProgressChangedEventArgs(_progress * 100 / _totalSongs, null));
168.                }
169.            }
170.        }
171. 
172.        private void ParseNormalizeProgress(string consoleLine, PlaylistItem item)
173.        {
174.            // Duration: 00:30:58.39, start: 0.023021, bitrate: 106 kb/s
175.            // size=     105kB time=00:00:06.69 bitrate= 128.7kbits/s speed=13.4x
176.            Regex extractDuration = new Regex(@"Duration:\s*([0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{2}),\sstart:");
177.            Match match = extractDuration.Match(consoleLine);
178.            if (match.Length > 0 && match.Groups.Count >= 2)
179.            {
180.                logger.Info("Duration: " + match.Groups[0].Value);
181.                item.Duration = TimeSpan.Parse(match.Groups[0].Value).TotalSeconds;
182.                logger.Info("Duration seconds: " + item.Duration);
183.                return;
184.            }
185. 
186.            if (item.Duration == 0)
187.            {
188.                return;
189.            }
190. 
191.            Regex extractProgressDuration = new Regex(@"time=([0-9]{2}:[0-9]{2}:[0-9]{2}\.[0-9]{2})\s*bitrate=");
192.            match = extractProgressDuration.Match(consoleLine);
193.            if (match.Length > 0 && match.Groups.Count >= 2)
194.            {
195.                logger.Info("progress Duration: " + match.Groups[0].Value);
196.                logger.Info("progress Duration seconds: " + TimeSpan.Parse(match.Groups[0].Value).TotalSeconds);
197.                item.DownloadProgress = (int)(70 + TimeSpan.Parse(match.Groups[0].Value).TotalSeconds / item.Duration * 30);
198.                OnProgressChanged(new ProgressChangedEventArgs(_progress * 100 / _totalSongs, null));
199.            }
200.        }
201. 
202.        private Task<string> StartProcess(string executablePath, string arguments, PlaylistItem item, Action<string, PlaylistItem> parseProgressFunc)
203.        {
204.            var promise = new TaskCompletionSource<string>();
205.            logger.Info("[RUN CMD] " + executablePath + arguments);
206.            Process process = new Process
207.            {
208.                StartInfo =
209.                {
210.                    FileName = executablePath,
211.                    Arguments = arguments,
212.                    CreateNoWindow = !_runSettings.IsDebug,
213.                    WindowStyle = _runSettings.IsDebug ? ProcessWindowStyle.Normal : ProcessWindowStyle.Hidden,
214.                    RedirectStandardOutput = true,
215.                    RedirectStandardError = true,
216.                    UseShellExecute = false
217. 
218.                },
219.                EnableRaisingEvents = true
220.            };
221.            // --audio-quality 5 --extract-audio --audio-format mp3  -o "c:\Users\Julian\Music\PlaylistDownloader\\%(title)s.%(ext)s" https://www.youtube.com/watch?v=mDuElaL1dU0
222. 
223.            process.OutputDataReceived += (object sender, DataReceivedEventArgs e) =>
224.            {
225.                string consoleLine = e.Data;
226.                if (!string.IsNullOrWhiteSpace(consoleLine))
227.                {
228.                    logger.Info(consoleLine);
229.                    parseProgressFunc(consoleLine, item);
230.                }
231. 
232.                if (CancellationPending)
233.                {
234.                    logger.Info("Canceling process because of user: " + executablePath);
235.                    process.Close();
236.                    promise.SetResult(null);
237.                }
238.            };
239. 
240.            process.ErrorDataReceived += (object sender, DataReceivedEventArgs e) =>
241.            {
242.                string consoleLine = e.Data;
243. 
244.                if (!string.IsNullOrWhiteSpace(consoleLine))
245.                {
246.                    logger.Info("Error: " + consoleLine);
247.                    parseProgressFunc(consoleLine, item);
248.                }
249. 
250.                if (CancellationPending)
251.                {
252.                    logger.Info("Canceling process because of user: " + executablePath);
253.                    process.Close();
254.                    promise.SetResult(null);
255.                }
256.            };
257. 
258.            process.Exited += new EventHandler((object sender, EventArgs e) =>
259.            {
260.                process.Dispose();
261.                logger.Info("Closing process");
262.                promise.SetResult(null);
263.            });
264. 
265.            process.Start();
266. 
267.            process.BeginOutputReadLine();
268.            process.BeginErrorReadLine();
269. 
270.            return promise.Task;
271.        }
272. 
273.        internal void Abort()
274.        {
275.            if (_cts != null)
276.            {
277.                _cts.Cancel();
278.                _cts = null;
279.            }
280.            CancelAsync();
281.        }
282. 
283.        private static string MakeValidFileName(string name)
284.        {
285.            return Regex.Replace(
286.                name,
287.                "[^A-Za-z0-9_ -]+"/*Matches any nonword character. Equivalent to '[^A-Za-z0-9_]'*/
288.                "-",
289.                RegexOptions.IgnoreCase).Trim('-', ' ').ToLower();
290.        }
291.    }
292.}


โค้ดที่ปรับแต่งแล้วได้ประมาณนี้ครับ

2

Code (C#)
001.using System;
002.using System.Collections.Generic;
003.using System.ComponentModel;
004.using System.Configuration;
005.using System.Diagnostics;
006.using System.IO;
007.using System.Linq;
008.using System.Text.RegularExpressions;
009.using System.Threading;
010.using System.Threading.Tasks;
011.using NLog;
012. 
013.namespace PlaylistDownloader
014.{
016. 
017.    public class Downloader : BackgroundWorker
018.    {
019. 
020.        private readonly List<PlaylistItem> _playlist;
021.        private readonly RunSettings _runSettings;
022. 
023.        private int _progress;
024.        private int _totalSongs;
025.        private int _completeSongs;
026.        private CancellationTokenSource _cts;
027.        private static Logger logger = LogManager.GetCurrentClassLogger();
028.        public double progressValue = 0d;
029.        public Downloader(RunSettings settings, ICollection<PlaylistItem> playlist)
030.        {
031.            _playlist = playlist.ToList<PlaylistItem>();
032.            _totalSongs = _playlist.Count;
033. 
034.            _cts = new CancellationTokenSource();
035. 
036.            _runSettings = settings;
037.        }
038.        int itemIndex = 0;
039.        protected override void OnDoWork(DoWorkEventArgs args)
040.        {
041.            _progress = 0;
042. 
043.            LimitedConcurrencyLevelTaskScheduler scheduler = new LimitedConcurrencyLevelTaskScheduler(1);
044.            var factory = new TaskFactory(scheduler);
045.            var tasks = new List<Task>();
046. 
047.            _playlist.ForEach(plst =>
048.            {
049.                tasks.Add(factory.StartNew(() => DownloadPlaylistItem(plst)));
050.            });
051. 
052.            Task.WaitAll(tasks.ToArray());
053. 
054. 
055.        }
056. 
057.        public void DownloadPlaylistItem(PlaylistItem item)
058.        {
059.            string destinationFilePathWithoutExtension = null;
060.             string tempFilePathWithoutExtension = null;
061. 
062.            item.DownloadProgress = 5;
063.            if (!string.IsNullOrWhiteSpace(item.FileName) )
064.            {
065.                tempFilePathWithoutExtension = Path.Combine(_runSettings.FolTemp, MakeValidFileName(item.FileName)) ;
066.                destinationFilePathWithoutExtension = Path.Combine(_runSettings.SongsFolder + "\\" + MakeValidFileName(item.OwnerName), MakeValidFileName(item.FileName)) ;
067.                item.DownloadProgress = 10;
068.                if (!File.Exists(destinationFilePathWithoutExtension) || !File.Exists(tempFilePathWithoutExtension))
069.                {
070.                  StartProcessyoutube_dl(item, tempFilePathWithoutExtension, destinationFilePathWithoutExtension,ParseYoutubeDlProgress);
071.                }
072.                else
073.                {
074.                    Finish(item);
075.                }
076.            }
077.            else
078.            {
079.                Finish(item);
080. 
081.            }
082. 
083. 
084.        }
085.      
086.        private string StartProcessyoutube_dl( PlaylistItem item, string tempFile, string desFile, Action<string, PlaylistItem> parseProgressFunc)
087.        {
088.            string executablePath = _runSettings.YoutubeDlPath;
089.            string destinationFilePathWithoutExtension = desFile;
090.            string tempFilePathWithoutExtension = tempFile;
091.            var promise = new TaskCompletionSource<string>();
092. 
093.            Directory.CreateDirectory(Path.GetDirectoryName(destinationFilePathWithoutExtension));
094. 
095.            string arguments = string.Format(" --output \"{0}\"" +
096.                              " {1}",  destinationFilePathWithoutExtension + ".mp4", item.Link);
097. 
098.            logger.Info("[RUN CMD] " + executablePath + arguments);
099.            string _filename = executablePath;
100.            Process process = new Process
101.            {
102.                StartInfo =
103.              {
104.                  FileName = executablePath,
105.                  Arguments = arguments,
106.                  CreateNoWindow = !_runSettings.IsDebug,
107.                  WindowStyle = _runSettings.IsDebug ? ProcessWindowStyle.Normal : ProcessWindowStyle.Hidden,
108.                  RedirectStandardOutput = true,
109.                  RedirectStandardError = true,
110.                  UseShellExecute = false
111. 
112.              },
113.                EnableRaisingEvents = true
114.            };
115.            // --audio-quality 5 --extract-audio --audio-format mp3  -o "c:\Users\Julian\Music\PlaylistDownloader\\%(title)s.%(ext)s" https://www.youtube.com/watch?v=mDuElaL1dU0
116. 
117.            process.OutputDataReceived += (object sender, DataReceivedEventArgs e) =>
118.            {
119.                string consoleLine = e.Data;
120.                if (!string.IsNullOrWhiteSpace(consoleLine))
121.                {
122.                    logger.Info(consoleLine);
123.                    parseProgressFunc(consoleLine, item);
124.                }
125. 
126.                if (CancellationPending)
127.                {
128.                    logger.Info("Canceling process because of user: " + executablePath);
129.                    process.Close();
130.                    promise.SetResult(null);
131.                }
132.            };
133. 
134.            process.ErrorDataReceived += (object sender, DataReceivedEventArgs e) =>
135.            {
136.                string consoleLine = e.Data;
137. 
138.                if (!string.IsNullOrWhiteSpace(consoleLine))
139.                {
140.                    logger.Info("Error: " + consoleLine);
141.                    parseProgressFunc(consoleLine, item);
142.                }
143. 
144.                if (CancellationPending)
145.                {
146.                    logger.Info("Canceling process because of user: " + executablePath);
147.                    process.Close();
148.                    promise.SetResult(null);
149.                }
150.               // Finish(item, tempFilePathWithoutExtension);
151.            };
152. 
153.            process.Exited += new EventHandler((object sender, EventArgs e) =>
154.            {
155. 
156.                process.Dispose();
157.                logger.Info("Closing process");
158.                promise.SetResult(null);
159.                Finish(item);
160.                /* if (File.Exists(tempFilePathWithoutExtension + ".mp4"))
161.                 {
162.                  if(new FileInfo(tempFilePathWithoutExtension + ".mp4").Length>0)
163.                 StartProcessffmpeg(item, tempFilePathWithoutExtension , destinationFilePathWithoutExtension, ParseYoutubeDlProgress);
164.                 }*/
165. 
166. 
167. 
168.            });
169. 
170.            process.Start();
171. 
172.            process.BeginOutputReadLine();
173.            process.BeginErrorReadLine();
174. 
175.            return promise.Task.Result;
176.        }
177. 
178.  
179. 
180.        private void ParseYoutubeDlProgress(string consoleLine, PlaylistItem item)
181.        {
182.            // [download]   0.0% of 4.66MiB at 336.14KiB/s ETA 00:14
183.            Regex extractDownloadProgress = new Regex(@"\[download\][\s]*([0-9\.]+)%");
184.            Match match = extractDownloadProgress.Match(consoleLine);
185.            if (match.Length > 0 && match.Groups.Count >= 2)
186.            {
187.                if (double.TryParse(match.Groups[1].Value, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out double downloadProgress))
188.                {
189.                    logger.Info("[download + convert progress] " + downloadProgress);
190.                    if (downloadProgress > 100)//|| _progress > 100
191.                    {
192. 
193.                        Debugger.Break();
194.                    }
195.                    item.DownloadProgress = (double)(10.0 + downloadProgress / 100 * 90);
196. 
197.                    OnProgressChanged(new ProgressChangedEventArgs(_progress * 100 / _totalSongs, null));
198. 
199.                }
200.            }
201.        }
202. 
203. 
204.        public void Finish(PlaylistItem item)
205.        {
206.            item.DownloadProgress = 100;
207.            itemIndex++;
208.            _progress++;
209.            progressValue = Convert.ToDouble(((double)_progress * 100d / (double)_totalSongs).ToString("N2"));
210.            OnProgressChanged(new ProgressChangedEventArgs(_progress * 100 / _totalSongs, null));
211.            try
212.            {
213. 
214.                if (itemIndex < _playlist.Count)
215.                    DownloadPlaylistItem(_playlist[itemIndex]);
216.                /*if(File.Exists(tempFilePathWithoutExtension + ".mp4"))
217.                File.Delete(tempFilePathWithoutExtension + ".mp4");*/
218.            }
219.            catch { }
220. 
221. 
222.        }
223.        internal void Abort()
224.        {
225.            if (_cts != null)
226.            {
227.                _cts.Cancel();
228.                _cts = null;
229.            }
230.            CancelAsync();
231.        }
232. 
233.        private static string MakeValidFileName(string name)
234.        {
235.            /* return Regex.Replace(
236.                 name,
237.                 "[^A-Za-z0-9_ -]+",  /*Matches any nonword character. Equivalent to '[^A-Za-z0-9_]'*
238.                 "-",
239.                 RegexOptions.IgnoreCase).Trim('-', ' ').ToLower();*/
240. 
241.            return new Regex(@"([~\""#%&*:<>?/\{|}\]\[\.]{1,})", RegexOptions.None).Replace(name, "");
242.        }
243. 
244.    }
245.}




ปล.ไม่ทราบว่ามีใคร มี โค้ดดาวน์โหลดไฟล์ยูทูปไม๊ ครับ ที่ไม่ใช่ youtube-dl ครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2020-11-05 08:43:32 By : lamaka.tor
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ช่วยหาแนวทางให้หน่อยครับ ผมอยากให้มันทำงาน รอบเดียวจบ ครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)





ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2025 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่