Skip to content

Commit

Permalink
Merge pull request #54 from iloveicedgreentea/develop
Browse files Browse the repository at this point in the history
Actual Jellyfin support and misc fixes
  • Loading branch information
iloveicedgreentea authored Feb 11, 2024
2 parents 46b6e6b + 6223b71 commit 2edbd2e
Show file tree
Hide file tree
Showing 21 changed files with 853 additions and 493 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
uses: docker/[email protected]

- name: Log into registry ${{ env.REGISTRY }}
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') }}
# if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') || github.event_name == 'pull_request'}}
uses: docker/[email protected]
with:
registry: ${{ env.REGISTRY }}
Expand All @@ -43,5 +43,5 @@ jobs:
uses: docker/[email protected]
with:
context: .
push: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') }}
push: true
tags: ${{ steps.meta.outputs.tags }}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.21 as build
FROM golang:1.22 as build

WORKDIR /go/src/app
COPY . .
Expand Down
21 changes: 21 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM golang:1.22 as build

WORKDIR /go/src/app
COPY . .
RUN go mod download
WORKDIR /go/src/app/cmd

RUN CGO_ENABLED=0 go build -o /go/bin/app

FROM alpine:20231219

RUN apk add supervisor
COPY docker/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY docker/watch.py /watch.py

COPY --from=build /go/bin/app /
COPY --from=build /go/src/app/web /web
EXPOSE 9999

# CMD ["/app"]
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ build:
test:
./test.sh
docker-build:
docker buildx build --load --tag gowatchit-local .
docker buildx build --platform linux/amd64 --load --tag gowatchit-local . -f ./Dockerfile.dev
docker-push:
docker buildx build --push --platform linux/amd64 --tag ghcr.io/iloveicedgreentea/gowatchit:test .
docker-run:
LOG_FILE=false LOG_LEVEL=debug docker-compose up
LOG_FILE=false LOG_LEVEL=debug docker-compose -f docker-compose-test.yml up
run: build
LOG_FILE=false LOG_LEVEL=debug ./build/server
6 changes: 4 additions & 2 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,7 @@ Modify UUID filter to accept comma for multiple
* fix cache on resume
* various speedups
* remove listen port config
* improve search by using tmdb
* add author name to mqtt topic and logs
* improve search by filtering tmdb
* add author name to mqtt topic and logs
* add option to skip TMDB for jellyfin, seems to be necessary because their metadata is super unreliable
* Implement start/stop support for jellyfin
3 changes: 1 addition & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ func main() {
r.GET("/health", handlers.ProcessHealthcheckWebhookGin)

// Add plex webhook handler
// TODO: split out non plex specific stuff into a library
r.POST("/plexwebhook", func(c *gin.Context) {
handlers.ProcessWebhook(plexChan, c)
})
Expand All @@ -92,11 +91,11 @@ func main() {
r.POST("/save-config", api.SaveConfig)
// TODO: add generic webhook endpoint, maybe mqtt?

// TODO implement signal checking, error chan, etc
/*
###############################
block until workers get ready
############################## */
log.Info("Waiting for workers to be ready...")
<-plexReady
<-minidspReady
<-jfReady
Expand Down
14 changes: 14 additions & 0 deletions docker-compose-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: '3.8'

services:
plex-webhook-automation:
platform: linux/amd64
image: gowatchit-local:latest
ports:
- '9999:9999'
environment:
SUPER_DEBUG: 'false'
LOG_LEVEL: 'debug'
volumes:
- ./docker/data:/data
- ./web:/web
1 change: 0 additions & 1 deletion internal/common/webhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/iloveicedgreentea/go-plex/models"
)

// TODO: test this if not already
func DecodeWebhook(payload []string) (models.PlexWebhookPayload, int, error) {
var pwhPayload models.PlexWebhookPayload

Expand Down
70 changes: 60 additions & 10 deletions internal/ezbeq/ezbeq.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ func (c *BeqClient) MuteCommand(status bool) error {
func (c *BeqClient) MakeCommand(payload []byte) error {
for _, v := range c.DeviceInfo {
endpoint := fmt.Sprintf("/api/1/devices/%s", v.Name)
log.Debugf("ezbeq: Using endpoint %s", endpoint)
_, err := c.makeReq(endpoint, payload, http.MethodPatch)
if err != nil {
return err
Expand Down Expand Up @@ -171,7 +170,7 @@ func (c *BeqClient) makeReq(endpoint string, payload []byte, methodType string)
// log.Debugf("Using url %s", req.URL)
// log.Debugf("Headers from req %v", req.Header)
// simple retry
res, err := c.makeCallWithRetry(req, 5, endpoint)
res, err := c.makeCallWithRetry(req, 20, endpoint)

return res, err
}
Expand All @@ -188,13 +187,15 @@ func (c *BeqClient) makeCallWithRetry(req *http.Request, maxRetries int, endpoin
res, err = c.HTTPClient.Do(req)
if err != nil {
log.Debugf("Error with request - Retrying %v", err)
time.Sleep(time.Second * 2)
continue
}
defer res.Body.Close()

resp, err = io.ReadAll(res.Body)
if err != nil {
log.Debugf("Reading body failed - Retrying %v", err)
time.Sleep(time.Second * 2)
continue
}

Expand All @@ -213,6 +214,7 @@ func (c *BeqClient) makeCallWithRetry(req *http.Request, maxRetries int, endpoin
log.Debug(string(resp), status)
log.Debug("Retrying request...")
err = fmt.Errorf("error in response: %v", res.Status)
time.Sleep(time.Second * 2)
continue
}
}
Expand Down Expand Up @@ -260,15 +262,37 @@ func (c *BeqClient) searchCatalog(m *models.SearchRequest) (models.BeqCatalog, e

// search through results and find match
for _, val := range payload {
log.Debugf("Beq results: Title: %v -- Codec %v, ID: %v", val.Title, val.AudioTypes, val.ID)
// if skipping TMDB, set the IDs to match
if config.GetBool("jellyfin.skiptmdb") {
if m.Title == "" {
return models.BeqCatalog{}, errors.New("title is blank, can't skip TMDB")
}
log.Debug("Skipping TMDB for search")
val.MovieDbID = m.TMDB
if !strings.EqualFold(val.Title, m.Title) {
log.Debugf("%s did not match with title %s", val.Title, m.Title)
continue
}
log.Debugf("%s matched with title %s", val.Title, m.Title)
}
log.Debugf("Beq results: Title: %v // Codec %v, ID: %v", val.Title, val.AudioTypes, val.ID)
// if we find a match, return it. Much easier to match on tmdb since plex provides it also
if val.MovieDbID == m.TMDB && val.Year == m.Year && val.AudioTypes[0] == m.Codec {
var audioMatch bool
// rationale here is some BEQ entries have multiple audio types in one entry
for _, v := range val.AudioTypes {
if strings.EqualFold(v, m.Codec) {
audioMatch = true
break
}
}
if val.MovieDbID == m.TMDB && val.Year == m.Year && audioMatch {
log.Debugf("%s matched with codecs %v, checking further", val.Title, val.AudioTypes)
// if it matches, check edition
if checkEdition(val, m.Edition) {
log.Infof("Found a match in catalog from author %s", val.Author)
return val, nil
} else {
log.Error("Found a match but editions did not match entry. Not loading")
log.Errorf("Found a potential match but editions did not match entry. Not loading")
}
}
}
Expand Down Expand Up @@ -299,9 +323,6 @@ func (c *BeqClient) LoadBeqProfile(m *models.SearchRequest) error {
return nil
}

if m.TMDB == "" {
return errors.New("tmdb is empty. Can't find a match")
}
log.Debugf("beq payload is %#v", m)

// if no devices provided, error
Expand Down Expand Up @@ -330,6 +351,37 @@ func (c *BeqClient) LoadBeqProfile(m *models.SearchRequest) error {
return err
}
}
// most metadata contains DD+5.1 or something but its actually DD+ Atmos, so try a few options
} else if m.Codec == "DD+Atmos5.1Maybe" {
m.Codec = "DD+ Atmos"
catalog, err = c.searchCatalog(m)
// else try DD+ 5.1
if err != nil {
m.Codec = "DD+ 5.1"
catalog, err = c.searchCatalog(m)
if err != nil {
m.Codec = "DD+"
catalog, err = c.searchCatalog(m)
if err != nil {
return err
}
}
}
} else if m.Codec == "DD+Atmos7.1Maybe" {
m.Codec = "DD+ Atmos"
catalog, err = c.searchCatalog(m)
// else try DD+ 7.1
if err != nil {
m.Codec = "DD+ 7.1"
catalog, err = c.searchCatalog(m)
if err != nil {
m.Codec = "DD+"
catalog, err = c.searchCatalog(m)
if err != nil {
return err
}
}
}
} else {
catalog, err = c.searchCatalog(m)
if err != nil {
Expand Down Expand Up @@ -382,8 +434,6 @@ func (c *BeqClient) LoadBeqProfile(m *models.SearchRequest) error {
// write payload to each device
for _, v := range m.Devices {
endpoint := fmt.Sprintf("/api/2/devices/%s", v)
log.Debugf("json payload %v", string(jsonPayload))
log.Debugf("using endpoint %s", endpoint)
_, err = c.makeReq(endpoint, jsonPayload, http.MethodPatch)
if err != nil {
log.Debugf("json payload %v", string(jsonPayload))
Expand Down
35 changes: 34 additions & 1 deletion internal/ezbeq/ezbeq_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ezbeq

import (
// "strings"
"strings"
"fmt"
"testing"

Expand Down Expand Up @@ -670,6 +670,35 @@ func TestLoadProfile(t *testing.T) {
Devices: []string{"master", "master2"},
Slots: []int{1},
},
// DD+Atmos5.1Maybe //underwater
{
TMDB: "443791",
Year: 2020,
Codec: "DD+Atmos5.1Maybe",
SkipSearch: false,
EntryID: "",
MVAdjust: 0.0,
DryrunMode: false,
PreferredAuthor: "none",
Edition: "",
MediaType: "movie",
Devices: []string{"master", "master2"},
Slots: []int{1},
},
{
TMDB: "804095",
Year: 2022,
Codec: "DD+Atmos7.1Maybe",
SkipSearch: false,
EntryID: "",
MVAdjust: 0.0,
DryrunMode: false,
PreferredAuthor: "none",
Edition: "",
MediaType: "movie",
Devices: []string{"master", "master2"},
Slots: []int{1},
},
}

for _, tc := range tt {
Expand All @@ -682,3 +711,7 @@ func TestLoadProfile(t *testing.T) {
}

}

func TestTitleCom(t *testing.T) {
assert.True(t, strings.EqualFold("American Sniper", ""))
}
Loading

0 comments on commit 2edbd2e

Please sign in to comment.