Beispiel #1
0
        protected override async Task <int> OnExecute(CommandLineApplication app)
        {
            try
            {
                _console.WriteLine("Killing any existing server process...");
                WebServerUtils.KillServerProcess();

                if (string.IsNullOrWhiteSpace(FFmpegPath))
                {
                    _console.WriteLine($"Using the default path for ffmpeg = {_appSettings.FFmpegPath}...");
                    FFmpegPath = _appSettings.FFmpegPath;
                }

                if (string.IsNullOrWhiteSpace(FFprobePath))
                {
                    _console.WriteLine($"Using the default path for ffprobe = {_appSettings.FFprobePath}...");
                    FFprobePath = _appSettings.FFprobePath;
                }

                if (!_fileService.IsLocalFile(FFmpegPath))
                {
                    _console.WriteLine($"FFmpegPath = {FFmpegPath} is not valid ");
                    return(-1);
                }

                if (!_fileService.IsLocalFile(FFprobePath))
                {
                    _console.WriteLine($"FFprobePath = {FFprobePath} is not valid ");
                    return(-1);
                }

                var url = ServerUtils.StartServerIfNotStarted(_console, FFmpegPath, FFprobePath);
                _console.WriteLine(string.IsNullOrWhiteSpace(url)
                    ? "Server couldn't be started"
                    : "Server was started");
            }
            catch (Exception e)
            {
                _console.WriteLine(e.ToString());
            }

            return(await base.OnExecute(app));
        }
Beispiel #2
0
        protected override async Task <int> OnExecute(CommandLineApplication app)
        {
            try
            {
                if (!WebServerUtils.IsServerAlive())
                {
                    _console.WriteLine("Server is not running");
                    return(-1);
                }

                var url = ServerUtils.StartServerIfNotStarted(_console);
                if (string.IsNullOrWhiteSpace(url))
                {
                    return(-1);
                }

                bool isLocal = _fileService.IsLocalFile(Mrl);
                if (!_fileService.Exists(Mrl))
                {
                    _console.WriteLine($"File = {Mrl} does not exist");
                    return(-1);
                }

                _console.WriteLine($"Trying to play file = {Mrl}...");
                var request = isLocal
                    ? PlayCliFileRequestDto.FromLocal(Mrl, VideoStreamIndex, AudioStreamIndex, SubsStreamIndex)
                    : PlayCliFileRequestDto.FromYoutube(Mrl, Quality);

                if (Seconds > 0)
                {
                    request.Seconds = Seconds;
                }

                _console.WriteLine(
                    $"The following request will be send to the api = {JsonConvert.SerializeObject(request, Formatting.Indented)}, " +
                    $"the server url is = {url}");
                var castItApi = RestService.For <ICastItApi>(url);
                var response  = await castItApi.Play(request);

                _console.WriteLine(response.Succeed
                    ? $"File = {Mrl} was successfully loaded"
                    : $"File couldn't be loaded. Error = {response.Message}");
            }
            catch (Exception e)
            {
                _console.WriteLine(e.ToString());
                return(-1);
            }
            return(await base.OnExecute(app));
        }