public void GetCategoriesPornHub(VideoAdminDTO video) { using (var client = new WebClient()) { client.Headers.Add("user-agent", "Mozilla / 5.0(Windows NT 10.0; WOW64; Trident / 7.0; rv: 11.0) like Gecko"); string oldUrl = video.Url; try { var html = client.DownloadString(video.Url); video.Url = "https://www.pornhub.com/embed/" + video.Url.Substring(47); HtmlDocument document = new HtmlDocument(); document.LoadHtml(html); video.Categories = document.DocumentNode.SelectSingleNode("//div[@class='categoriesWrapper']").SelectNodes(".//a").Select(x => new CategoryDTO() { Name_en = x.InnerText }); video.Categories = video.Categories.Reverse().Skip(1); } catch { video.Url = "https://www.pornhub.com/embed/" + video.Url.Substring(47); video.LoadError = true; } } }
public void GetCategoriesDrTuber(VideoAdminDTO video) { using (var client = new WebClient()) { client.Headers.Add("user-agent", "Mozilla / 5.0(Windows NT 10.0; WOW64; Trident / 7.0; rv: 11.0) like Gecko"); var html = client.DownloadString(video.Url); HtmlDocument document = new HtmlDocument(); document.LoadHtml(html); if (!video.Url.Contains("embed")) { var array = video.Url.Split('/'); video.Url = "http://www.drtuber.com/embed/" + array[4]; } try { video.Categories = document.DocumentNode.SelectSingleNode("//div[@class='categories_list']") .SelectNodes(".//a") .Select(x => x.GetAttributeValue("title", string.Empty)) .Select(o => new CategoryDTO() { Name_en = o }); } catch { List <CategoryDTO> list = new List <CategoryDTO>(); video.Categories = list; } } }
public void GetCategoriesXhamster(VideoAdminDTO video) { using (var client = new WebClient()) { client.Headers.Add("user-agent", "Mozilla / 5.0(Windows NT 10.0; WOW64; Trident / 7.0; rv: 11.0) like Gecko"); var html = client.DownloadString(video.Url); HtmlDocument document = new HtmlDocument(); document.LoadHtml(html); if (!video.Url.Contains("embed")) { string[] array = video.Url.Split('-'); video.Url = "https://xhamster.com/xembed.php?video=" + array[array.Length - 1]; } try { video.Categories = document.DocumentNode.SelectNodes("//div[@class='entity-description-container__categories categories-container']") .First() .ChildNodes .Where(x => x.Name == "a") .Select(p => p.InnerText.Replace(" ", "").Replace("\n", "")).Select(o => new CategoryDTO() { Name_en = o }); } catch { List <CategoryDTO> list = new List <CategoryDTO>(); video.Categories = list; } } }
public async Task EditVideo(VideoListAdminDTO vid) { Video = await AdminRep.GetVideoByIdAsync(vid.Id); Video.DatabaseCategories = await AdminRep.GetCategoriesAsync(); Video.IsEdited = true; }
public async Task AddVideoAsync(VideoAdminDTO vid, string username) { var downloadPath = GetDownloadPath(); var previewfileName = GetVideoFileName(vid.Preview); var imgfileName = GetVideoFileName(vid.Img); using (var client = new WebClient()) { client.DownloadFile(vid.Preview, downloadPath + "/" + previewfileName); client.DownloadFile(vid.Img, downloadPath + "/" + imgfileName); } Video video = new Video(); video.Description = vid.Description; video.Title = vid.Title; video.Title_en = vid.Title_en; video.Url = vid.Url; video.Img = imgfileName; video.TimeStamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); //var ffMpeg = new NReco.VideoConverter.FFMpegConverter(); //string mp4Name = ChangeNameToMp4(previewfileName); //ffMpeg.ConvertMedia(downloadPath + "/" + previewfileName, downloadPath + "/" + "test.mp4", Format.mp4); //File.Delete(downloadPath + "/" + previewfileName); video.Preview = previewfileName; video.HD = vid.HD; video.Duration = vid.Duration; video.AllowMain = vid.AllowMain; using (var db = new myDb()) { var user = db.Users.Where(x => x.Username == username).First(); video.User = user; foreach (CategoryDTO item in vid.Categories) { Category tag = await db.Categories .Where(x => x.Name == item.Name) .FirstAsync(); video.Categories.Add(tag); } db.Videos.Add(video); await db.SaveChangesAsync(); } }
public async Task UpdateVideoAsync(VideoAdminDTO video) { using (var db = new myDb()) { var dbVideo = db.Videos.Find(video.Id); dbVideo.Title = video.Title; dbVideo.Description = video.Description; dbVideo.Img = video.Img; dbVideo.Preview = video.Preview; dbVideo.Url = video.Url; dbVideo.AllowMain = video.AllowMain; dbVideo.Categories.Clear(); foreach (CategoryDTO item in video.Categories) { var category = await db.Categories.Where(x => x.Name == item.Name).FirstAsync(); dbVideo.Categories.Add(category); } await db.SaveChangesAsync(); } }
public void GetCategoriesRedTube(VideoAdminDTO video) { using (var client = new WebClient()) { client.Headers.Add("user-agent", "Mozilla / 5.0(Windows NT 10.0; WOW64; Trident / 7.0; rv: 11.0) like Gecko"); var html = client.DownloadString(video.Url); HtmlDocument document = new HtmlDocument(); document.LoadHtml(html); if (!video.Url.Contains("embed")) { var url = video.Url.Substring(20); video.Url = "https://embed.redtube.com/?id=" + url; } var divs = document.DocumentNode.SelectNodes("//div[@class='video-infobox-content']"); video.Categories = divs[divs.Count - 2].SelectNodes(".//a") .Select(x => new CategoryDTO() { Name_en = x.InnerHtml, }); } }