Ejemplo n.º 1
0
        /// <summary>
        /// タイムフリー
        /// </summary>
        /// <param name="program"></param>
        /// <returns></returns>
        public async Task TimeFree(Entities.Program program)
        {
            try
            {
                Status    = RecorderStatus.Working;
                _duration = (int)(program.End - program.Start).TotalSeconds;
                await Radiko.Login(Config.RadikoEmail, Config.RadikoPassword);


                _program = program;
                Directory.CreateDirectory(Path.Combine("wwwroot", "records"));
                _filename = Path.GetFullPath(Path.Combine("wwwroot", "records", $"{Guid.NewGuid().ToString()}.m4a"));
                StartTime = DateTime.Now;
                var m3U8 = await Radiko.GetTimeFreeM3U8(program);

                var arg = Define.Radiko.TimeFreeFfmpegArgs.Replace("[M3U8]", m3U8).Replace("[FILE]", _filename);
                arg = Replace(arg, _program);
                CreateProcess(arg);


                _ffmpeg.Start();

                _ffmpeg.BeginOutputReadLine();
                _ffmpeg.BeginErrorReadLine();
            }
            catch (Exception ex)
            {
                Global.Logger.Error($"{ex.Message}¥n{ex.StackTrace}");
            }
        }
Ejemplo n.º 2
0
        public async Task <ApiResponse> Post(string type)
        {
            return(await Execute(() =>
            {
                using (SqliteConnection)
                {
                    var stations = new List <Station>();
                    switch (type)
                    {
                    case Define.Radiko.TypeName:
                        var cMolde = new ConfigModel(SqliteConnection);
                        var config = cMolde.Get();
                        var login = !string.IsNullOrWhiteSpace(config?.RadikoEmail) &&
                                    !string.IsNullOrEmpty(config.RadikoPassword) &&
                                    Radiko.Login(config.RadikoEmail, config.RadikoPassword).Result;
                        stations = Radiko.GetStations(login).Result;
                        break;

                    case Define.Nhk.TypeName:
                        stations = Nhk.GetStations().Result;
                        break;
                    }

                    var model = new StationModel(SqliteConnection);
                    model.Refresh(stations);

                    Result.Data = stations;
                    Result.Result = true;
                }
            }));
        }
Ejemplo n.º 3
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;
            }
        }