Skip to content

Commit

Permalink
Merge pull request #209 from iawia002/youku-lang
Browse files Browse the repository at this point in the history
extractors/youku: 🔧 multi-language video
  • Loading branch information
iawia002 authored Jul 29, 2018
2 parents e8169dd + ed845c0 commit ee8a445
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 17 deletions.
57 changes: 41 additions & 16 deletions extractors/youku.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ type segs struct {
}

type stream struct {
Size int64 `json:"size"`
Width int `json:"width"`
Height int `json:"height"`
Segs []segs `json:"segs"`
Type string `json:"stream_type"`
Size int64 `json:"size"`
Width int `json:"width"`
Height int `json:"height"`
Segs []segs `json:"segs"`
Type string `json:"stream_type"`
AudioLang string `json:"audio_lang"`
}

type youkuVideo struct {
Expand All @@ -53,6 +54,18 @@ type youkuData struct {

const youkuReferer = "https://v.youku.com"

func getAudioLang(lang string) string {
var youkuAudioLang = map[string]string{
"guoyu": "国语",
"ja": "日语",
}
translate, ok := youkuAudioLang[lang]
if !ok {
return lang
}
return translate
}

// https://g.alicdn.com/player/ykplayer/0.5.61/youku-player.min.js
// {"0505":"interior","050F":"interior","0501":"interior","0502":"interior","0503":"interior","0510":"adshow","0512":"BDskin","0590":"BDskin"}

Expand Down Expand Up @@ -87,18 +100,31 @@ func youkuUps(vid string) youkuData {

func genData(youkuData data) map[string]downloader.FormatData {
var (
size int64
bestQuality string
size int64
bestQuality string
formatString string
quality string
)
format := map[string]downloader.FormatData{}
// get the best quality
for _, s := range youkuData.Stream {
if s.Size > size {
size = s.Size
bestQuality = s.Type
}
}
for _, stream := range youkuData.Stream {
if stream.AudioLang == "default" {
formatString = stream.Type
quality = fmt.Sprintf(
"%s %dx%d", stream.Type, stream.Width, stream.Height,
)
} else {
formatString = fmt.Sprintf("%s-%s", stream.Type, stream.AudioLang)
quality = fmt.Sprintf(
"%s %dx%d %s", stream.Type, stream.Width, stream.Height,
getAudioLang(stream.AudioLang),
)
}
// get the best quality
if stream.Size > size {
size = stream.Size
bestQuality = formatString
}

ext := strings.Split(
strings.Split(stream.Segs[0].URL, "?")[0],
".",
Expand All @@ -112,8 +138,7 @@ func genData(youkuData data) map[string]downloader.FormatData {
}
urls = append(urls, url)
}
quality := fmt.Sprintf("%s %dx%d", stream.Type, stream.Width, stream.Height)
format[stream.Type] = downloader.FormatData{
format[formatString] = downloader.FormatData{
URLs: urls,
Size: stream.Size,
Quality: quality,
Expand Down
2 changes: 1 addition & 1 deletion extractors/youku_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestYouku(t *testing.T) {
URL: "http://v.youku.com/v_show/id_XMzQ1MTAzNjQwNA==.html",
Title: "这!就是街舞 第一季 第3期:百强“互杀”队长不忍直视",
Size: 750911635,
Quality: "mp4hd2v2 1280x720",
Quality: "mp4hd2v2 1280x720 国语",
},
},
}
Expand Down

0 comments on commit ee8a445

Please sign in to comment.