Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Web;
- using System.Net;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using System.Text.RegularExpressions;
- namespace DecodingEntities
- {
- class Program
- {
- public static WebClient wc = new WebClient();
- static void Main(string[] args)
- {
- //JSON.net library required to run this code. http://james.newtonking.com/json
- //url = "https://www.facebook.com/video.php?v=1452983714984650";
- Console.WriteLine("Insert video URL:");
- string url = Console.ReadLine();
- string strRegex = @"params\"",\""(.*)\""]";
- Regex myRegex = new Regex(strRegex, RegexOptions.None);
- wc.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0");
- wc.Headers.Add("Content-Type", "text/html; charset=utf-8");
- string html = "";
- bool error = false;
- try
- {
- html = wc.DownloadString(url);
- }
- catch (WebException wex)
- {
- Console.WriteLine("Invalid URL");
- error = true;
- }
- if (!error)
- {
- string title = Regex.Match(html, @"<title id=\""pageTitle\"">(.*?) | .*? </title>").Groups[1].Value;
- string para = myRegex.Match(html).Groups[1].Value;
- para = clearEntities(para);
- int lindex = 0;
- string[] s = para.Split('}');
- for (int i = 0; i < 2; i++)
- {
- lindex += s[i].Length;
- }
- para = para.Substring(0, lindex + 2);
- Console.WriteLine("Searching video link...");
- try
- {
- List<Dictionary<string, string>> video_data = JObject.Parse(para).SelectToken("video_data").ToObject<List<Dictionary<string, string>>>();
- if (video_data[0].ContainsKey("hd_src"))
- {
- Console.WriteLine("Downloading HD video.\r\nStoring video: "+title+".mp4");
- DescarregaVideo(video_data[0]["hd_src"], title);
- }
- else if (video_data[0].ContainsKey("sd_src"))
- {
- Console.WriteLine("Downloading SD video.\r\nStoring video: " + title + ".mp4");
- DescarregaVideo(video_data[0]["sd_src"], title);
- }
- else
- {
- Console.WriteLine("No link.");
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine("Error searching link.");
- }
- }
- Console.ReadKey();
- }
- public static void DescarregaVideo(string url, string nom)
- {
- try
- {
- wc.DownloadFile(url, nom + ".mp4");
- Console.WriteLine("Download Complete.");
- }
- catch (WebException wex)
- {
- Console.WriteLine("Error during video download.");
- }
- }
- public static string clearEntities(string para)
- {
- para = para.Replace("[", "");
- para = para.Replace("]", "");
- para = para.Replace("\\u00257B", "{");
- para = para.Replace("\\u00257D", "}");
- para = para.Replace("\\u002522", "\"");
- para = para.Replace("\\u00253A", ":");
- para = para.Replace("\\u00252C", ",");
- para = para.Replace("\\u00255C", "\\");
- para = para.Replace("\\u00252F", "/");
- para = para.Replace("\\u00253F", "?");
- para = para.Replace("\\u00253D", "=");
- para = para.Replace("\\u002526", "&");
- para = para.Replace("\\u00255B", "[");
- para = para.Replace("\\u00255D", "]");
- return Uri.UnescapeDataString(para)+"\"}";
- }
- }
- }
Add Comment
Please, Sign In to add comment