예제 #1
0
        protected async Task <bool> CreateCompilationAsync(TimePeriod timePeriod)
        {
            Console.WriteLine($"Creating YouTube {timePeriod.ToString().ToLower()} compilation for the \"{ChannelName}\" channel");

            DateTime start = DateTime.UtcNow;

            List <RedditSubmission> redditSubmissions = await _redditManager.
                                                        ObtainTopAsync(RedditSub, "clips.twitch.tv", timePeriod, timePeriod != TimePeriod.Day);

            if (redditSubmissions.Count == 0)
            {
                Console.WriteLine("No submissions found on /r/" + RedditSub);
                return(false);
            }

            List <TwitchClip> twitchClips   = new List <TwitchClip>();
            TimeSpan          contentLength = new TimeSpan();

            for (int i = 0; i < redditSubmissions.Count && contentLength <= TimeSpan.FromSeconds(610); i++) // 10+ min vids
            {
                RedditSubmission submission = redditSubmissions.ElementAt(i);

                TwitchClip clip = _twitchManager.DownloadClip(submission.Title, submission.Url.AbsolutePath);

                if (clip != null)
                {
                    twitchClips.Add(clip);

                    contentLength = contentLength.Add(_videoManager.GetVideoLength(clip.LocalLocation));
                }
            }

            List <string> clipPaths = twitchClips.Select(x => x.LocalLocation).ToList();

            if (UseOutro)
            {
                clipPaths.Add(OutroPath);
            }

            string compilationPath = _videoManager.CreateCompilationVideo($"{ChannelName}_" +
                                                                          $"{timePeriod.ToString()}_{start.Year}-{start.Month}-{start.Day}-{start.Hour}", clipPaths);

            BuildVideoDetails(timePeriod, compilationPath, OutroPath, twitchClips, contentLength,
                              out string title, out string description, out List <string> youtubeTags);

            RemoveClips(twitchClips);

            _youtubeManager.UploadVideoAsync(ChannelName, title, description, youtubeTags.ToArray(), compilationPath).Wait();

            Console.WriteLine("Deleting compilation video from local disk and storing creation-entry in DB");
            try
            {
                File.Delete(compilationPath);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            _database.StoreUploadEntry(ChannelName, title, timePeriod, start);

            Console.WriteLine($"Finished proccess: Created and uploaded twitch " +
                              $"{timePeriod.ToString().ToLower()} compilation '{title}' at {start.ToString()}");

            return(true);
        }