예제 #1
0
        public async Task <ApiResponse> Index([FromBody] ProgramSearchCondition cond)
        {
            return(await Execute(() =>
            {
                using (SqliteConnection)
                {
                    var pModel = new ProgramModel(SqliteConnection);
                    var res = pModel.Search(cond);

                    if (!res.Any() && string.IsNullOrWhiteSpace(cond.Keyword) && cond.Refresh)
                    {
                        RefreshPrograms(cond.StationId);
                        res = pModel.Search(cond);
                    }
                    Result.Data = new { programs = res, range = pModel.GetRange(cond.StationId) };
                    Result.Result = true;
                }
            }));
        }
예제 #2
0
        /// <summary>
        /// 録音開始
        /// </summary>
        /// <returns></returns>
        public async Task Start()
        {
            try
            {
                Status = RecorderStatus.Working;
                using (var con = new SqliteConnection($"Data Source={Define.File.DbFile}"))
                {
                    var pModel = new ProgramModel(con);
                    _program = pModel.Search(new ProgramSearchCondition()
                    {
                        StationId = Task.Station.Id, From = Task.Reserve.Start, To = Task.Reserve.End
                    }).FirstOrDefault();
                    _program.Station = Task.Station;
                }

                if (Task.Reserve.IsTimeFree)
                {
                    // 番組情報取得
                    using (var con = new SqliteConnection($"Data Source={Define.File.DbFile}"))
                    {
                        _ = TimeFree(_program);
                    }
                }
                else
                {
                    await Radiko.Login(Config.RadikoEmail, Config.RadikoPassword);

                    Directory.CreateDirectory(Path.Combine("wwwroot", "records"));
                    _filename = Path.GetFullPath(Path.Combine("wwwroot", "records", $"{Guid.NewGuid().ToString()}.m4a"));
                    StartTime = DateTime.Now;
                    _token    = await Radio.Radiko.GetAuthToken();

                    var arg = Define.Radiko.RealTimeFfmpegArgs.Replace("[TOKEN]", _token)
                              .Replace("[TIME]", (Task.End.AddSeconds(Define.Radiko.EndSec) - DateTime.Now).ToString(@"hh\:mm\:ss"))
                              .Replace("[FILE]", _filename);
                    arg = Replace(arg, _program);
                    CreateProcess(arg);

                    _ffmpeg.Start();
                    _ffmpeg.BeginOutputReadLine();
                    _ffmpeg.BeginErrorReadLine();
                }
            }
            catch (Exception ex)
            {
                var a = ex.Message;
            }
        }