Created
December 10, 2019 11:56
-
-
Save kkdai/6f8ab73c16927f233cfccc1d656a33e6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func getVideoURL(data url.Values) (string, error) { | |
streamMap, ok := data["url_encoded_fmt_stream_map"] | |
if !ok { | |
err = errors.New(fmt.Sprint("no stream map found in the server's answer")) | |
return err | |
} | |
// read each stream | |
streamsList := strings.Split(streamMap[0], ",") | |
// Get video title and author. | |
title, author := getVideoTitleAuthor(answer) | |
// Get video download link | |
var streams []stream | |
for streamPos, streamRaw := range streamsList { | |
streamQry, err := url.ParseQuery(streamRaw) | |
if err != nil { | |
y.log(fmt.Sprintf("An error occured while decoding one of the video's stream's information: stream %d: %s\n", streamPos, err)) | |
continue | |
} | |
if _, ok := streamQry["quality"]; !ok { | |
y.log(fmt.Sprintf("An empty video's stream's information: stream %d\n", streamPos)) | |
continue | |
} | |
streams = append(streams, stream{ | |
"quality": streamQry["quality"][0], | |
"type": streamQry["type"][0], | |
"url": streamQry["url"][0], | |
"title": title, | |
"author": author, | |
}) | |
y.log(fmt.Sprintf("Title: %s Author: %s Stream found: quality '%s', format '%s'", title, author, streamQry["quality"][0], streamQry["type"][0])) | |
//2019/12/10 16:49:15 Title: dotGo 2015 - Rob Pike - Simplicity is Complicated Author: dotconferences Stream found: quality 'hd720', format 'video/mp4; codecs="avc1.64001F, mp4a.40.2"' | |
//2019/12/10 16:49:15 Title: dotGo 2015 - Rob Pike - Simplicity is Complicated Author: dotconferences Stream found: quality 'medium', format 'video/webm; codecs="vp8.0, vorbis"' | |
//2019/12/10 16:49:15 Title: dotGo 2015 - Rob Pike - Simplicity is Complicated Author: dotconferences Stream found: quality 'medium', format 'video/mp4; codecs="avc1.42001E, mp4a.40.2"' | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment