Exemple #1
0
        public ActionResult GetVideolist(string input)
        {
            lst.Clear();
            string lineOfText1 = "";

            input = "angular_videos";
            string folderName = "Upload";

            string webRootPath = _hostingEnvironment.WebRootPath;
            string newPath     = Path.Combine(webRootPath, folderName);

            // var filestream = new System.IO.FileStream("./app_data/" + input + ".txt",
            var filestream = new System.IO.FileStream(newPath + "/" + input + ".txt",

                                                      // var filestream = new System.IO.FileStream("./app_data/" + input + ".txt",
                                                      System.IO.FileMode.Open,
                                                      System.IO.FileAccess.Read,
                                                      System.IO.FileShare.ReadWrite);


            System.IO.BufferedStream bs = new System.IO.BufferedStream(filestream);

            var file = new System.IO.StreamReader(bs, System.Text.Encoding.UTF8, true, 128);

            while ((lineOfText1 = file.ReadLine()) != null)
            {
                try
                {
                    VdeoData obj = new VdeoData();
                    obj.name = Youtube.Youtube.GetVideoId(lineOfText1);
                    if (obj.name.Length > 4 && !lst.Select(x => x.name).ToList().Contains(obj.name))
                    {
                        lst.Add(obj);
                    }

                    // Example(lineOfText1);
                    if (lst.Count > 200)
                    {
                        break;
                    }
                } //return Json(lst.Take(5));
                catch (Exception ex)
                {
                }
            }
            var list = JsonConvert.SerializeObject(lst, Formatting.None,
                                                   new JsonSerializerSettings()
            {
                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
            });

            return(Content(list, "application/json"));
        }
Exemple #2
0
        static async void Example(string line)
        {
            // This method runs asynchronously.
            VdeoData obj = new VdeoData();
            string   t   = await Task.Run(() => Youtube.Youtube.GetVideoId(line));

            obj.name = t;
            if (t != null && t.Length > 4 && !lst.Select(x => x.name).ToList().Contains(obj.name))
            {
                lst.Add(obj);
            }
        }