Пример #1
0
        public IActionResult DownloadSingleStream(long streamId)
        {
            using (var context = new MainDataContext()) {
                HandleDownloadStreamsLogic handleDownloadStreamsLogic = new HandleDownloadStreamsLogic();
                if (handleDownloadStreamsLogic.PrepareDownload(StreamHelpers.GetStreamDetails(streamId)))
                {
                    return(Ok());
                }
            }

            return(Conflict("Already exists."));
        }
Пример #2
0
        public void UpdateLiveStatus(List <Streamer> listOfStreamers)
        {
            string listOfIds = "?user_id=";

            for (int i = 0; i < listOfStreamers.Count; i++)
            {
                if (i != listOfStreamers.Count - 1)
                {
                    listOfIds += listOfStreamers[i].streamerId + "&user_id=";
                }
                else
                {
                    listOfIds += listOfStreamers[i].streamerId;
                }
            }

            TwitchApiHelpers twitchApiHelpers = new TwitchApiHelpers();
            var response = twitchApiHelpers.TwitchRequest($"https://api.twitch.tv/helix/streams{listOfIds}&first=100",
                                                          Method.GET);

            StreamHelpers.GetStreamsResult liveStream =
                JsonConvert.DeserializeObject <StreamHelpers.GetStreamsResult>(response.Content);

            for (int x = 0; x < listOfStreamers.Count; x++)
            {
                var stream = liveStream.data.FirstOrDefault(item => item.user_id == listOfStreamers[x].streamerId);

                if (stream != null && stream.type == "live")
                {
                    // if live and if not a re-run or something else

                    using (var context = new MainDataContext()) {
                        var alreadyExistingStream =
                            context.Streams.FirstOrDefault(item => item.vodId == Int64.Parse(stream.id));

                        var streamer =
                            context.Streamers.FirstOrDefault(item => item.streamerId == listOfStreamers[x].streamerId);

                        if (streamer.isLive == false)
                        {
                            streamer.isLive = true;
                            context.SaveChanges();
                        }

                        NotificationHub.Current.Clients.All.SendAsync($"{streamer.id}Live",
                                                                      true);

                        if (streamer.getLive == false || alreadyExistingStream != null)
                        {
                            // already downloading/downloaded, or user does not want to download this streamers live stream
                            continue;
                        }
                    }

                    if (DateTime.UtcNow.Subtract(stream.started_at).TotalMinutes < 5)
                    {
                        // queue up the stream to be downloaded
                        StreamExtended convertedLiveStream = new StreamExtended {
                            streamId   = StreamHelpers.GetStreamDetails(Int64.Parse(stream.id), true, stream.user_id).streamId,
                            vodId      = Int64.Parse(stream.id),
                            streamerId = stream.user_id,
                            title      = stream.title,
                            createdAt  = stream.started_at
                        };

                        CreateLiveStream createLiveStream = new CreateLiveStream();
                        createLiveStream.PrepareLiveStreamDownload(convertedLiveStream, stream.user_login);
                    }
                }
                else
                {
                    using (var context = new MainDataContext()) {
                        var streamer =
                            context.Streamers.FirstOrDefault(item => item.streamerId == listOfStreamers[x].streamerId);

                        if (streamer.isLive == true)
                        {
                            streamer.isLive = false;
                            context.SaveChanges();
                        }

                        NotificationHub.Current.Clients.All.SendAsync($"{streamer.id}Live",
                                                                      false);
                    }
                }
            }
        }