From 9d9fb9c745757a0f78cc8a219f9d917143af271e Mon Sep 17 00:00:00 2001 From: Benjamin Waller Date: Mon, 13 Jul 2020 10:30:46 +0200 Subject: [PATCH 1/2] added Scrobble and Unscrobble Scrobble und Unscrobble allows to set a mediaitem to watched or unwatched --- plex.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/plex.go b/plex.go index 1424b52..24c5feb 100644 --- a/plex.go +++ b/plex.go @@ -1157,3 +1157,48 @@ func (p *Plex) TerminateSession(sessionID string, reason string) error { return nil } + +// Scrobble sets watched status of KEY to watched +func (p *Plex) Scrobble(key string) error { + re, _ := regexp.Compile("([0-9]+)") + keynumber := re.FindString(key) + + query := fmt.Sprintf("%s/:/scrobble?identifier=com.plexapp.plugins.library&key=%s", p.URL, keynumber) + + resp, err := p.get(query, p.Headers) + + if err != nil { + return err + } + + defer resp.Body.Close() + + if resp.StatusCode != http.StatusOK { + return errors.New(resp.Status) + } + + return nil +} + +// Unscrobble sets watched status of KEY to unwatched +func (p *Plex) Unscrobble(key string) error { + + re, _ := regexp.Compile("([0-9]+)") + keynumber := re.FindString(key) + + query := fmt.Sprintf("%s/:/unscrobble?identifier=com.plexapp.plugins.library&key=%s", p.URL, keynumber) + + resp, err := p.get(query, p.Headers) + + if err != nil { + return err + } + + defer resp.Body.Close() + + if resp.StatusCode != http.StatusOK { + return errors.New(resp.Status) + } + + return nil +} From 4bab7500d8472d9a3dbf208320e59d8281d9a4d3 Mon Sep 17 00:00:00 2001 From: Benjamin Waller Date: Mon, 13 Jul 2020 10:36:08 +0200 Subject: [PATCH 2/2] added regexp import --- plex.go | 1 + 1 file changed, 1 insertion(+) diff --git a/plex.go b/plex.go index 24c5feb..8213a37 100644 --- a/plex.go +++ b/plex.go @@ -10,6 +10,7 @@ import ( "io/ioutil" "net/http" "net/url" + "regexp" "runtime" "strconv" "time"