Beispiel #1
0
        public override async Task <string> Handle(HttpRequest request, HttpResponse response)
        {
            string rootDirectory = string.Empty;

            if (request.Query.ContainsKey(string.Empty))
            {
                rootDirectory = request.Query[string.Empty].FirstOrDefault(s => s.EndsWith(".xml"));
            }

            if (ProgramSettings.Settings.Dlna && !string.IsNullOrEmpty(rootDirectory))
            {
                rootDirectory =
                    new Uri(rootDirectory.Remove(rootDirectory.IndexOf(".xml", StringComparison.Ordinal))).LocalPath;

                var directoriesInfo = FileManager.GetDirectories(rootDirectory);

                var result = new List <Item>();

                await Task.Run((() => {
                    foreach (var directory in directoriesInfo.Where(d => Tools.Tools.CheckAccessPath(d.Key)))
                    {
                        result.Add(CreateDirectoryItem(request, directory.Key, directory.Value));

                        Log.LogDebug("Directory: {0}", directory);
                    }

                    var filesInfo = FileManager.GetFiles(rootDirectory);

                    foreach (var file in filesInfo.Where(f => Tools.Tools.CheckAccessPath(f.Key)))
                    {
                        bool torrent = Path.GetExtension(file.Key) == ".torrent";
                        result.Add(
                            new Item {
                            //Name = $"{file.Value} ({Tools.Tools.FSize(file.Length)})",
                            Name = $"{file.Value} ({Tools.Tools.FSize(new FileInfo(file.Key).Length)})",
                            Link = CreateUrl(request, torrent
                                        ? DlnaTorrentRequestHandler.URL_PATH
                                        : DlnaFileRequestHandler.URL_PATH,
                                             new NameValueCollection()
                            {
                                { string.Empty, HttpUtility.UrlEncode(file.Key) }
                            }),
                            Type = torrent ? ItemType.DIRECTORY : ItemType.FILE
                        }
                            );

                        Log.LogDebug("File: {0}", file);
                    }
                }));

                return(ResponseSerializer.ToXml(result));
            }
            else
            {
                Log.LogDebug("Directory Not Found: {0}", rootDirectory);
                response.StatusCode = (int)HttpStatusCode.NotFound;
                return($"Directory Not Found: {rootDirectory}");
            }
        }
Beispiel #2
0
        public override string Handle(HttpRequest request, HttpResponse response)
        {
            string rootDirectory = string.Empty;

            if (request.Query.ContainsKey(string.Empty))
            {
                rootDirectory = request.Query[string.Empty].FirstOrDefault(s => s.EndsWith(".xml"));
            }

            if (!string.IsNullOrEmpty(rootDirectory))
            {
                rootDirectory =
                    new Uri(rootDirectory.Remove(rootDirectory.IndexOf(".xml"))).LocalPath;

                var directoriesInfo = FileManager.GetDirectories(rootDirectory);

                var result = new List <Item>();

                foreach (var directory in directoriesInfo.Where(d => Tools.Tools.CheckAccessPath(d.Key)))
                {
                    result.Add(CreateDirectoryItem(request, directory.Key, directory.Value));

                    Log.LogDebug("Directory: {0}", directory);
                }

                var filesInfo = FileManager.GetFiles(rootDirectory);

                foreach (var file in filesInfo.Where(f => Tools.Tools.CheckAccessPath(f.Key)))
                {
                    result.Add(
                        new Item {
                        //Name = $"{file.Value} ({Tools.Tools.FSize(file.Length)})",
                        Name = $"{file.Value}",
                        Link = CreateUrl(request, DlnaFileRequestHandler.URL_PATH,
                                         new NameValueCollection()
                        {
                            { string.Empty, HttpUtility.UrlEncode(file.Key) }
                        }),
                        Type = ItemType.FILE
                    }
                        );

                    Log.LogDebug("File: {0}", file);
                }

                return(ResponseSerializer.ToXml(result.ToArray()));
            }
            else
            {
                Log.LogDebug("Directory Not Found: {0}", rootDirectory);
                response.StatusCode = (int)HttpStatusCode.NotFound;
                return($"Directory Not Found: {rootDirectory}");
            }
        }
Beispiel #3
0
        public override async Task <string> Handle(HttpRequest request, HttpResponse response)
        {
            Log.LogDebug("HandleStream get file");

            string file = string.Empty;

            if (request.Query.ContainsKey(string.Empty))
            {
                file = request.Query[string.Empty][0];
                file = HttpUtility.UrlDecode(file);
            }

            if (ProgramSettings.Settings.Dlna && !string.IsNullOrEmpty(file))
            {
                try {
                    var fileRequest = await FileRequest.Create(request, file);

                    if (fileRequest.File.Exists && Tools.Tools.CheckAccessPath(fileRequest.File.FullName))
                    {
                        var data = await File.ReadAllBytesAsync(fileRequest.File.FullName);

                        string source = string.Empty;
                        var    items  = GetItems(data, ref source);

                        if (!string.IsNullOrEmpty(source))
                        {
                            return(source);
                        }
                        else
                        {
                            return(ResponseSerializer.ToM3U(items.ToArray()));
                        }
                    }
                    else
                    {
                        Log.LogDebug("File not found: {0}", file);
                        response.StatusCode = (int)HttpStatusCode.NotFound;
                    }
                } catch (Exception exception) {
                    Log.LogError(exception);
                    response.StatusCode = (int)HttpStatusCode.NotFound;
                }
            }
            else
            {
                Log.LogDebug("Incorrect parameter: {0}", file);

                response.StatusCode = (int)HttpStatusCode.NoContent;
            }

            return(null);
        }
        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}");
        }
        public override string Handle(HttpRequest request, HttpResponse response)
        {
            var result = new List <Item>();

            if ((ProgramSettings.Settings.UserUrls != null) && (ProgramSettings.Settings.UserUrls.Length > 0))
            {
                result.AddRange(from string url in ProgramSettings.Settings.UserUrls
                                select new Item {
                    Name = url.Split('\\').Last().Split('/').Last(),
                    Link = url,
                    Type = ItemType.FILE
                });
            }

            response.ContentType = MimeTypes.Get(PARAM_URLS.Substring(PARAM_URLS.IndexOf('.')));

            return(ResponseSerializer.ToM3U(result.ToArray()));
        }
Beispiel #6
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));
        }
Beispiel #7
0
        public override 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.Name);

                    try {
                        var query          = request.Query.ConvertToNameValue();
                        var context        = new PluginContext(pluginKey, request, query);
                        var pluginResponse = plugin.Instance.GetList(context);

                        if (pluginResponse != null)
                        {
                            if (pluginResponse.source != null)
                            {
                                Log.LogDebug(
                                    "Plugin Playlist.source not null! Write to response Playlist.source and ignore other methods. Plugin: {0}",
                                    pluginKey);
                                return(pluginResponse.source);
                            }
                            else
                            {
                                return(ResponseSerializer.ToXml(pluginResponse));
                            }
                        }
                    } catch (Exception exception) {
                        Log.LogError(exception, exception.Message);
                        response.StatusCode = (int)HttpStatusCode.BadRequest;
                        return($"Plugin: {pluginKey}");
                    }
                }
            }
            response.StatusCode = (int)HttpStatusCode.NotFound;
            return($"Plugin is not defined in request. Plugin: {pluginKey}");
        }
Beispiel #8
0
        public override string Handle(HttpRequest request, HttpResponse response)
        {
            var result = new List <Item>();

            if (ProgramSettings.Settings.Dlna)
            {
                if (ProgramSettings.Settings.DlnaFilterType == FilterMode.INCLUSION)
                {
                    if (ProgramSettings.Settings.DlnaDirectories != null)
                    {
                        foreach (string directory in ProgramSettings.Settings.DlnaDirectories)
                        {
                            Console.WriteLine(directory);
                            if (FileManager.DirectoryExists(directory))
                            {
                                Console.WriteLine(true);
                                result.Add(DlnaDirectoryRequestHandler.CreateDirectoryItem(request, directory));

                                Log.LogDebug($"Filtering directory: {directory}");
                            }
                        }
                    }
                }
                else
                {
                    var drives = FileManager.GetDrives();

                    foreach (var drive in drives.Where(i => Tools.Tools.CheckAccessPath(i.Name)))
                    {
                        if (drive.IsReady)
                        {
                            string mainText =
                                $"{drive.Name} ({Tools.Tools.FSize(drive.AvailableFreeSpace)} свободно из {Tools.Tools.FSize(drive.TotalSize)})";
                            string subText = $"<br>Метка диска: {drive.VolumeLabel}<br>Тип носителя: {drive.DriveType}";

                            result.Add(new Item {
                                Name = mainText + subText,
                                Link = DlnaDirectoryRequestHandler.CreateDriveItem(request, drive.Name),
                                Type = ItemType.DIRECTORY
                            });

                            Log.LogDebug($"Drive: {mainText}{subText}");
                        }
                    }
                }
            }


            if ((ProgramSettings.Settings.UserUrls != null) && (ProgramSettings.Settings.UserUrls.Length > 0))
            {
                result.Add(
                    new Item {
                    Name = "Пользовательские ссылки",
                    Link = CreateUrl(request, UserUrlsRequestHandler.URL_PATH,
                                     new NameValueCollection()
                    {
                        { string.Empty, UserUrlsRequestHandler.PARAM_URLS }
                    }),
                    Type = ItemType.DIRECTORY
                }
                    );

                Log.LogDebug("User urls: {0}", ProgramSettings.Settings.UserUrls.Length);
            }

            foreach (var plugin in PluginManager.Instance.GetPlugins())
            {
                result.Add(
                    new Item {
                    Name      = plugin.Value.Name,
                    Link      = PluginRequestHandler.CreatePluginUrl(request, plugin.Key),
                    ImageLink = plugin.Value.ImageLink,
                    Type      = ItemType.DIRECTORY
                }
                    );

                Log.LogDebug("Plugin: {0}", plugin.Value.Name);
            }

            return(ResponseSerializer.ToM3U(result.ToArray()));
        }