go run main.go https://www.youtube.com/watch\?v\=pp-wmEKWLSo\&gdfds 0h0m12s 0h1m12s https://www.youtube.com/embed/pp-wmEKWLSo?end=72&gdfds=&start=12&v=pp-wmEKWLSo
Created
March 5, 2021 08:29
-
-
Save owulveryck/22c0c906ace95fb6920e8b09d27c5e5d to your computer and use it in GitHub Desktop.
Create a youtube video link with a portion of the video only
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"net/url" | |
"os" | |
"time" | |
) | |
func main() { | |
embededLink, _ := url.Parse(`https://www.youtube.com/embed/`) | |
u, err := url.Parse(os.Args[1]) | |
if err != nil { | |
log.Fatal(err) | |
} | |
v := u.Query()["v"] | |
if len(v) == 0 { | |
log.Fatal("bad request") | |
} | |
embededLink.Path = embededLink.Path + v[0] | |
start, err := time.ParseDuration(os.Args[2]) | |
if err != nil { | |
log.Fatal(err) | |
} | |
end, err := time.ParseDuration(os.Args[3]) | |
if err != nil { | |
log.Fatal(err) | |
} | |
q := u.Query() | |
q.Set("start", fmt.Sprintf("%.0f", start.Seconds())) | |
q.Set("end", fmt.Sprintf("%.0f", end.Seconds())) | |
embededLink.RawQuery = q.Encode() | |
fmt.Println(embededLink) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment