|
|
@ -11,7 +11,6 @@ import (
|
|
11
|
11
|
"io/ioutil"
|
|
12
|
12
|
"net/url"
|
|
13
|
13
|
"os"
|
|
14
|
|
"strings"
|
|
15
|
14
|
|
|
16
|
15
|
"github.com/russross/blackfriday"
|
|
17
|
16
|
"gopkg.in/yaml.v2"
|
|
|
@ -128,17 +127,13 @@ func main() {
|
|
128
|
127
|
case "text":
|
|
129
|
128
|
err = textTmpl.Execute(os.Stdout, post)
|
|
130
|
129
|
case "video":
|
|
131
|
|
if !strings.HasPrefix(post.URL, "https://www.youtube.com/watch") {
|
|
132
|
|
exit(fmt.Errorf("can't handle video '%s'", post.URL))
|
|
133
|
|
}
|
|
134
|
|
|
|
135
|
130
|
u, err := url.Parse(post.URL)
|
|
136
|
131
|
if err != nil {
|
|
137
|
132
|
exit(fmt.Errorf("invalid video url '%s'", post.URL))
|
|
138
|
133
|
}
|
|
139
|
134
|
id := u.Query().Get("v")
|
|
140
|
|
if id == "" {
|
|
141
|
|
exit(fmt.Errorf("invalid video url '%s'", post.URL))
|
|
|
135
|
if (u.Host != "youtube.com" && u.Host != "www.youtube.com") || id == "" {
|
|
|
136
|
exit(fmt.Errorf("unsupported video url '%s'", post.URL))
|
|
142
|
137
|
}
|
|
143
|
138
|
post.URL = id
|
|
144
|
139
|
err = videoTmpl.Execute(os.Stdout, post)
|