Skip to content

Commit

Permalink
fix yt issue Couldn't extract url from format iawia002#622
Browse files Browse the repository at this point in the history
  • Loading branch information
joeke80215 authored and M1178475702 committed Apr 16, 2020
1 parent 7e28d26 commit b33f37f
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions extractors/youtube/youtube.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,29 @@ type streamFormat struct {

type playerResponseType struct {
StreamingData struct {
Formats []streamFormat `json:"formats"`
AdaptiveFormats []streamFormat `json:"adaptiveFormats"`
Formats []streamFormat `json:"formats"`
AdaptiveFormats adaptiveFormats `json:"adaptiveFormats"`
} `json:"streamingData"`
VideoDetails struct {
Title string `json:"title"`
} `json:"videoDetails"`
}

type adaptiveFormats []streamFormat

func (playerAdaptiveFormats adaptiveFormats) filterPlayerAdaptiveFormats(videoInfoFormats ytdl.FormatList) (filter adaptiveFormats) {
videoInfoFormatMap := make(map[int]struct{}, len(videoInfoFormats))
for _, f := range videoInfoFormats {
videoInfoFormatMap[f.Number] = struct{}{}
}
for _, f := range playerAdaptiveFormats {
if _, ok := videoInfoFormatMap[f.Itag]; ok {
filter = append(filter, f)
}
}
return
}

type youtubeData struct {
Args struct {
PlayerResponse string `json:"player_response"`
Expand Down Expand Up @@ -131,6 +146,10 @@ func youtubeDownload(uri string) downloader.Data {
return downloader.EmptyData(uri, err)
}
title := playerResponse.VideoDetails.Title
playerResponse.StreamingData.AdaptiveFormats = playerResponse.
StreamingData.
AdaptiveFormats.
filterPlayerAdaptiveFormats(videoInfo.Formats)

streams, err := extractVideoURLS(playerResponse, videoInfo)
if err != nil {
Expand All @@ -156,7 +175,7 @@ func getStreamExt(streamType string) string {
}

func getRealURL(videoFormat streamFormat, videoInfo *ytdl.VideoInfo, ext string) (*downloader.URL, error) {
ytdlFormat := new(ytdl.Format)
var ytdlFormat *ytdl.Format
for _, f := range videoInfo.Formats {
if f.Itag.Number == videoFormat.Itag {
ytdlFormat = f
Expand Down

0 comments on commit b33f37f

Please sign in to comment.