MCPcopy
hub / github.com/mxpv/podsync / parseYoutubeURL

Function parseYoutubeURL

pkg/builder/url.go:75–126  ·  view source on GitHub ↗
(parsed *url.URL)

Source from the content-addressed store, hash-verified

73}
74
75func parseYoutubeURL(parsed *url.URL) (model.Type, string, error) {
76 path := parsed.EscapedPath()
77
78 // https://www.youtube.com/playlist?list=PLCB9F975ECF01953C
79 // https://www.youtube.com/watch?v=rbCbho7aLYw&list=PLMpEfaKcGjpWEgNtdnsvLX6LzQL0UC0EM
80 if strings.HasPrefix(path, "/playlist") || strings.HasPrefix(path, "/watch") {
81 kind := model.TypePlaylist
82
83 id := parsed.Query().Get("list")
84 if id != "" {
85 return kind, id, nil
86 }
87
88 return "", "", errors.New("invalid playlist link")
89 }
90
91 // - https://www.youtube.com/channel/UC5XPnUk8Vvv_pWslhwom6Og
92 // - https://www.youtube.com/channel/UCrlakW-ewUT8sOod6Wmzyow/videos
93 if strings.HasPrefix(path, "/channel") {
94 kind := model.TypeChannel
95 parts := strings.Split(parsed.EscapedPath(), "/")
96 if len(parts) <= 2 {
97 return "", "", errors.New("invalid youtube channel link")
98 }
99
100 id := parts[2]
101 if id == "" {
102 return "", "", errors.New("invalid id")
103 }
104
105 return kind, id, nil
106 }
107
108 // - https://www.youtube.com/user/fxigr1
109 if strings.HasPrefix(path, "/user") {
110 kind := model.TypeUser
111
112 parts := strings.Split(parsed.EscapedPath(), "/")
113 if len(parts) <= 2 {
114 return "", "", errors.New("invalid user link")
115 }
116
117 id := parts[2]
118 if id == "" {
119 return "", "", errors.New("invalid id")
120 }
121
122 return kind, id, nil
123 }
124
125 return "", "", errors.New("unsupported link format")
126}
127
128func parseVimeoURL(parsed *url.URL) (model.Type, string, error) {
129 parts := strings.Split(parsed.EscapedPath(), "/")

Callers 5

TestParseYoutubeURL_UserFunction · 0.85
ParseURLFunction · 0.85

Calls 1

GetMethod · 0.65

Tested by 4

TestParseYoutubeURL_UserFunction · 0.68