public async Task <BasicStreamInfo> GetLivestreamStatusFromChannelId(string ChannelId)
    {
        try
        {
            var client = new RestClient($"https://www.youtube.com/channel/{ChannelId}/live");
            client.Timeout = 8000;
            var request = new RestRequest(Method.GET);
            request.AddCookie("CONSENT", "YES+cb");
            IRestResponse response = await client.ExecuteAsync(request);

            if (response.StatusCode == HttpStatusCode.NotFound)
            {
                CMessage.GotResponseNonExistentUser(ChannelId, API_NAME);
                return(BasicStreamInfo.Empty);
            }

            string videoId = ScrapeBit.FirstString(response.Content, "\"videoDetails\":{\"videoId\":\"", "\"");
            if (videoId == null)
            {
                return(BasicStreamInfo.Empty);
            }

            if (response.Content.Contains("LIVE_STREAM_OFFLINE"))
            {
                CMessage.GotResponseScheduledLivestream(ChannelId, API_NAME);
                return(BasicStreamInfo.Empty);
            }
            else
            {
                return(new BasicStreamInfo(true, videoId));
            }
        }
        catch (Exception) { return(BasicStreamInfo.Empty); }
    }
예제 #2
0
    public async Task Run()
    {
        try
        {
            GetLiveInfo info = await GetInfoForSpecified();

            if (info == null || info.ProgramInfo == null)
            {
                CMessage.GotResponseNonExistentUser(Name, API_NAME); return;
            }

            if (!info.IsLive)
            {
                CMessage.GotResponseFromAPIStreamerOffline(Name, API_NAME); return;
            }

            string Title       = info.ProgramInfo.Title.ToString(); // ToString, not tested, maybe converts \n \3c.. chars like that to proper chars.
            string Path        = FilePaths.GetLivestreamsPath(FileName.Purify($"{info.ProgramInfo.Title} [{DateTime.Now.Ticks.GetHashCode()}].mp4"));
            string Description = info.StreamerInfo.Info.ToString();

            if (info.ProgramInfo.StreamInfo.Length < 1)
            {
                return;
            }
            StreamInfo HighestQuality = GetValidPlayUrl(info.ProgramInfo.StreamInfo);
            if (HighestQuality == null)
            {
                return;
            }

            CMessage.LivestreamFound(Title, HighestQuality.Desc, Platform.Trovo);

            await Download(HighestQuality.PlayUrl, Path);

            var Upload = new Youtube(FilePaths.SecretsFile);
            await Upload.Init();

            _ = Upload.UploadWithRetry(new YoutubeUpload()
            {
                LivestreamPath = Path, Title = info.ProgramInfo.Title, Description = Description, ThumbnailPath = null
            }, TimeSpan.FromHours(3));
        }
        catch (Exception)
        {
            CError.ErrorInRunBlock(API_NAME);
        }
    }