Skip to content
This repository has been archived by the owner on Aug 12, 2020. It is now read-only.

Commit

Permalink
feature(getVideoInfo): provide flag for streams extracted from the DA…
Browse files Browse the repository at this point in the history
…SH manifest
  • Loading branch information
the TV authored and corny committed Mar 30, 2020
1 parent 8fbe86f commit 136380c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
3 changes: 3 additions & 0 deletions format.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ type Range struct {
type Format struct {
Itag
Adaptive bool
// FromDASH indicates that the stream
// was extracted from the DASH manifest file
FromDASH bool
Index *Range
Init *Range
url string
Expand Down
38 changes: 20 additions & 18 deletions video_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,20 @@ const youtubeDateFormat = "2006-01-02"

// VideoInfo contains the info a youtube video
type VideoInfo struct {
ID string // The video ID
Title string // The video title
Description string // The video description
DatePublished time.Time // The date the video was published
Formats FormatList // Formats the video is available in
Keywords []string // List of keywords associated with the video
Uploader string // Author of the video
Song string
Artist string
Album string
Writers string
Duration time.Duration // Duration of the video
htmlPlayerFile string
ID string // The video ID
Title string // The video title
Description string // The video description
DatePublished time.Time // The date the video was published
Formats FormatList // Formats the video is available in
DashManifestURL string // URI of the DASH manifest file
Keywords []string // List of keywords associated with the video
Uploader string // Author of the video
Song string
Artist string
Album string
Writers string
Duration time.Duration // Duration of the video
htmlPlayerFile string
}

// GetVideoInfo fetches info from a url string, url object, or a url string
Expand Down Expand Up @@ -262,17 +263,17 @@ func (c *Client) getVideoInfoFromHTML(cx context.Context, id string, html []byte
log.Debug().Msgf("No formats found")
}

if dashManifestURL := inf.Dashmpd; dashManifestURL != "" {
if info.DashManifestURL = inf.Dashmpd; info.DashManifestURL != "" {
tokens, err := c.getSigTokens(cx, info.htmlPlayerFile)
if err != nil {
return nil, fmt.Errorf("Unable to extract signature tokens: %w", err)
}
regex := regexp.MustCompile("\\/s\\/([a-fA-F0-9\\.]+)")
regexSub := regexp.MustCompile("([a-fA-F0-9\\.]+)")
dashManifestURL = regex.ReplaceAllStringFunc(dashManifestURL, func(str string) string {
info.DashManifestURL = regex.ReplaceAllStringFunc(info.DashManifestURL, func(str string) string {
return "/signature/" + decipherTokens(tokens, regexSub.FindString(str))
})
dashFormats, err := c.getDashManifest(cx, dashManifestURL)
dashFormats, err := c.getDashManifest(cx, info.DashManifestURL)
if err != nil {
return nil, fmt.Errorf("Unable to extract dash manifest: %w", err)
}
Expand Down Expand Up @@ -361,8 +362,9 @@ func (c *Client) getDashManifest(cx context.Context, urlString string) (formats
}
if itag := getItag(rep.Itag); itag != nil {
format := &Format{
Itag: *itag,
url: rep.URL,
Itag: *itag,
url: rep.URL,
FromDASH: true,
}
if rep.Height != 0 {
format.Itag.Resolution = strconv.Itoa(rep.Height) + "p"
Expand Down

0 comments on commit 136380c

Please sign in to comment.