Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions plex.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"io/ioutil"
"net/http"
"net/url"
"regexp"
"runtime"
"strconv"
"time"
Expand Down Expand Up @@ -1157,3 +1158,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
}