public async Task Run()
    {
        try
        {
            string PageResponse = await RequestCurrentStatus();

            if (PageResponse != null)
            {
                Player DownloadInfo = Player.RetrievePlayer(PageResponse);
                if (DownloadInfo.Quality == Quality.NotFound)
                {
                    return;
                }

                string Title       = ScrapeBit.FirstFrom(PageResponse, TITLE);
                string Path        = FilePaths.GetLivestreamsPath(FileName.Purify($"{Title} [{DateTime.Now.Ticks.GetHashCode()}].mp4"));
                string Description = ScrapeBit.FirstFrom(PageResponse, DESCRIPTION);


                Console.WriteLine($"Found Livestream with Title: {Title} and Quality: {DownloadInfo.Quality}");
                await Download(DownloadInfo.Url, Path);

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

                _ = Upload.UploadWithRetry(new YoutubeUpload()
                {
                    LivestreamPath = Path, Title = Title, Description = Description, ThumbnailPath = null
                }, TimeSpan.FromHours(3));
            }
        }

        catch (Exception x) { Console.WriteLine($"Error in Check loop, Exception occurred: {x.Message}, please restart"); }
    }
Example #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);
        }
    }
    public async Task Run()
    {
        try
        {
            var Status = await GetLivestreamStatusFromChannelId(ChannelId);

            if (!Status.IsLivestreaming)
            {
                return;
            }

            var ytExplode = new YoutubeClient();
            var metadata  = await ytExplode.Videos.GetAsync(Status.videoId);

            var UploadInformation = new YoutubeUpload()
            {
                Title          = metadata.Title,
                Description    = metadata.Description,
                ThumbnailPath  = FilePaths.GetThumbnailPath(FileName.Purify($"{metadata.Title} [{DateTime.Now.Ticks.GetHashCode()}].jpeg")),
                LivestreamPath = FilePaths.GetLivestreamsPath(FileName.Purify($"{metadata.Title} [{DateTime.Now.Ticks.GetHashCode()}].mp4"))
            };

            CMessage.LivestreamFound(metadata.Title, Platform.YouTube);


            try
            { // Try in a try, because sometimes thumbnail downloads fails
              // if not this try block it will not download the livestream and will not upload
                new WebClient().DownloadFile(metadata.Thumbnails.MaxResUrl, UploadInformation.ThumbnailPath);
            }
            catch (Exception) { }

            await Streamlink.Download(UploadInformation.LivestreamPath, metadata.Url);

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

            _ = Upload.UploadWithRetry(UploadInformation, TimeSpan.FromHours(3));
        }
        catch (Exception x)
        {
            CError.ErrorInRunBlock(API_NAME, x.Message);
        }
    }