예제 #1
0
        public async void findURLandDownload(object args)
        {
            object[]        param           = args as object[];
            RequestDownload request         = param[0] as RequestDownload;
            string          isRetriedString = param[1] as string;
            int             isRetried       = Convert.ToInt32(isRetriedString);

            try
            {
                string        url              = request.baseURL;
                List <string> urlsWithIframe   = new List <string>();
                List <string> urlsToDownload   = new List <string>();
                List <string> urlsWithFindLink = new List <string>();
                downloadAsync(urlsWithFindLink, urlsWithIframe, urlsToDownload, url, request);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception line : " + ex.ToString());
                if (isRetried == 1)
                {
                    object[] objs = new object[2];
                    objs[0] = request;
                    objs[1] = 0;
                    findURLandDownload(objs);
                }
            }
            finally
            {
            }
        }
예제 #2
0
        void OnBtnbtnStartDownloadUrlClicked(object sender, EventArgs args)
        {
            RequestDownload request = new RequestDownload();

            request.baseURL = txtPageUrl.Text;
            object[] objs = new object[2];
            objs[0] = request;
            objs[1] = "1";
            Thread t = new Thread(new ParameterizedThreadStart(findURLandDownload));

            t.Start(objs);
            //findURLandDownload(objs);
        }
예제 #3
0
        private async void downloadAsync(List <string> urlsWithFindLink, List <string> urlsWithIframe, List <string> urlsToDownload, string url, RequestDownload request)
        {
            try
            {
                string pageSource = "";

                pageSource       = getPageSource(url);
                urlsWithFindLink = extractURLFromHTMLHasVideoURL(url);

                if (pageSource.Contains("<iframe"))
                {
                    //urlsWithIframe = extractURLFromIframeTag(path, url);
                }

                if (null != urlsWithFindLink)
                {
                    for (int i = 0; i < urlsWithFindLink.Count; i++)
                    {
                        if (!urlsToDownload.Contains(urlsWithFindLink[i]))
                        {
                            urlsToDownload.Add(urlsWithFindLink[i]);
                        }
                    }
                }

                if (null != urlsWithIframe)
                {
                    for (int i = 0; i < urlsWithIframe.Count; i++)
                    {
                        if (!urlsToDownload.Contains(urlsWithIframe[i]))
                        {
                            urlsToDownload.Add(urlsWithIframe[i]);
                        }
                    }
                }



                if (null != urlsToDownload)
                {
                    for (int i = 0; i < urlsToDownload.Count; i++)
                    {
                        try
                        {
                            VideoInfor video = new VideoInfor();
                            video.DownloadUrl = WebUtility.UrlDecode(urlsToDownload[i]);
                            video.BasURL      = url;
                            string[] splitedURL = urlsToDownload[i].Split('/');
                            string   title      = RemoveIllegalPathCharacters(splitedURL[splitedURL.Length - 1]).ToLower();
                            if (!title.Contains(".mp4") && !title.Contains(".flv") && !title.Contains(".3gp") && !video.DownloadUrl.Contains(".m3u8"))
                            {
                                title = title + ".mp4";
                            }
                            video.Title = title;

#if __ANDROID__
                            var dir         = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDcim);
                            var newFilepath = System.IO.Path.Combine(dir.AbsolutePath, title);
                            video.Path = newFilepath;
#endif
#if __IOS__
                            video.Path = System.IO.Path.Combine(DependencyService.Get <IDownloadState>().OnDownloadStarted(), title);
#endif
                            new FileInfo(video.Path).Directory.Create();
                            downloadVideo(video, false);
                        }
                        catch (Exception ex)
                        {
                            txtPageSource.Text = ex.ToString();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }