151 lines
4.2 KiB
Go
151 lines
4.2 KiB
Go
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io/ioutil"
|
|
"log"
|
|
"net/http"
|
|
"regexp"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func recv(c *gin.Context) {
|
|
c.Request.Header.Set("Content-Type", "application/json")
|
|
log.Println(c.Request.Header.Get("Content-Type"))
|
|
|
|
txt, _ := ioutil.ReadAll(c.Request.Body)
|
|
plain := string(txt)
|
|
|
|
regex := regexp.MustCompile(`{.*`)
|
|
js := regex.FindStringSubmatch(plain)
|
|
|
|
var p Plex
|
|
|
|
json.Unmarshal([]byte(js[0]), &p)
|
|
|
|
postToDiscord(p)
|
|
|
|
c.String(http.StatusOK, "ok")
|
|
}
|
|
|
|
func getEvent(e string) string {
|
|
switch e {
|
|
case "media.play":
|
|
return "started playing"
|
|
case "media.resume":
|
|
return "resumed playing"
|
|
case "media.stop":
|
|
return "stopped playing"
|
|
case "media.pause":
|
|
return "paused"
|
|
case "media.rate":
|
|
return "rated"
|
|
}
|
|
return e
|
|
}
|
|
|
|
type Plex struct {
|
|
Event string `json:"event"`
|
|
User bool `json:"user"`
|
|
Owner bool `json:"owner"`
|
|
Account Account `json:"Account"`
|
|
Server Server `json:"Server"`
|
|
Player Player `json:"Player"`
|
|
Metadata Metadata `json:"Metadata"`
|
|
}
|
|
type Account struct {
|
|
ID int `json:"id"`
|
|
Thumb string `json:"thumb"`
|
|
Title string `json:"title"`
|
|
}
|
|
type Server struct {
|
|
Title string `json:"title"`
|
|
UUID string `json:"uuid"`
|
|
}
|
|
type Player struct {
|
|
Local bool `json:"local"`
|
|
PublicAddress string `json:"publicAddress"`
|
|
Title string `json:"title"`
|
|
UUID string `json:"uuid"`
|
|
}
|
|
type Genre struct {
|
|
ID int `json:"id"`
|
|
Filter string `json:"filter"`
|
|
Tag string `json:"tag"`
|
|
Count int `json:"count"`
|
|
}
|
|
type Director struct {
|
|
ID int `json:"id"`
|
|
Filter string `json:"filter"`
|
|
Tag string `json:"tag"`
|
|
}
|
|
type Writer struct {
|
|
ID int `json:"id"`
|
|
Filter string `json:"filter"`
|
|
Tag string `json:"tag"`
|
|
Count int `json:"count,omitempty"`
|
|
}
|
|
type Producer struct {
|
|
ID int `json:"id"`
|
|
Filter string `json:"filter"`
|
|
Tag string `json:"tag"`
|
|
Count int `json:"count"`
|
|
}
|
|
type Country struct {
|
|
ID int `json:"id"`
|
|
Filter string `json:"filter"`
|
|
Tag string `json:"tag"`
|
|
Count int `json:"count"`
|
|
}
|
|
type Role struct {
|
|
ID int `json:"id"`
|
|
Filter string `json:"filter"`
|
|
Tag string `json:"tag"`
|
|
Count int `json:"count,omitempty"`
|
|
Role string `json:"role"`
|
|
Thumb string `json:"thumb,omitempty"`
|
|
}
|
|
type Similar struct {
|
|
ID int `json:"id"`
|
|
Filter string `json:"filter"`
|
|
Tag string `json:"tag"`
|
|
Count int `json:"count"`
|
|
}
|
|
type Metadata struct {
|
|
LibrarySectionType string `json:"librarySectionType"`
|
|
RatingKey string `json:"ratingKey"`
|
|
Key string `json:"key"`
|
|
GUID string `json:"guid"`
|
|
Studio string `json:"studio"`
|
|
Type string `json:"type"`
|
|
Title string `json:"title"`
|
|
LibrarySectionTitle string `json:"librarySectionTitle"`
|
|
LibrarySectionID int `json:"librarySectionID"`
|
|
LibrarySectionKey string `json:"librarySectionKey"`
|
|
ContentRating string `json:"contentRating"`
|
|
Summary string `json:"summary"`
|
|
Rating float64 `json:"rating"`
|
|
AudienceRating float64 `json:"audienceRating"`
|
|
ViewOffset int `json:"viewOffset"`
|
|
LastViewedAt int `json:"lastViewedAt"`
|
|
Year int `json:"year"`
|
|
Tagline string `json:"tagline"`
|
|
Thumb string `json:"thumb"`
|
|
Art string `json:"art"`
|
|
Duration int `json:"duration"`
|
|
OriginallyAvailableAt string `json:"originallyAvailableAt"`
|
|
AddedAt int `json:"addedAt"`
|
|
UpdatedAt int `json:"updatedAt"`
|
|
AudienceRatingImage string `json:"audienceRatingImage"`
|
|
PrimaryExtraKey string `json:"primaryExtraKey"`
|
|
RatingImage string `json:"ratingImage"`
|
|
Genre []Genre `json:"Genre"`
|
|
Director []Director `json:"Director"`
|
|
Writer []Writer `json:"Writer"`
|
|
Producer []Producer `json:"Producer"`
|
|
Country []Country `json:"Country"`
|
|
Role []Role `json:"Role"`
|
|
Similar []Similar `json:"Similar"`
|
|
}
|