Beispiel #1
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);
        }
        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 : "");
        }
        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);
        }
        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 #5
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);
        }