To receive notifications about scheduled maintenance, please subscribe to the mailing-list gitlab-operations@sympa.ethz.ch. You can subscribe to the mailing-list at https://sympa.ethz.ch

Commit 849caaa9 authored by Christof Gerber's avatar Christof Gerber
Browse files

Fix bug that GetSubtitle didn't check for automatic caption when auto=true

parent fb16074e
......@@ -40,6 +40,12 @@ var SupportedSubs = map[SubtitleFormat]bool{
SubTTML: true,
}
type ErrYoutubeDLLangNotSupported string
func (e ErrYoutubeDLLangNotSupported) Error() string {
return string(e)
}
type ErrYoutubeDL string
func (e ErrYoutubeDL) Error() string {
......@@ -144,7 +150,7 @@ func listSubs(id string) (subs *SubList, err error) {
return subs, nil
}
// findSub return nil when subtitle not available in any format
// findSub return nil when subtitle in the requested language is not available in any format
func findSub(id string, language string) (formats []string, err error) {
subList, err := listSubs(id)
if err != nil {
......@@ -205,12 +211,28 @@ func downloadSubtitle(auto bool, id string, language string, format string, file
// GetSubtitle downloads the subtitle of the video id in the passed language.
// Throws an error if subtitle not found.
// Downlaods the automaic caption when auto is true.
// Downlaods the automatic caption when auto is true.
func GetSubtitle(auto bool, id string, language string) (sub *astisub.Subtitles, err error) {
formats, err := findSub(id, language)
if err != nil {
return nil, err
var formats []string
if auto == false {
formats, err = findSub(id, language)
if err != nil {
return nil, err
}
if formats == nil {
return nil, ErrYoutubeDLLangNotSupported(fmt.Sprintf("No subtitle with language %s for video %s", language, id))
}
} else {
formats, err = findAutomaticCaption(id, language)
if err != nil {
return nil, err
}
if formats == nil {
return nil, ErrYoutubeDLLangNotSupported(fmt.Sprintf("No automatic caption with language %s for video %s", language, id))
}
}
for _, format := range formats {
......@@ -270,6 +292,8 @@ func GetVideoURL(id string) (video *url.URL, audio *url.URL, err error) {
return video, audio, nil
}
// GetPlaylistVideos returns a list of youtube video id's that are in the given playlist.
// The response is limited to the first 50 videos.
func GetPlaylistVideos(playListID string, apiKey string) (members []string, err error) {
client := &http.Client{
Transport: &transport.APIKey{Key: apiKey},
......@@ -280,7 +304,10 @@ func GetPlaylistVideos(playListID string, apiKey string) (members []string, err
return nil, err
}
// Make the API call to YouTube.
call := service.PlaylistItems.List("id,contentDetails").PlaylistId(playListID)
call := service.PlaylistItems.List("id,contentDetails").
PlaylistId(playListID).
MaxResults(50)
response, err := call.Do()
if err != nil {
return nil, err
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment