Beispiel #1
0
    // Use this for initialization
    void Start()
    {
        // 1G

        SYSTEM_AUDIO_ANALYZER    = k514AudioAnalyzer.singleton;
        SYSTEM_MATH_MANAGER      = k514MathManager.singleton;
        SYSTEM_SPECTRUM_MANAGER  = k514SpectrumManager.singleton;
        SYSTEM_PATTERN_MANAGER   = k514PatternCatchManager.singleton;
        SYSTEM_YOUTUBE_DATA      = AudioAnalyzePreset.singleton;
        SYSTEM_SOUND_MANAGER     = k514SoundManager.singleton;
        SYSTEM_ENEMY_SPAWNER     = k514EnemySpawner.singleton;
        SYSTEM_PATTERN_GENERATOR = k514PatternGenerator.singleton;

        // 2G

        SYSTEM_YOUTUBE_CONNECTOR = YoutubeSearcher.singleton;
        SYSTEM_YOUTUBE_MANAGER   = k514YoutubeManager.singleton;


        Debug.Log("System Manager loaded");
    }
Beispiel #2
0
        public void YoutubeSearch()
        {
            if (youtubeSearching)
            {
                AddLog("이미 Youtube 서비스에서 검색을 실행중입니다.", TaskLogType.Failed);
                return;
            }

            if (SettingManager.YoutubeSearchOption.UseDateSearch)
            {
                if (!SettingManager.YoutubeSearchOption.DateRange.Vaild)
                {
                    AddLog("유튜브 검색의 날짜 설정이 잘못되었습니다.", TaskLogType.Failed);
                    return;
                }
            }

            youtubeSearching = true;
            _detailsOption.YoutubeEnableChange(false);
            _vertManager.ChangeEditable(false, ServiceKind.Youtube);
            lvYoutube.Items.Clear();

            Thread thr = new Thread(() =>
            {
                var sw = new Stopwatch();
                var youtubeSearcher        = new YoutubeSearcher();
                bool isCanceled            = false;
                SearchResult info          = SearchResult.Fail_APIError;
                YoutubeSearchOption option = YoutubeSearchOption.GetDefault();

                youtubeSearcher.SearchProgressChanged += Searcher_SearchProgressChanged;
                youtubeSearcher.SearchFinished        += Searcher_SearchFinished;
                youtubeSearcher.ChangeInfoMessage     += Searcher_ChangeInfoMessage;
                youtubeSearcher.SearchItemFound       += Searcher_SearchItemFound;

                Dispatcher.Invoke(() =>
                {
                    sw.Start();

                    AddLog("Youtube 검색 엔진을 초기화중입니다.", TaskLogType.SearchReady);

                    option       = SettingManager.YoutubeSearchOption;
                    option.Query = tbQuery.Text;

                    var tb = new TaskProgressBar();

                    tb.SetValue(title: "Youtube 검색", message: "검색이 진행중입니다.", maximum: 1);

                    lvTask.Items.Insert(0, tb);
                    dict[youtubeSearcher] = tb;

                    if (option.OutputServices == OutputFormat.None)
                    {
                        tb.SetValue(message: "결과를 내보낼 위치가 없습니다.", maximum: 1);
                        AddLog("검색을 내보낼 위치가 없습니다.", TaskLogType.Failed);

                        info       = SearchResult.Fail_InvaildSetting;
                        isCanceled = true;
                    }

                    youtubeSearcher.Vertification(SettingManager.YoutubeCredentials.Item1);

                    if (!youtubeSearcher.IsVerification) // 인증되지 않았을 경우
                    {
                        tb.SetValue(message: "API키가 인증되지 않았습니다.", maximum: 1);
                        AddLog("API키가 인증되지 않았습니다.", TaskLogType.Failed);

                        info       = SearchResult.Fail_APIError;
                        isCanceled = true;
                    }
                });

                IEnumerable <YoutubeSearchResult> youtubeResult = null;
                ExportResultPack pack = null;

                if (!isCanceled)
                {
                    try
                    {
                        youtubeResult = youtubeSearcher.Search(option);

                        if (youtubeResult.Count() == 0)
                        {
                            info = SearchResult.Fail_NoResult;
                            AddLog("검색 결과가 없습니다.", TaskLogType.Failed);
                        }
                        else
                        {
                            info = SearchResult.Success;
                            AddLog("검색 결과를 내보내는 중입니다.", TaskLogType.Searching);
                            pack = Export(option.OutputServices, youtubeResult, ServiceKind.Youtube);
                        }
                    }
                    catch (InvaildOptionException)
                    {
                        AddLog("'Youtube' 검색 중 오류가 발생했습니다. [날짜를 사용하지 않은 상태에서는 '하루 기준' 옵션을 사용할 수 없습니다.]", TaskLogType.Failed);
                        info = SearchResult.Fail_InvaildSetting;
                    }
                    catch (CredentialsTypeException ex)
                    {
                        // TODO: Exception에 오류 코드 추가
                        AddLog("'Youtube' 검색 중 오류가 발생했습니다. [Youtube의 API키가 올바르게 입력되지 않은거 같습니다.]", TaskLogType.Failed);

                        Dispatcher.Invoke(() => SettingManager.YoutubeCredentials.Item2 = VerifyType.Invalid);

                        info = SearchResult.Fail_APIError;
                    }
                }

                Dispatcher.Invoke(() => {
                    AddLog($"Youtube 검색에 소요된 시간 : {sw.ElapsedMilliseconds}ms", TaskLogType.Complete);

                    _taskReport.AddReport(new TaskReportData()
                    {
                        Query            = option.Query,
                        RequestService   = ServiceKind.Youtube,
                        SearchCount      = option.SearchCount,
                        SearchData       = youtubeResult,
                        SearchDate       = DateTime.Now,
                        SearchResult     = info,
                        OutputFormat     = option.OutputServices,
                        ExportResultPack = pack
                    });

                    _taskReport.SetLastReport();

                    youtubeSearching = false;
                    _detailsOption.YoutubeEnableChange(true);
                    _vertManager.ChangeEditable(true, ServiceKind.Youtube);
                });
            });

            thr.Start();
        }
Beispiel #3
0
        //[ActionName("YoutubeSearch")]
        //[Route("youtubeSearch")]
        public async Task <IActionResult> Index(string YoutubeUri, string JobId)
        {
            ViewBag.JobId = JobId;

            try
            {
                VideoDownloader videoDownloader = new VideoDownloader();
                await _hubContext.Clients.Group(JobId).SendAsync("Index", "Start downloading video ...");

                string VideoFileName = videoDownloader.DownloadAsync(YoutubeUri, _configuration, _hubContext, JobId);


                if (VideoFileName != string.Empty)
                {
                    await _hubContext.Clients.Group(JobId).SendAsync("Index", "video downloaded successfully");

                    await Task.Delay(500);

                    VideoConverter videoConverter = new VideoConverter();
                    await _hubContext.Clients.Group(JobId).SendAsync("Index", "start converting video into mp3 format ...");

                    int errorCode = videoConverter.ConvertAsync(VideoFileName, _configuration, _hubContext, JobId);
                    if (errorCode == 0)
                    {
                        await _hubContext.Clients.Group(JobId).SendAsync("Index", "video converted successfully");

                        await Task.Delay(500);


                        AudioRecongnition audioRecongnition = new AudioRecongnition();
                        await _hubContext.Clients.Group(JobId).SendAsync("Index", "start recognition process of mp3 music ...");

                        RecognitionResultModel recognitionResultModel = await audioRecongnition.RecognizeAsync(VideoFileName, _configuration);

                        if (recognitionResultModel.errorCode == 0)
                        {
                            await _hubContext.Clients.Group(JobId).SendAsync("Index", "mp3 music recognized successfully successfully");

                            await Task.Delay(500);

                            YoutubeSearcher youtubeSearcher = new YoutubeSearcher();

                            await _hubContext.Clients.Group(JobId).SendAsync("Index", "Searching for videos related to the artist...");

                            List <VideoTempleteModel> listVideo = await youtubeSearcher.Run(recognitionResultModel.artist);

                            await _hubContext.Clients.Group(JobId).SendAsync("Index", "Getting youtube result...");

                            await Task.Delay(500);

                            ViewBag.error = "Video list is empty!";
                            return(View("Index", listVideo));;
                        }
                        else
                        {
                            ViewBag.error = recognitionResultModel.errorDescription;
                            return(View("Index", new List <VideoTempleteModel>()));
                        }
                    }
                    else
                    {
                        ViewBag.error = "Sorry! An Error occure in converting video into mp3 music";
                        return(View("Index", new List <VideoTempleteModel>()));
                    }
                }
                else
                {
                    ViewBag.error = "sorry! An error occure in downloading video";
                    return(View("Index", new List <VideoTempleteModel>()));
                }
            }
            catch (Exception ex)
            {
                ViewBag.error = "Unknown error ocured - " + ex.Message;

                return(View("Index", new List <VideoTempleteModel>()));
            }
        }