コード例 #1
0
        public override async Task <(ResultType result, List <DownloadInfo> downloadInfos)> GetFileUrlsOfVod(CancellationToken cancellationToken)
        {
            (bool retrieveVideoSuccess, HitboxVideo video) = await Hitbox.RetrieveVideo(VideoInfo.VideoId);

            if (!retrieveVideoSuccess)
            {
                return(ResultType.Failure, null);
            }

            VideoInfo = new HitboxVideoInfo(video);

            // TODO: Figure out how to determine quality when there are multiple.
            string m3u8path   = "https://smashcast-vod.akamaized.net/static/videos/vods" + GetM3U8PathFromM3U(video.MediaProfiles.First().Url);
            string folderpath = TsVideoJob.GetFolder(m3u8path);
            string m3u8;

            HttpClient          client   = new HttpClient();
            HttpResponseMessage response = await client.GetAsync(new Uri( m3u8path ));

            if (response.StatusCode == System.Net.HttpStatusCode.OK)
            {
                m3u8 = await response.Content.ReadAsStringAsync();
            }
            else
            {
                return(ResultType.Failure, null);
            }

            // who cares, hitbox is dead
            return(ResultType.Failure, null);

            //string[] filenames = TsVideoJob.GetFilenamesFromM3U8( m3u8 );
            //List<string> urls = new List<string>( filenames.Length );
            //foreach ( var filename in filenames ) {
            //	urls.Add( folderpath + filename );
            //}
            //return (ResultType.Success, urls.ToArray());
        }
コード例 #2
0
        public override async Task <(ResultType result, List <DownloadInfo> downloadInfos)> GetFileUrlsOfVod(CancellationToken cancellationToken)
        {
            var video_json = await TwitchYTDL.GetVideoJson(long.Parse(VideoInfo.VideoId));

            VideoInfo = new TwitchVideoInfo(TwitchYTDL.VideoFromJson(video_json));

            string folderpath;
            List <DownloadInfo> downloadInfos;

            while (true)
            {
                try {
                    bool interactive = false;
                    if (interactive)
                    {
                        Status = "";
                        string tmp1         = Path.Combine(GetTempFolder(), GetTempFilenameWithoutExtension() + "_baseurl.txt");
                        string tmp2         = Path.Combine(GetTempFolder(), GetTempFilenameWithoutExtension() + "_tsnames.txt");
                        string linesbaseurl = TryGetUserCopyBaseurlM3U(tmp1);
                        string linestsnames = TryGetUserCopyTsnamesM3U(tmp2);
                        if (linesbaseurl == null)
                        {
                            File.WriteAllText(tmp1, "get baseurl for m3u8 from https://www.twitch.tv/videos/" + VideoInfo.VideoId);
                        }
                        if (linestsnames == null)
                        {
                            File.WriteAllText(tmp2, "get actual m3u file from https://www.twitch.tv/videos/" + VideoInfo.VideoId);
                        }

                        if (linesbaseurl == null || linestsnames == null)
                        {
                            await Task.Delay(200);

                            Process.Start(tmp1);
                            await Task.Delay(200);

                            Process.Start(tmp2);
                            await Task.Delay(200);

                            return(ResultType.UserInputRequired, null);
                        }

                        folderpath    = TsVideoJob.GetFolder(GetM3U8PathFromM3U(linesbaseurl, VideoQuality));
                        downloadInfos = TsVideoJob.GetFilenamesFromM3U8(folderpath, linestsnames);
                    }
                    else
                    {
                        string m3u8path = ExtractM3u8FromJson(video_json);
                        folderpath = TsVideoJob.GetFolder(m3u8path);
                        var client = new System.Net.Http.HttpClient();
                        var result = await client.GetAsync(m3u8path);

                        string m3u8 = await result.Content.ReadAsStringAsync();

                        downloadInfos = TsVideoJob.GetFilenamesFromM3U8(folderpath, m3u8);
                    }
                } catch (TwitchHttpException e) {
                    if (e.StatusCode == System.Net.HttpStatusCode.NotFound && VideoInfo.VideoRecordingState == RecordingState.Live)
                    {
                        // this can happen on streams that have just started, in this just wait a bit and retry
                        try {
                            await Task.Delay(20000, cancellationToken);
                        } catch (TaskCanceledException) {
                            return(ResultType.Cancelled, null);
                        }
                        video_json = await TwitchYTDL.GetVideoJson(long.Parse(VideoInfo.VideoId));

                        VideoInfo = new TwitchVideoInfo(TwitchYTDL.VideoFromJson(video_json));
                        continue;
                    }
                    else
                    {
                        throw;
                    }
                }
                break;
            }

            return(ResultType.Success, downloadInfos);
        }