Beispiel #1
0
        public TwitchClip[] GetClips(string broadcasterId)
        {
            TwitchClip[] twitchClips = new TwitchClip[100];
            int          index       = 0;

            using (WebClient wc = CreateTwitchWebClient())
            {
                string getUserUrl = string.Format(Get_Clips_URL_T, broadcasterId) + "&first=100";
                //string getUserUrl = string.Format(Get_Clips_URL_T, broadcasterId) + "&first=100" + "&started_at=2019-01-01T22:34:18Z" + "&ended_at=2019-03-01T22:34:18Z";
                //string getUserUrl = string.Format(Get_Clips_URL, broadcasterId, "", "", "", 100, "");
                string  twitchClipsStr  = wc.DownloadString(getUserUrl);
                JObject twitchClipsJson = JObject.Parse(twitchClipsStr);

                foreach (JObject twitchClipJson in twitchClipsJson.Value <JArray>("data"))
                {
                    twitchClips[index]           = new TwitchClip();
                    twitchClips[index].Title     = twitchClipJson["title"].ToString();
                    twitchClips[index].CreatedAt = twitchClipJson["created_at"].ToString();
                    index++;
                }
            }
            return(twitchClips);
        }
Beispiel #2
0
 public DownloadInfo(TwitchClip Clip, string Path)
 {
     clip = Clip;
     path = Path;
 }
        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);
        }