(link string)
| 10 | ) |
| 11 | |
| 12 | func ParseURL(link string) (model.Info, error) { |
| 13 | parsed, err := parseURL(link) |
| 14 | if err != nil { |
| 15 | return model.Info{}, err |
| 16 | } |
| 17 | |
| 18 | info := model.Info{} |
| 19 | |
| 20 | if strings.HasSuffix(parsed.Host, "youtube.com") { |
| 21 | kind, id, err := parseYoutubeURL(parsed) |
| 22 | if err != nil { |
| 23 | return model.Info{}, err |
| 24 | } |
| 25 | |
| 26 | info.Provider = model.ProviderYoutube |
| 27 | info.LinkType = kind |
| 28 | info.ItemID = id |
| 29 | |
| 30 | return info, nil |
| 31 | } |
| 32 | |
| 33 | if strings.HasSuffix(parsed.Host, "vimeo.com") { |
| 34 | kind, id, err := parseVimeoURL(parsed) |
| 35 | if err != nil { |
| 36 | return model.Info{}, err |
| 37 | } |
| 38 | |
| 39 | info.Provider = model.ProviderVimeo |
| 40 | info.LinkType = kind |
| 41 | info.ItemID = id |
| 42 | |
| 43 | return info, nil |
| 44 | } |
| 45 | |
| 46 | if strings.HasSuffix(parsed.Host, "soundcloud.com") { |
| 47 | kind, id, err := parseSoundcloudURL(parsed) |
| 48 | if err != nil { |
| 49 | return model.Info{}, err |
| 50 | } |
| 51 | |
| 52 | info.Provider = model.ProviderSoundcloud |
| 53 | info.LinkType = kind |
| 54 | info.ItemID = id |
| 55 | |
| 56 | return info, nil |
| 57 | } |
| 58 | |
| 59 | return model.Info{}, errors.New("unsupported URL host") |
| 60 | } |
| 61 | |
| 62 | func parseURL(link string) (*url.URL, error) { |
| 63 | if !strings.HasPrefix(link, "http") { |
no test coverage detected