Пример #1
0
        public HosterBase GetHoster(string name)
        {
            HosterBase hb = null;

            if (hostersByName.TryGetValue(name.ToLower(), out hb))
            {
                return(hb);
            }
            return(null);
        }
Пример #2
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);
        }
Пример #3
0
        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 : "");
        }
Пример #4
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
            });
        }
Пример #5
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
            });
        }
        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));
                    }
                }
            }
        }
Пример #7
0
        internal void LoadAllSiteUtilDlls(string path)
        {
            var assemblies = new Dictionary <Assembly, DateTime>();

            assemblies.Add(Assembly.GetExecutingAssembly(), Helpers.FileUtils.RetrieveLinkerTimestamp(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath));
            if (Directory.Exists(path))
            {
                foreach (string dll in Directory.GetFiles(path, "OnlineVideos.Sites.*.dll"))
                {
                    try
                    {
                        assemblies.Add(AppDomain.CurrentDomain.Load(AssemblyName.GetAssemblyName(dll)), Helpers.FileUtils.RetrieveLinkerTimestamp(dll));
                    }
                    catch (Exception dllLoadException)
                    {
                        Log.Warn("Error loading {0}: {1}", dll, dllLoadException.Message);
                    }
                }
            }
            // search all assemblies for exported SiteUtilBase and HosterBase implementing non abstract classes
            foreach (var assembly in assemblies)
            {
                try
                {
                    Log.Info("Looking for SiteUtils and Hosters in {0} (Version: {1}, Compiled: {2})",
                             assembly.Key.GetName().Name,
                             assembly.Key.GetName().Version.ToString(),
                             assembly.Value.ToString("yyyy-MM-dd HH:mm:ss"));

                    Type[] typeArray = assembly.Key.GetExportedTypes();
                    foreach (Type type in typeArray)
                    {
                        if (type.BaseType != null && type.IsSubclassOf(typeof(SiteUtilBase)) && !type.IsAbstract)
                        {
                            string shortName = type.Name;
                            if (shortName.EndsWith("Util"))
                            {
                                shortName = shortName.Substring(0, shortName.Length - 4);
                            }

                            Type alreadyAddedType = null;
                            if (!utils.TryGetValue(shortName, out alreadyAddedType))
                            {
                                utils.Add(shortName, type);
                            }
                            else
                            {
                                // use the type from the assembly with the latest CompileTime
                                if (assemblies[alreadyAddedType.Assembly] < assembly.Value)
                                {
                                    utils[shortName] = type;
                                    Log.Warn(string.Format("Duplicate SiteUtil '{0}'. Using the one from '{1}', because DLL has newer compile time than '{2}'.",
                                                           shortName,
                                                           type.Assembly.GetName().Name.Replace("OnlineVideos.Sites.", ""),
                                                           alreadyAddedType.Assembly.GetName().Name.Replace("OnlineVideos.Sites.", "")));
                                }
                                else
                                {
                                    Log.Warn(string.Format("Duplicate SiteUtil '{0}'. Using the one from '{1}', because DLL has newer compile time than '{2}'.",
                                                           shortName,
                                                           alreadyAddedType.Assembly.GetName().Name.Replace("OnlineVideos.Sites.", ""),
                                                           type.Assembly.GetName().Name.Replace("OnlineVideos.Sites.", "")));
                                }
                            }
                        }
                        else if (type.BaseType != null && type.IsSubclassOf(typeof(HosterBase)) && !type.IsAbstract)
                        {
                            string     shortName          = type.Name.ToLower();
                            HosterBase alreadyAddedHoster = null;
                            if (!hostersByName.TryGetValue(shortName, out alreadyAddedHoster))
                            {
                                HosterBase hb = (HosterBase)Activator.CreateInstance(type);
                                hb.Initialize();
                                hostersByName.Add(shortName, hb);
                                if (!hostersByDNS.ContainsKey(hb.GetHosterUrl().ToLower()))
                                {
                                    hostersByDNS.Add(hb.GetHosterUrl().ToLower(), hb);
                                }
                            }
                            else
                            {
                                // use the type from the assembly with the latest CompileTime
                                if (assemblies[alreadyAddedHoster.GetType().Assembly] < assembly.Value)
                                {
                                    HosterBase hb = (HosterBase)Activator.CreateInstance(type);
                                    hb.Initialize();
                                    hostersByName[shortName] = hb;
                                    Log.Warn(string.Format("Duplicate Hoster '{0}'. Using the one from '{1}', because DLL has newer compile time than '{2}'.",
                                                           shortName,
                                                           type.Assembly.GetName().Name.Replace("OnlineVideos.Sites.", ""),
                                                           alreadyAddedHoster.GetType().Assembly.GetName().Name.Replace("OnlineVideos.Sites.", "")));
                                }
                                else
                                {
                                    Log.Warn(string.Format("Duplicate Hoster '{0}'. Using the one from '{1}', because DLL has newer compile time than '{2}'.",
                                                           shortName,
                                                           alreadyAddedHoster.GetType().Assembly.GetName().Name.Replace("OnlineVideos.Sites.", ""),
                                                           type.Assembly.GetName().Name.Replace("OnlineVideos.Sites.", "")));
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Log.Warn("Error loading SiteUtils and Hosters: {0} ", ex.Message);
                }
            }
            Log.Info("Found {0} SiteUtils and {1} Hosters in {2} assemblies", utils.Count, hostersByName.Count, assemblies.Count);
        }