public override string GetVideoUrl(VideoInfo video) { string result = String.Empty; int p = video.VideoUrl.LastIndexOf('/'); if (p >= 0) { string id = video.VideoUrl.Substring(p + 1); string newToken = Doskabouter.Helpers.NPOHelper.GetToken(video.VideoUrl, GetProxy()); if (!String.IsNullOrEmpty(newToken)) { string webData = GetWebData(String.Format(fileUrlFormatString, id) + newToken, proxy: GetProxy()); JObject contentData = (JObject)JObject.Parse(webData); JArray items = contentData["items"][0] as JArray; List <KeyValuePair <string, string> > playbackOptions = new List <KeyValuePair <string, string> >(); foreach (JToken item in items) { string s = item.Value <string>("url"); Match m = Regex.Match(s, @"/ida/(?<quality>[^/]*)/"); if (!m.Success) { m = Regex.Match(s, @"(?<quality>\d+x\d+)_"); } if (m.Success) { string quality = m.Groups["quality"].Value; try { VideoQuality vq = (VideoQuality)Enum.Parse(typeof(VideoQuality), quality, true); if (Enum.IsDefined(typeof(VideoQuality), vq) && vq.Equals(preferredQuality)) { result = s; } } catch (ArgumentException) { }; playbackOptions.Add(new KeyValuePair <string, string>(quality, s)); } } playbackOptions.Sort(Compare); video.PlaybackOptions = new Dictionary <string, string>(); foreach (KeyValuePair <string, string> kv in playbackOptions) { video.PlaybackOptions.Add(kv.Key, kv.Value); } } if (String.IsNullOrEmpty(result)) { result = video.PlaybackOptions.Last().Value; } } return(result); }
public override string GetVideoUrl(VideoInfo video) { string result = String.Empty; int p = video.VideoUrl.LastIndexOf('/'); if (p >= 0) { string id = video.VideoUrl.Substring(p + 1); string webData = GetWebData(@"http://ida.omroep.nl/npoplayer/i.js"); Match m = Regex.Match(webData, @"token\s*=\s*""(?<token>[^""]*)""", defaultRegexOptions); if (m.Success) { webData = GetWebData(String.Format(fileUrlFormatString, id) + m.Groups["token"].Value); JObject contentData = (JObject)JObject.Parse(webData); JArray items = contentData["streams"] as JArray; List <KeyValuePair <string, string> > playbackOptions = new List <KeyValuePair <string, string> >(); foreach (JToken item in items) { string s = item.Value <string>(); m = Regex.Match(s, @"/ida/(?<quality>[^/]*)/"); if (m.Success) { string quality = m.Groups["quality"].Value; try { VideoQuality vq = (VideoQuality)Enum.Parse(typeof(VideoQuality), quality, true); if (Enum.IsDefined(typeof(VideoQuality), vq) && vq.Equals(preferredQuality)) { result = s; } } catch (ArgumentException) { }; playbackOptions.Add(new KeyValuePair <string, string>(quality, s)); } } playbackOptions.Sort(Compare); video.PlaybackOptions = new Dictionary <string, string>(); foreach (KeyValuePair <string, string> kv in playbackOptions) { video.PlaybackOptions.Add(kv.Key, kv.Value); } } if (String.IsNullOrEmpty(result)) { result = video.PlaybackOptions.Last().Value; } } return(result); }
public override string GetVideoUrl(VideoInfo video) { string result = String.Empty; int p = video.VideoUrl.LastIndexOf('/'); if (p >= 0) { string id = video.VideoUrl.Substring(p + 1); string webData = GetWebData(@"http://ida.omroep.nl/npoplayer/i.js?s=" + HttpUtility.UrlEncode(video.VideoUrl)); Match m = Regex.Match(webData, @"token\s*=\s*""(?<token>[^""]*)""", defaultRegexOptions); if (m.Success) { int first = -1; int second = -1; string token = m.Groups["token"].Value; for (int i = 5; i < token.Length - 4; i++) { if (Char.IsDigit(token[i])) { if (first == -1) { first = i; } else if (second == -1) { second = i; } } } if (first == -1) { first = 12; } if (second == -1) { second = 13; } char[] newToken = token.ToCharArray(); newToken[first] = token[second]; newToken[second] = token[first]; webData = GetWebData(String.Format(fileUrlFormatString, id) + new String(newToken)); JObject contentData = (JObject)JObject.Parse(webData); JArray items = contentData["streams"] as JArray; List <KeyValuePair <string, string> > playbackOptions = new List <KeyValuePair <string, string> >(); foreach (JToken item in items) { string s = item.Value <string>(); m = Regex.Match(s, @"/ida/(?<quality>[^/]*)/"); if (m.Success) { string quality = m.Groups["quality"].Value; try { VideoQuality vq = (VideoQuality)Enum.Parse(typeof(VideoQuality), quality, true); if (Enum.IsDefined(typeof(VideoQuality), vq) && vq.Equals(preferredQuality)) { result = s; } } catch (ArgumentException) { }; playbackOptions.Add(new KeyValuePair <string, string>(quality, s)); } } playbackOptions.Sort(Compare); video.PlaybackOptions = new Dictionary <string, string>(); foreach (KeyValuePair <string, string> kv in playbackOptions) { video.PlaybackOptions.Add(kv.Key, kv.Value); } } if (String.IsNullOrEmpty(result)) { result = video.PlaybackOptions.Last().Value; } } return(result); }