Skip to content

Commit

Permalink
Button to Open Media in VLC
Browse files Browse the repository at this point in the history
  • Loading branch information
DeekshithSH committed Jul 14, 2024
1 parent 3c52c67 commit 1e1ac1a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
28 changes: 18 additions & 10 deletions internal/commands/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,31 @@ func sendLink(ctx *ext.Context, u *ext.Update) error {
hash := utils.GetShortHash(fullHash)
link := fmt.Sprintf("%s/stream/%d?hash=%s", config.ValueOf.Host, messageID, hash)
text := []styling.StyledTextOption{styling.Code(link)}
row := tg.KeyboardButtonRow{
Buttons: []tg.KeyboardButtonClass{
&tg.KeyboardButtonURL{
Text: "Download",
URL: link + "&d=true",
markup := &tg.ReplyInlineMarkup{
Rows: []tg.KeyboardButtonRow{{
Buttons: []tg.KeyboardButtonClass{
&tg.KeyboardButtonURL{
Text: "Download",
URL: link + "&d=true",
},
},
},
}},
}
if strings.Contains(file.MimeType, "video") || strings.Contains(file.MimeType, "audio") || strings.Contains(file.MimeType, "pdf") {
row.Buttons = append(row.Buttons, &tg.KeyboardButtonURL{
markup.Rows[0].Buttons = append(markup.Rows[0].Buttons, &tg.KeyboardButtonURL{
Text: "Stream",
URL: link,
})
markup.Rows = append(markup.Rows, tg.KeyboardButtonRow{
Buttons: []tg.KeyboardButtonClass{
&tg.KeyboardButtonURL{
Text: "Open In VLC",
URL: fmt.Sprintf("%s/vlc/%d?hash=%s", config.ValueOf.Host, messageID, hash),
},
},
})
}
markup := &tg.ReplyInlineMarkup{
Rows: []tg.KeyboardButtonRow{row},
}
fmt.Println(markup)
if strings.Contains(link, "http://localhost") {
_, err = ctx.Reply(u, text, &ext.ReplyOpts{
NoWebpage: false,
Expand Down
9 changes: 9 additions & 0 deletions internal/routes/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ func (e *allRoutes) LoadHome(r *Route) {
r.Engine.GET("/stream/:messageID", getStreamRoute)
}

func (e *allRoutes) LoadVLC(r *Route) {
log = e.log.Named("VLC Redirect")
defer log.Info("Redirect to VLC")
r.Engine.GET("/vlc/:messageID", func(ctx *gin.Context) {
ctx.Redirect(http.StatusMovedPermanently,
fmt.Sprintf("vlc://%s/stream/%s?hash=%s", ctx.Request.Host, ctx.Param("messageID"), ctx.Query("hash")))
})
}

func getStreamRoute(ctx *gin.Context) {
w := ctx.Writer
r := ctx.Request
Expand Down

0 comments on commit 1e1ac1a

Please sign in to comment.