public override string GetVideoUrl(VideoInfo video) { login(); string url = string.Format(videoPlayUrl, video.VideoUrl); XmlDocument xDoc = GetWebData <XmlDocument>(url, cookies: cc); XmlNode errorElement = xDoc.SelectSingleNode("//error"); if (errorElement != null) { throw new OnlineVideosException(errorElement.SelectSingleNode("./description/text()").InnerText); } XmlNode drm = xDoc.SelectSingleNode("//drmProtected"); if (drm != null && drm.InnerText.Trim().ToLower() == "true") { throw new OnlineVideosException("DRM protected content, sorry! :/"); } foreach (XmlElement item in xDoc.SelectNodes("//items/item")) { string mediaformat = item.GetElementsByTagName("mediaFormat")[0].InnerText.ToLower(); string itemUrl = item.GetElementsByTagName("url")[0].InnerText.Trim(); if (mediaformat.StartsWith("mp4") && itemUrl.ToLower().EndsWith(".f4m")) { url = string.Concat(itemUrl, "?hdcore=3.5.0&g=", HelperUtils.GetRandomChars(12)); } else if (mediaformat.StartsWith("mp4") && itemUrl.ToLower().Contains(".f4m?")) { url = string.Concat(itemUrl, "&hdcore=3.5.0&g=", HelperUtils.GetRandomChars(12)); } else if (mediaformat.StartsWith("smi")) { video.SubtitleText = GetWebData(itemUrl, cookies: cc, encoding: System.Text.Encoding.Default); } } return(url); }
public override string GetVideoUrl(VideoInfo video) { string url = string.Format(videoPlayUrl, video.VideoUrl); XmlDocument xDoc = GetWebData <XmlDocument>(url); XmlNode errorElement = xDoc.SelectSingleNode("//error"); if (errorElement != null) { throw new OnlineVideosException(errorElement.SelectSingleNode("./description/text()").InnerText); } XmlNode drm = xDoc.SelectSingleNode("//drmProtected"); if (drm != null && drm.InnerText.Trim().ToLower() == "true") { throw new OnlineVideosException("DRM protected content, sorry! :/"); } foreach (XmlElement item in xDoc.SelectNodes("//items/item")) { string mediaformat = item.GetElementsByTagName("mediaFormat")[0].InnerText.ToLower(); string itemUrl = item.GetElementsByTagName("url")[0].InnerText.Trim(); if (mediaformat.StartsWith("mp4") && itemUrl.ToLower().EndsWith(".f4m")) { url = string.Concat(itemUrl, "?hdcore=3.5.0&g=", HelperUtils.GetRandomChars(12)); } else if (mediaformat.StartsWith("mp4") && itemUrl.ToLower().Contains(".f4m?")) { url = string.Concat(itemUrl, "&hdcore=3.5.0&g=", HelperUtils.GetRandomChars(12)); } else if (mediaformat.StartsWith("webvtt")) { try { string srt = GetWebData(itemUrl, encoding: System.Text.Encoding.Default); Regex rgx; //Remove WEBVTT stuff rgx = new Regex(@"WEBVTT"); srt = rgx.Replace(srt, new MatchEvaluator((Match m) => { return(string.Empty); })); //Add hours rgx = new Regex(@"(\d\d:\d\d\.\d\d\d)\s*-->\s*(\d\d:\d\d\.\d\d\d).*?\n", RegexOptions.Multiline); srt = rgx.Replace(srt, new MatchEvaluator((Match m) => { return("00:" + m.Groups[1].Value + " --> 00:" + m.Groups[2].Value + "\n"); })); // Remove all trailing stuff, ie in 00:45:21.960 --> 00:45:25.400 A:end L:82% rgx = new Regex(@"(\d\d:\d\d:\d\d\.\d\d\d)\s*-->\s*(\d\d:\d\d:\d\d\.\d\d\d).*\n", RegexOptions.Multiline); srt = rgx.Replace(srt, new MatchEvaluator((Match m) => { return(m.Groups[1].Value + " --> " + m.Groups[2].Value + "\n"); })); //Remove all tags rgx = new Regex(@"</{0,1}[^>]+>"); srt = rgx.Replace(srt, string.Empty); //Add index rgx = new Regex(@"(?<time>\d\d:\d\d:\d\d\.\d\d\d\s*?-->\s*?\d\d:\d\d:\d\d\.\d\d\d)"); int i = 0; foreach (Match m in rgx.Matches(srt)) { i++; string time = m.Groups["time"].Value; srt = srt.Replace(time, i + "\n" + time); } srt = HttpUtility.HtmlDecode(srt).Trim(); video.SubtitleText = srt; } catch { } } } return(url); }
public override string GetVideoUrl(VideoInfo video) { bool isArchive = video.GetOtherAsString() == cArchiveCategory; string archiveUrl = ""; if (isArchive) { Regex archiveRgx = new Regex(@".*(?<prefix>\d-)(?<id>\d*)"); Match archiveMatch = archiveRgx.Match(video.VideoUrl); if (archiveMatch.Success) { Regex mediakantaIdRegex = new Regex(@"""mediakantaId"":""(?<id>[^""]*)"); string id = archiveMatch.Groups["id"].Value; Match mediakantaIdMatch = mediakantaIdRegex.Match(GetWebData(string.Format(cUrlArchiveEmbedFormat, id, id))); if (mediakantaIdMatch.Success) { archiveUrl = archiveMatch.Groups["prefix"].Value + mediakantaIdMatch.Groups["id"].Value; } } } string url = string.Format(cUrlHdsFormat, isArchive ? archiveUrl : video.VideoUrl); JObject json = GetWebData <JObject>(url, cache: false); JToken hdsStream = json["data"]["media"]["HDS"].FirstOrDefault(h => h["subtitles"] != null && h["subtitles"].Count() > 0); if (hdsStream == null) { hdsStream = json["data"]["media"]["HDS"].First; } else { JToken subtitle = hdsStream["subtitles"].FirstOrDefault(s => s["lang"].Value <string>() == ApiLanguage); if (subtitle == null) { subtitle = hdsStream["subtitles"].FirstOrDefault(s => s["lang"].Value <string>() == ApiOtherLanguage); } if (subtitle != null && subtitle["uri"] != null) { video.SubtitleUrl = subtitle["uri"].Value <string>(); } } string data = hdsStream["url"].Value <string>(); byte[] bytes = Convert.FromBase64String(data); RijndaelManaged rijndael = new RijndaelManaged(); byte[] iv = new byte[16]; Array.Copy(bytes, iv, 16); rijndael.IV = iv; rijndael.Key = Encoding.ASCII.GetBytes("yjuap4n5ok9wzg43"); rijndael.Mode = CipherMode.CFB; rijndael.Padding = PaddingMode.Zeros; ICryptoTransform decryptor = rijndael.CreateDecryptor(rijndael.Key, rijndael.IV); int padLen = 16 - bytes.Length % 16; byte[] newbytes = new byte[bytes.Length - 16 + padLen]; Array.Copy(bytes, 16, newbytes, 0, bytes.Length - 16); Array.Clear(newbytes, newbytes.Length - padLen, padLen); string result = null; using (MemoryStream msDecrypt = new MemoryStream(newbytes)) { using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read)) { using (StreamReader srDecrypt = new StreamReader(csDecrypt)) { result = srDecrypt.ReadToEnd(); } } } Regex r; if (video.GetOtherAsString() == cApiContentTypeTvLive) { r = new Regex(@"(?<url>.*\.f4m)"); } else { r = new Regex(@"(?<url>.*hmac=[a-z0-9]*)"); } Match m = r.Match(result); if (m.Success) { result = m.Groups["url"].Value; } if (video.GetOtherAsString() == cApiContentTypeTvLive) { result += "?g=" + HelperUtils.GetRandomChars(12) + "&hdcore=3.3.0&plugin=flowplayer-3.3.0.0"; MPUrlSourceFilter.AfhsManifestUrl f4mUrl = new MPUrlSourceFilter.AfhsManifestUrl(result) { LiveStream = true }; result = f4mUrl.ToString(); } else { result += "&g=" + HelperUtils.GetRandomChars(12) + "&hdcore=3.3.0&plugin=flowplayer-3.3.0.0"; } return(result); }
public override string GetVideoUrl(VideoInfo video) { string url = string.Format("http://player.yle.fi/api/v1/media.jsonp?protocol=HDS&client=areena-flash-player&id={0}", video.VideoUrl); string subtitleUrl = string.Empty; JObject json = GetWebData <JObject>(url, cache: false); JToken hdsStream = json["data"]["media"]["HDS"].FirstOrDefault(h => h["subtitles"] != null && h["subtitles"].Count() > 0); if (hdsStream == null) { hdsStream = json["data"]["media"]["HDS"].First; } else { JToken subtitle = hdsStream["subtitles"].FirstOrDefault(s => s["lang"].Value <string>() == ApiLanguage); if (subtitle == null && ApiLanguage == "fi") { subtitle = hdsStream["subtitles"].FirstOrDefault(s => s["lang"].Value <string>() == "fih"); //Hearing impaired } if (subtitle == null) { subtitle = hdsStream["subtitles"].FirstOrDefault(s => s["lang"].Value <string>() == ApiOtherLanguage); } if (subtitle != null && subtitle["uri"] != null) { subtitleUrl = subtitle["uri"].Value <string>(); } } if (!string.IsNullOrEmpty(subtitleUrl)) { video.SubtitleText = GetWebData(subtitleUrl, encoding: Encoding.UTF8, forceUTF8: true); } string data = hdsStream["url"].Value <string>(); string result = DecryptData(data); Regex r; bool useHls = !result.Contains(".f4m") && !result.Contains("*~hmac"); if (useHls) { url = string.Format("http://player.yle.fi/api/v1/media.jsonp?protocol=HLS&client=areena-flash-player&id={0}", video.VideoUrl); json = GetWebData <JObject>(url, cache: false); data = json["data"]["media"]["HLS"].First["url"].Value <string>(); result = DecryptData(data); r = new Regex(@"(?<url>.*\.m3u8)"); Match m = r.Match(result); if (m.Success) { result = m.Groups["url"].Value; video.PlaybackOptions = HlsPlaylistParser.GetPlaybackOptions(GetWebData(result), result); result = video.PlaybackOptions.Last().Value; } } else { r = new Regex(@"(?<url>.*hmac=[a-z0-9]*)"); Match m = r.Match(result); if (m.Success) { result = m.Groups["url"].Value + "&g=" + HelperUtils.GetRandomChars(12) + "&hdcore=3.8.0&plugin=flowplayer-3.8.0.0"; } } return(result); }