Beispiel #1
0
        private string GetUrlFromHosters(string url, VideoInfo video)
        {
            Uri uri = new Uri(url);

            foreach (HosterBase hosterUtil in HosterFactory.GetAllHosters())
            {
                if (uri.Host.ToLower().Contains(hosterUtil.GetHosterUrl().ToLower()))
                {
                    Dictionary <string, string> options = hosterUtil.GetPlaybackOptions(url);
                    if (options != null && options.Count > 0)
                    {
                        if (options.Count > 1)
                        {
                            video.PlaybackOptions = options;
                        }
                        return(options.Last().Value);
                    }
                    else
                    {
                        return(String.Empty);
                    }
                }
            }
            return(String.Empty);
        }
        public override string GetVideoUrl(VideoInfo video)
        {
            string data = GetWebData(video.VideoUrl);
            JToken jt   = JObject.Parse(data) as JToken;
            JToken vids = jt["video"]["mp4"];

            if (vids != null)
            {
                video.PlaybackOptions = new System.Collections.Generic.Dictionary <string, string>();
                video.PlaybackOptions.Add("low", vids.Value <string>("low_quality"));
                string h = vids.Value <string>("high_quality");
                if (!String.IsNullOrEmpty(h))
                {
                    video.PlaybackOptions.Add("high", h);
                }
                return(video.PlaybackOptions.Last().Value);
            }
            //probably youtube
            JToken vid = jt["video"]["youtubeId"];

            foreach (HosterBase hosterUtil in HosterFactory.GetAllHosters())
            {
                if (hosterUtil.Matches("youtube.com"))
                {
                    video.PlaybackOptions = hosterUtil.GetPlaybackOptions(@"http://youtube.com/" + vid.Value <string>());
                }
            }
            return(video.PlaybackOptions.Last().Value);
        }
Beispiel #3
0
        public override string GetVideoUrl(VideoInfo video)
        {
            HosterBase svtPlay = HosterFactory.GetHoster("SVTPlay");
            string     url     = svtPlay.GetVideoUrl(video.VideoUrl);

            if (svtPlay is ISubtitle)
            {
                video.SubtitleText = (svtPlay as ISubtitle).SubtitleText;
            }
            return(url);
        }
Beispiel #4
0
        public override string GetPlaylistItemVideoUrl(VideoInfo clonedVideoInfo, string chosenPlaybackOption, bool inPlaylist = false)
        {
            Uri uri = new Uri(clonedVideoInfo.VideoUrl);

            //chosenPlaybackOption = "";
            clonedVideoInfo.PlaybackOptions = new Dictionary <string, string>();
            foreach (HosterBase hosterUtil in HosterFactory.GetAllHosters())
            {
                if (uri.Host.ToLower().Contains(hosterUtil.GetHosterUrl().ToLower()))
                {
                    Dictionary <string, string> options = hosterUtil.GetPlaybackOptions(clonedVideoInfo.VideoUrl);
                    if (options != null && options.Count > 0)
                    {
                        if (!string.IsNullOrEmpty(chosenPlaybackOption) && options.Keys.Contains(chosenPlaybackOption))
                        {
                            return(options[chosenPlaybackOption]);
                        }
                        else
                        {
                            string        chosenoption = options.Last().Key;
                            List <string> availoptions = options.Keys.ToList();
                            for (int i = availoptions.Count - 1; i >= 0; i--)
                            {
                                if (useMP4Playback && availoptions[i].IndexOf("mp4", StringComparison.InvariantCultureIgnoreCase) > -1)
                                {
                                    chosenoption = availoptions[i];
                                    break;
                                }
                                else if (!useMP4Playback && availoptions[i].IndexOf("flv", StringComparison.InvariantCultureIgnoreCase) > -1)
                                {
                                    chosenoption = availoptions[i];
                                    break;
                                }
                            }

                            if (autoChoose)
                            {
                                return(options[chosenoption]);
                            }

                            clonedVideoInfo.PlaybackOptions = options;
                            return(options[chosenoption]);
                        }
                    }
                }
            }

            return(clonedVideoInfo.VideoUrl);
        }
        public override string GetVideoUrl(VideoInfo video)
        {
            video.PlaybackOptions = new Dictionary <string, string>();
            string data             = GetWebData(video.VideoUrl);
            var    talkDetailsMatch = regEx_FileUrl.Match(data);

            if (talkDetailsMatch.Success)
            {
                JObject talkDetails = JsonConvert.DeserializeObject(talkDetailsMatch.Groups["json"].Value) as JObject;
                foreach (JProperty htmlStream in talkDetails["__INITIAL_DATA__"]["talks"][0]["downloads"]["nativeDownloads"])
                {
                    HttpUrl httpUrl = new HttpUrl(htmlStream.Value.ToString())
                    {
                        UserAgent = OnlineVideoSettings.Instance.UserAgent
                    };
                    video.PlaybackOptions.Add(htmlStream.Name, httpUrl.ToString());
                }
                if (video.PlaybackOptions.Count == 0)
                {
                    string url = talkDetails["__INITIAL_DATA__"]["talks"][0]["player_talks"][0]["resources"]["hls"]["stream"].ToString();
                    if (string.IsNullOrEmpty(url))
                    {
                        var external = talkDetails["__INITIAL_DATA__"]["talks"][0]["player_talks"][0]["external"];
                        if (external.Value <string>("service") == "YouTube")
                        {
                            HosterBase hoster = HosterFactory.GetHoster(external.Value <string>("service"));
                            video.PlaybackOptions = hoster.GetPlaybackOptions(@"https://www.youtube.com/watch?v=" + external.Value <string>("code"));
                        }
                    }
                    else
                    {
                        var m3u8Data = GetWebData(url);
                        var options  = Helpers.HlsPlaylistParser.GetPlaybackOptions(m3u8Data, url);
                        foreach (var key in options.Keys)
                        {
                            HttpUrl httpUrl = new HttpUrl(options[key])
                            {
                                UserAgent = OnlineVideoSettings.Instance.UserAgent
                            };
                            video.PlaybackOptions.Add(key, httpUrl.ToString());
                        }
                        return(video.GetPreferredUrl(false));
                    }
                }
            }
            return(video.PlaybackOptions.Count > 0 ? video.PlaybackOptions.Last().Value : "");
        }
Beispiel #6
0
        public override List <string> GetMultipleVideoUrls(VideoInfo video, bool inPlaylist = false)
        {
            video.PlaybackOptions = new Dictionary <string, string>();
            string videoUrl = video.VideoUrl;

            if (videoUrl.EndsWith(".m3u8"))
            {
                MyHlsPlaylistParser parser = new MyHlsPlaylistParser(GetWebData(videoUrl), videoUrl);
                foreach (MyHlsStreamInfo streamInfo in parser.StreamInfos)
                {
                    video.PlaybackOptions.Add(string.Format("{0}x{1} ({2}kbps)", streamInfo.Width, streamInfo.Height, streamInfo.Bandwidth), streamInfo.Url);
                }
            }
            else
            {
                HosterBase hoster = HosterFactory.GetAllHosters().FirstOrDefault <HosterBase>((HosterBase h) => videoUrl.ToLower().Contains(h.GetHosterUrl().ToLower()));
                if (hoster != null)
                {
                    video.PlaybackOptions = hoster.GetPlaybackOptions(videoUrl);
                    if (hoster is ISubtitle)
                    {
                        video.SubtitleText = (hoster as ISubtitle).SubtitleText;
                    }
                }
            }
            if (video.PlaybackOptions.Count == 0)
            {
                return(new List <string>());
            }
            if (video.HasDetails && (video as DetailVideoInfo).Title2 == "Live")
            {
                video.PlaybackOptions = video.PlaybackOptions.ToDictionary(p => p.Key, p => p.Value.Replace("start=", "dummy="));
            }
            string url = video.PlaybackOptions.First <KeyValuePair <string, string> >().Value;

            if (inPlaylist)
            {
                video.PlaybackOptions.Clear();
            }
            return(new List <string>()
            {
                url
            });
        }
        internal static Dictionary <string, string> GetPlaybackOptionsFromYoutubeUrl(string source)
        {
            var playbackOptions = new Dictionary <string, string>();

            if (string.IsNullOrEmpty(source))
            {
                return(playbackOptions);
            }

            string url = WebUtils.GetYouTubeURL(source);

            FileLog.Debug("Getting download and playback options, URL = '{0}'", url);

            try
            {
                var hosterBase = HosterFactory.GetHoster("Youtube");
                playbackOptions = hosterBase.GetPlaybackOptions(url);

                if (playbackOptions == null)
                {
                    return(null);
                }
            }
            catch (Exception e)
            {
                FileLog.Error("Error getting playback options, Reason = '{0}'", e.Message);
                return(null);
            }

            if (playbackOptions.Count == 0)
            {
                return(null);
            }

            foreach (var option in playbackOptions)
            {
                FileLog.Debug("Found download option, Source URL = '{0}', Quality = '{1}'", option.Value, option.Key);
            }

            return(playbackOptions);
        }
Beispiel #8
0
            public static string getPlaybackUrl(string playerUrl, iStreamUtil Util)
            {
                string data = WebCache.Instance.GetWebData(playerUrl, cookies: Util.GetCookie(), forceUTF8: Util.forceUTF8Encoding, allowUnsafeHeader: Util.allowUnsafeHeaders, encoding: Util.encodingOverride);
                Match  n    = Regex.Match(data, @"URL=(?<url>[^""]*)");

                if (n.Groups[1].Value == "http://istream.ws" || n.Groups[1].Value == "")
                {
                    HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(playerUrl);
                    string         e         = myRequest.Address.Query.Substring(3);

                    string encodeQuery  = System.Uri.EscapeDataString(e);
                    string newplayerurl = "http://istream.ws" + myRequest.Address.LocalPath + "?m=" + encodeQuery;
                    string data2        = WebCache.Instance.GetWebData(newplayerurl, cookies: Util.GetCookie(), forceUTF8: Util.forceUTF8Encoding, allowUnsafeHeader: Util.allowUnsafeHeaders, encoding: Util.encodingOverride);

                    Match m = Regex.Match(data2, @"URL=(?<url>[^""]*)");
                    playerUrl = m.Groups[1].Value;
                }
                else
                {
                    playerUrl = n.Groups[1].Value;
                }

                WebRequest  request  = WebRequest.Create(playerUrl);
                WebResponse response = request.GetResponse();
                string      url      = response.ResponseUri.ToString();
                Uri         uri      = new Uri(url);

                foreach (HosterBase hosterUtil in HosterFactory.GetAllHosters())
                {
                    if (uri.Host.ToLower().Contains(hosterUtil.GetHosterUrl().ToLower()))
                    {
                        Dictionary <string, string> options = hosterUtil.GetPlaybackOptions(url);
                        if (options != null && options.Count > 0)
                        {
                            url = options.Last().Value;
                        }
                        break;
                    }
                }
                return(url);
            }
            public static string getPlaybackUrl(string playerUrl, Movie2KSerienUtil Util)
            {
                string data = WebCache.Instance.GetWebData(playerUrl, cookies: Util.GetCookie(), forceUTF8: Util.forceUTF8Encoding, allowUnsafeHeader: Util.allowUnsafeHeaders, encoding: Util.encodingOverride);
                Match  m    = Regex.Match(data, Util.hosterUrlRegEx);
                string url  = m.Groups["url"].Value;
                Uri    uri  = new Uri(url);

                foreach (HosterBase hosterUtil in HosterFactory.GetAllHosters())
                {
                    if (uri.Host.ToLower().Contains(hosterUtil.GetHosterUrl().ToLower()))
                    {
                        Dictionary <string, string> options = hosterUtil.GetPlaybackOptions(url);
                        if (options != null && options.Count > 0)
                        {
                            url = options.Last().Value;
                        }
                        break;
                    }
                }
                return(url);
            }
Beispiel #10
0
        public override List <string> GetMultipleVideoUrls(VideoInfo video, bool inPlaylist = false)
        {
            video.PlaybackOptions = new Dictionary <string, string>();
            string videoUrl = video.VideoUrl;

            if (videoUrl.EndsWith(".m3u8"))
            {
                video.PlaybackOptions = HlsPlaylistParser.GetPlaybackOptions(GetWebData(videoUrl), videoUrl, (x, y) => y.Bandwidth.CompareTo(x.Bandwidth), (x) => x.Width + "x" + x.Height + " (" + x.Bandwidth / 1000 + " Kbps)");
            }
            else
            {
                HosterBase hoster = HosterFactory.GetAllHosters().FirstOrDefault <HosterBase>((HosterBase h) => videoUrl.ToLower().Contains(h.GetHosterUrl().ToLower()));
                if (hoster != null)
                {
                    video.PlaybackOptions = hoster.GetPlaybackOptions(videoUrl);
                    if (hoster is ISubtitle)
                    {
                        video.SubtitleText = (hoster as ISubtitle).SubtitleText;
                    }
                }
            }
            if (video.PlaybackOptions.Count == 0)
            {
                return(new List <string>());
            }
            if (video.HasDetails && (video as DetailVideoInfo).Title2 == "Live")
            {
                video.PlaybackOptions = video.PlaybackOptions.ToDictionary(p => p.Key, p => p.Value.Replace("start=", "dummy="));
            }
            string url = video.PlaybackOptions.First <KeyValuePair <string, string> >().Value;

            if (inPlaylist)
            {
                video.PlaybackOptions.Clear();
            }
            return(new List <string>()
            {
                url
            });
        }
            public static string getPlaybackUrl(string playerUrl, MyTainmentUtil Util)
            {
                string      data     = WebCache.Instance.GetWebData(playerUrl, cookies: Util.GetCookie(), forceUTF8: Util.forceUTF8Encoding, allowUnsafeHeader: Util.allowUnsafeHeaders, encoding: Util.encodingOverride);
                WebRequest  request  = WebRequest.Create(playerUrl);
                WebResponse response = request.GetResponse();
                string      url      = response.ResponseUri.ToString();
                Uri         uri      = new Uri(url);

                foreach (HosterBase hosterUtil in HosterFactory.GetAllHosters())
                {
                    if (uri.Host.ToLower().Contains(hosterUtil.GetHosterUrl().ToLower()))
                    {
                        Dictionary <string, string> options = hosterUtil.GetPlaybackOptions(url);
                        if (options != null && options.Count > 0)
                        {
                            url = options.Last().Value;
                        }
                        break;
                    }
                }
                return(url);
            }
        private static int PlaybackComparer(PlaybackElement e1, PlaybackElement e2)
        {
            HosterBase h1 = HosterFactory.GetHoster(e1.server);
            HosterBase h2 = HosterFactory.GetHoster(e2.server);

            //first stage is to compare priorities (the higher the user priority, the better)
            int res = (h1 != null && h2 != null) ? IntComparer(h1.UserPriority, h2.UserPriority) : 0;

            if (res != 0)
            {
                return(res);
            }
            else
            {
                //no priorities found or equal priorites -> see if status is different
                res = String.Compare(e1.status, e2.status);

                if (res != 0)
                {
                    return(res);
                }
                else
                {
                    //equal status -> compare percentage
                    res = IntComparer(e1.percentage, e2.percentage);
                    if (res != 0)
                    {
                        return(res);
                    }
                    else
                    {
                        //everything else is same -> compare alphabetically
                        return(String.Compare(e1.server, e2.server));
                    }
                }
            }
        }
Beispiel #13
0
 public string GetVideoUrls(string url)
 {
     return(HosterFactory.GetHoster("Youtube").getVideoUrls(url));
 }
        public static Dictionary <string, string> GetYouTubePlaybackOptions(EpisodeInfo info)
        {
            if (!HosterFactory.ContainsName("youtube"))
            {
                Log.Warn("youtube hoster was not found");
                return(null);
            }

            if (info == null ||
                string.IsNullOrEmpty(info.SeriesTitle) ||
                string.IsNullOrEmpty(info.SeriesNumber) ||
                (string.IsNullOrEmpty(info.EpisodeNumber) && string.IsNullOrEmpty(info.AirDate))
                )
            {
                Log.Warn("Not enough info to locate video");
                return(null);
            }

            string youtubeTitle = Regex.Replace(info.SeriesTitle, "[^A-z0-9]", "").ToLower();

            Log.Debug("Searching for youtube video: Show: {0}, Season: {1}, {2}", youtubeTitle, info.SeriesNumber, string.IsNullOrEmpty(info.AirDate) ? "Episode: " + info.EpisodeNumber : "Air Date: " + info.AirDate);

            string html = WebCache.Instance.GetWebData("http://www.youtube.com/show/" + youtubeTitle);

            //look for season
            string seriesReg = string.Format(@"<a class=""yt-uix-tile-link"" href=""([^""]*)"">[\s\n]*Season {0} Episodes", info.SeriesNumber);
            Match  m         = Regex.Match(html, seriesReg);

            if (m.Success)
            {
                //found specified season
                string playlist = WebCache.Instance.GetWebData("http://www.youtube.com" + m.Groups[1].Value);
                string episodeReg;

                //look for specified episode
                if (string.IsNullOrEmpty(info.EpisodeNumber))
                {
                    episodeReg = string.Format(@"<a href=""(/watch[^""]*)"".*?>[\s\n]*<span.*?>.*?{0}", info.AirDate);
                    m          = Regex.Match(playlist, episodeReg);
                    if (m.Success)
                    {
                        return(HosterFactory.GetHoster("youtube").GetPlaybackOptions("http://youtube.com" + m.Groups[1].Value));
                    }
                    return(null);
                }

                episodeReg = string.Format(@"<span class=""video-index"">{0}</span>.*?<a href=""(/watch[^""]*)""", info.EpisodeNumber);
                m          = Regex.Match(playlist, episodeReg, RegexOptions.Singleline);
                if (m.Success)
                {
                    if (verifyYoutubePage(m.Groups[1].Value, info.SeriesNumber, info.EpisodeNumber))
                    {
                        return(HosterFactory.GetHoster("youtube").GetPlaybackOptions("http://youtube.com" + m.Groups[1].Value));
                    }
                    return(null);
                }
                //didn't find specified episode directly, loop through all videos and see if we get a match
                foreach (Match ep in Regex.Matches(playlist, @"<a href=""(/watch[^""]*)"""))
                {
                    if (verifyYoutubePage(ep.Groups[1].Value, info.SeriesNumber, info.EpisodeNumber))
                    {
                        return(HosterFactory.GetHoster("youtube").GetPlaybackOptions("http://youtube.com" + ep.Groups[1].Value));
                    }
                }
            }
            Log.Warn("Unable to locate 4od video on youtube");
            return(null);
        }
        /// <summary>
        /// Sorts and filters all video links (hosters) for a given video
        /// </summary>
        /// <param name="video">The video that is handled</param>
        /// <param name="baseUrl">The base url of the video</param>
        /// <param name="tmp"></param>
        /// <param name="limit">How many playback options are at most shown per hoster (0=all)</param>
        /// <param name="showUnknown">Also show playback options where no hoster is available yet</param>
        /// <returns></returns>
        public string SortPlaybackOptions(VideoInfo video, string baseUrl, string tmp, int limit, bool showUnknown)
        {
            List <PlaybackElement> lst = new List <PlaybackElement>();

            if (video.PlaybackOptions == null) // just one
            {
                lst.Add(new PlaybackElement("100%justone", FormatHosterUrl(tmp)));
            }
            else
            {
                foreach (string name in video.PlaybackOptions.Keys)
                {
                    PlaybackElement element = new PlaybackElement(FormatHosterName(name), FormatHosterUrl(video.PlaybackOptions[name]));
                    element.status = "ns";
                    if (element.server.Equals("videoclipuri") ||
                        HosterFactory.ContainsName(element.server.ToLower().Replace("google", "googlevideo")))
                    {
                        element.status = String.Empty;
                    }
                    lst.Add(element);
                }
            }

            Dictionary <string, int> counts = new Dictionary <string, int>();

            foreach (PlaybackElement el in lst)
            {
                if (counts.ContainsKey(el.server))
                {
                    counts[el.server]++;
                }
                else
                {
                    counts.Add(el.server, 1);
                }
            }
            Dictionary <string, int> counts2 = new Dictionary <string, int>();

            foreach (string name in counts.Keys)
            {
                if (counts[name] != 1)
                {
                    counts2.Add(name, counts[name]);
                }
            }

            lst.Sort(PlaybackComparer);

            for (int i = lst.Count - 1; i >= 0; i--)
            {
                if (counts2.ContainsKey(lst[i].server))
                {
                    lst[i].dupcnt = counts2[lst[i].server];
                    counts2[lst[i].server]--;
                }
            }

            video.PlaybackOptions = new Dictionary <string, string>();
            bool lastPlaybackOptionUrlPresent = false;

            foreach (PlaybackElement el in lst)
            {
                if (!Uri.IsWellFormedUriString(el.url, System.UriKind.Absolute))
                {
                    el.url = new Uri(new Uri(baseUrl), el.url).AbsoluteUri;
                }

                if ((limit == 0 || el.dupcnt <= limit) && (showUnknown || el.status == null || !el.status.Equals("ns")))
                {
                    video.PlaybackOptions.Add(el.GetName(), el.url);
                    lastPlaybackOptionUrlPresent |= (el.url == lastPlaybackOptionUrl);
                }
            }

            if (lst.Count == 1)
            {
                video.VideoUrl        = video.GetPlaybackOptionUrl(lst[0].GetName());
                video.PlaybackOptions = null;
                return(video.VideoUrl);
            }

            if (lastPlaybackOptionUrlPresent)
            {
                return(lastPlaybackOptionUrl);
            }

            if (lst.Count > 0)
            {
                tmp = lst[0].url;
            }

            return(tmp);
        }
Beispiel #16
0
        public override List <String> GetMultipleVideoUrls(VideoInfo video, bool inPlaylist = false)
        {
            List <String> urls      = new List <String>();
            string        resultUrl = GetVideoUrl(video);

            if (video.PlaybackOptions != null && video.PlaybackOptions.Count > 0)
            {
                List <string> valueList = video.PlaybackOptions.Values.ToList();
                video.PlaybackOptions.Clear();
                foreach (string value in valueList)
                {
                    urls.Add(value);
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(resultUrl))
                {
                    urls.Add(resultUrl);

                    Uri uri = new Uri(resultUrl);
                    foreach (HosterBase hosterUtil in HosterFactory.GetAllHosters())
                    {
                        if (uri.Host.ToLower().Contains(hosterUtil.GetHosterUrl().ToLower()))
                        {
                            Dictionary <string, string> options = hosterUtil.GetPlaybackOptions(resultUrl);
                            if (options != null && options.Count > 0)
                            {
                                string        chosenoption = options.Last().Key;
                                List <string> availoptions = options.Keys.ToList();
                                for (int i = availoptions.Count - 1; i >= 0; i--)
                                {
                                    if (useMP4Playback && availoptions[i].IndexOf("mp4", StringComparison.InvariantCultureIgnoreCase) > -1)
                                    {
                                        chosenoption = availoptions[i];
                                        break;
                                    }
                                    else if (!useMP4Playback && availoptions[i].IndexOf("flv", StringComparison.InvariantCultureIgnoreCase) > -1)
                                    {
                                        chosenoption = availoptions[i];
                                        break;
                                    }
                                }

                                if (autoChoose)
                                {
                                    urls.Clear();
                                    urls.Add(options[chosenoption]);
                                    break;
                                }
                                else
                                {
                                    urls.Clear();
                                    video.PlaybackOptions = options;
                                    urls.Add(options[chosenoption]);
                                    break;
                                }
                            }
                        }
                    }
                }
            }

            return(urls);
        }
Beispiel #17
0
 public HosterFactoryTests()
 {
     sut = new HosterFactory(new Container());
     sut.Register(typeof(FakeHoster));
 }