all repos — gopipe @ 4dee9cbfacb6ffa25a5915196d7cfeeacbd15999

Embed YouTube videos on Telegram, Discord and more!

pass mimetype to template
Marco Andronaco andronacomarco@gmail.com
Fri, 25 Oct 2024 16:19:03 +0200
commit

4dee9cbfacb6ffa25a5915196d7cfeeacbd15999

parent

8ec2c473fa23fd6f7418f00fad24c8c800d0ba87

2 files changed, 11 insertions(+), 3 deletions(-)

jump to
M src/app/handlers.gosrc/app/handlers.go

@@ -6,6 +6,7 @@ "html/template"

"log" "net/http" "regexp" + "strings" g "github.com/birabittoh/gopipe/src/globals" "github.com/kkdai/youtube/v2"

@@ -110,12 +111,19 @@ if g.Proxy {

videoURL = fmt.Sprintf("/proxy/%s/%d", videoID, formatID) } + splitResult := strings.Split(format.MimeType, ";") + var mimeType string + if len(splitResult) != 0 { + mimeType = splitResult[0] + } + data := map[string]interface{}{ "VideoID": videoID, "VideoURL": videoURL, "Author": video.Author, "Title": video.Title, "Description": video.Description, + "MimeType": mimeType, "Thumbnail": thumbnail, "Duration": video.Duration, "Captions": getCaptions(*video),
M templates/video.tmpltemplates/video.tmpl

@@ -13,19 +13,19 @@ <meta property="og:title" content="{{ .Title }}" />

<meta property="og:description" content="{{ .Description }}" /> <meta property="og:site_name" content="GoPipe ({{ .Author }})" /> <meta property="twitter:image" content="{{ .Thumbnail }}" /> - <meta property="twitter:player:stream:content_type" content="video/mp4" /> + <meta property="twitter:player:stream:content_type" content="{{ .MimeType }}" /> {{ if .VideoURL }} <meta property="og:video" content="{{ .VideoURL }}" /> <meta property="og:video:secure_url" content="{{ .VideoURL }}" /> <meta property="og:video:duration" content="{{ .Duration }}"> - <meta property="og:video:type" content="video/mp4" /> + <meta property="og:video:type" content="{{ .MimeType }}" /> {{ end }} {{end}} {{define "content" -}} <video style="width: 100%" autoplay controls> - <source src="{{ .VideoURL }}" type="video/mp4" /> + <source src="{{ .VideoURL }}" type="{{ .MimeType }}" /> {{ range .Captions }} <track kind="subtitles" label="{{ .Language }}" src="/sub/{{ .VideoID }}/{{ .Language }}.vtt" srclang="{{ .Language }}" /> {{ end }}