Exemplo n.º 1
0
        public override async Task <string> Handle(HttpRequest request, HttpResponse response)
        {
            string pluginKey = ParsePluginKey(request);

            if (!string.IsNullOrEmpty(pluginKey))
            {
                var plugin = PluginManager.Instance.GetPlugin(pluginKey);

                if (plugin != null)
                {
                    Log.LogDebug("Execute: {0}", plugin.ToString());

                    try {
                        Playlist pluginResponse = null;

                        await Task.Run((() => {
                            var query = request.Query.ConvertToNameValue();
                            var context = new PluginContext(pluginKey, request, query);
                            pluginResponse = plugin.Instance.GetList(context);
                        }));

                        if (pluginResponse != null)
                        {
                            if (!string.IsNullOrEmpty(pluginResponse.source))
                            {
                                Log.LogDebug(
                                    "Plugin Playlist.source not null! Write to response Playlist.source and ignore other methods. Plugin: {0}",
                                    pluginKey);
                                return(pluginResponse.source);
                                //} else if (!string.IsNullOrEmpty(pluginResponse.IsIptv) && pluginResponse.IsIptv == "True") {
                                //return ResponseSerializer.PlaylistToM3U8(pluginResponse);
                            }
                            else
                            {
                                return(ResponseSerializer.PlaylistToXml(pluginResponse));
                            }
                        }
                    } catch (Exception exception) {
                        Log.LogError(exception);
                        response.StatusCode = (int)HttpStatusCode.BadRequest;
                        return($"Plugin: {pluginKey}");
                    }
                }
            }
            response.StatusCode = (int)HttpStatusCode.NotFound;
            return($"Plugin is not defined in request. Plugin: {pluginKey}");
        }
Exemplo n.º 2
0
        public string GetFileList(Dictionary <string, string> files, string key, string type)
        {
            var items = new List <Item>();

            if (files.Count > 0)
            {
                if (files.Count > 1)
                {
                    string stream = string.Format("{0}/ace/getstream?{1}={2}", AceStreamEngine.GetServer, type, key);
                    return(HTTPUtility.GetRequest(stream));
                }
                else
                {
                    string stream = string.Format("{0}/ace/getstream?{1}={2}", AceStreamEngine.GetServer, type, key);
                    string name   = Path.GetFileName(files.First().Value);
                    var    item   = new Item()
                    {
                        Name      = Path.GetFileName(name),
                        ImageLink = "http://obovse.ru/ForkPlayer2.5/img/file.png",
                        Link      = stream,
                        Type      = ItemType.FILE
                    };
                    items.Add(item);

                    stream = string.Format("{0}/ace/manifest.m3u8?{1}={2}", AceStreamEngine.GetServer, type, key);
                    item   = new Item()
                    {
                        Name      = "(hls) " + Path.GetFileName(name),
                        ImageLink = "http://obovse.ru/ForkPlayer2.5/img/file.png",
                        Link      = stream,
                        Type      = ItemType.FILE
                    };
                    items.Add(item);
                }
            }

            var playlist = new Playlist {
                Items  = items.ToArray(),
                IsIptv = "false"
            };

            return(ResponseSerializer.PlaylistToXml(playlist));
        }