splitting out the eraser model from the locator model, adding library type logic.

This commit is contained in:
Matt Burchett 2018-11-20 12:20:20 -06:00
parent 3e5695a802
commit 81797f66ca
5 changed files with 207 additions and 138 deletions

View File

@ -2,6 +2,7 @@ package main
import ( import (
"flag" "flag"
"fmt"
"log" "log"
"git.linuxrocker.com/mattburchett/Housekeeper/pkg/communicator" "git.linuxrocker.com/mattburchett/Housekeeper/pkg/communicator"
@ -37,6 +38,9 @@ func main() {
log.Fatal(err) log.Fatal(err)
} }
libraryType := locator.GetLibraryType(cfg, sectionID)
fmt.Println(libraryType)
ids, titles := locator.GetTitles(cfg, sectionID, days) ids, titles := locator.GetTitles(cfg, sectionID, days)
if check { if check {

View File

@ -21,9 +21,6 @@ func LookupFileLocation(config config.Config, ids []int) []string {
plexURL := fmt.Sprintf("%s:%d%s%d%s%s", config.PlexHost, config.PlexPort, "/library/metadata/", i, "/?X-Plex-Token=", config.PlexToken) plexURL := fmt.Sprintf("%s:%d%s%d%s%s", config.PlexHost, config.PlexPort, "/library/metadata/", i, "/?X-Plex-Token=", config.PlexToken)
req, err := http.NewRequest(http.MethodGet, plexURL, nil) req, err := http.NewRequest(http.MethodGet, plexURL, nil)
if err != nil {
log.Fatal(err)
}
httpClient := http.Client{} httpClient := http.Client{}
req.Header.Set("User-Agent", "Housekeeper") req.Header.Set("User-Agent", "Housekeeper")

View File

@ -2,6 +2,7 @@ package locator
import ( import (
"encoding/json" "encoding/json"
"encoding/xml"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"log" "log"
@ -14,6 +15,44 @@ import (
"git.linuxrocker.com/mattburchett/Housekeeper/pkg/util" "git.linuxrocker.com/mattburchett/Housekeeper/pkg/util"
) )
// GetLibraryType checks to see what type the library is.
func GetLibraryType(config config.Config, sectionID int) string {
typeURL := fmt.Sprintf("%s:%d%s%d%s%s", config.PlexHost, config.PlexPort, "/library/sections/", sectionID, "/?X-Plex-Token=", config.PlexToken)
req, err := http.NewRequest(http.MethodGet, typeURL, nil)
httpClient := http.Client{}
req.Header.Set("User-Agent", "Housekeeper")
res, getErr := httpClient.Do(req)
if getErr != nil {
log.Fatal(getErr)
}
body, readErr := ioutil.ReadAll(res.Body)
if readErr != nil {
log.Fatal(readErr)
}
if err != nil {
log.Fatal(err)
}
typeModel := model.XMLPlexLibraryType{}
xml.Unmarshal(body, &typeModel)
var libraryType string
if typeModel.Thumb == "/:/resources/movie.png" {
libraryType = "movie"
} else if typeModel.Thumb == "/:/resources/show.png" {
libraryType = "show"
} else {
log.Fatal("Unsupported library type found. This app only supports movies and shows.")
}
return libraryType
}
// GetCount will gather a count of media in a specific library, required for GetTitles. // GetCount will gather a count of media in a specific library, required for GetTitles.
func GetCount(config config.Config, sectionID int) int { func GetCount(config config.Config, sectionID int) int {
countURL := fmt.Sprintf("%s%s%s%s%s%d", config.BaseURL, config.PlexPyContext, "/api/v2?apikey=", config.PlexPyAPIKey, "&cmd=get_library&section_id=", sectionID) countURL := fmt.Sprintf("%s%s%s%s%s%d", config.BaseURL, config.PlexPyContext, "/api/v2?apikey=", config.PlexPyAPIKey, "&cmd=get_library&section_id=", sectionID)

140
pkg/model/eraser_model.go Normal file
View File

@ -0,0 +1,140 @@
package model
import "encoding/xml"
// XMLPlexAPI - This is the XML version of the struct below it.
type XMLPlexAPI struct {
XMLName xml.Name `xml:"MediaContainer"`
Text string `xml:",chardata"`
Size string `xml:"size,attr"`
AllowSync string `xml:"allowSync,attr"`
Identifier string `xml:"identifier,attr"`
LibrarySectionID string `xml:"librarySectionID,attr"`
LibrarySectionTitle string `xml:"librarySectionTitle,attr"`
LibrarySectionUUID string `xml:"librarySectionUUID,attr"`
MediaTagPrefix string `xml:"mediaTagPrefix,attr"`
MediaTagVersion string `xml:"mediaTagVersion,attr"`
Video struct {
Text string `xml:",chardata"`
RatingKey string `xml:"ratingKey,attr"`
Key string `xml:"key,attr"`
GUID string `xml:"guid,attr"`
LibrarySectionTitle string `xml:"librarySectionTitle,attr"`
LibrarySectionID string `xml:"librarySectionID,attr"`
LibrarySectionKey string `xml:"librarySectionKey,attr"`
Studio string `xml:"studio,attr"`
Type string `xml:"type,attr"`
Title string `xml:"title,attr"`
ContentRating string `xml:"contentRating,attr"`
Summary string `xml:"summary,attr"`
Rating string `xml:"rating,attr"`
AudienceRating string `xml:"audienceRating,attr"`
Year string `xml:"year,attr"`
Tagline string `xml:"tagline,attr"`
Thumb string `xml:"thumb,attr"`
Art string `xml:"art,attr"`
Duration string `xml:"duration,attr"`
OriginallyAvailableAt string `xml:"originallyAvailableAt,attr"`
AddedAt string `xml:"addedAt,attr"`
UpdatedAt string `xml:"updatedAt,attr"`
AudienceRatingImage string `xml:"audienceRatingImage,attr"`
ChapterSource string `xml:"chapterSource,attr"`
PrimaryExtraKey string `xml:"primaryExtraKey,attr"`
RatingImage string `xml:"ratingImage,attr"`
Media struct {
Text string `xml:",chardata"`
VideoResolution string `xml:"videoResolution,attr"`
ID string `xml:"id,attr"`
Duration string `xml:"duration,attr"`
Bitrate string `xml:"bitrate,attr"`
Width string `xml:"width,attr"`
Height string `xml:"height,attr"`
AspectRatio string `xml:"aspectRatio,attr"`
AudioChannels string `xml:"audioChannels,attr"`
AudioCodec string `xml:"audioCodec,attr"`
VideoCodec string `xml:"videoCodec,attr"`
Container string `xml:"container,attr"`
VideoFrameRate string `xml:"videoFrameRate,attr"`
AudioProfile string `xml:"audioProfile,attr"`
VideoProfile string `xml:"videoProfile,attr"`
Part struct {
Text string `xml:",chardata"`
ID string `xml:"id,attr"`
Key string `xml:"key,attr"`
Duration string `xml:"duration,attr"`
File string `xml:"file,attr"`
Size string `xml:"size,attr"`
AudioProfile string `xml:"audioProfile,attr"`
Container string `xml:"container,attr"`
VideoProfile string `xml:"videoProfile,attr"`
Stream []struct {
Text string `xml:",chardata"`
ID string `xml:"id,attr"`
StreamType string `xml:"streamType,attr"`
Default string `xml:"default,attr"`
Codec string `xml:"codec,attr"`
Index string `xml:"index,attr"`
Bitrate string `xml:"bitrate,attr"`
Language string `xml:"language,attr"`
LanguageCode string `xml:"languageCode,attr"`
BitDepth string `xml:"bitDepth,attr"`
ChromaLocation string `xml:"chromaLocation,attr"`
ChromaSubsampling string `xml:"chromaSubsampling,attr"`
FrameRate string `xml:"frameRate,attr"`
HasScalingMatrix string `xml:"hasScalingMatrix,attr"`
Height string `xml:"height,attr"`
Level string `xml:"level,attr"`
Profile string `xml:"profile,attr"`
RefFrames string `xml:"refFrames,attr"`
ScanType string `xml:"scanType,attr"`
Title string `xml:"title,attr"`
Width string `xml:"width,attr"`
DisplayTitle string `xml:"displayTitle,attr"`
Selected string `xml:"selected,attr"`
Channels string `xml:"channels,attr"`
AudioChannelLayout string `xml:"audioChannelLayout,attr"`
SamplingRate string `xml:"samplingRate,attr"`
Key string `xml:"key,attr"`
} `xml:"Stream"`
} `xml:"Part"`
} `xml:"Media"`
Genre []struct {
Text string `xml:",chardata"`
ID string `xml:"id,attr"`
Filter string `xml:"filter,attr"`
Tag string `xml:"tag,attr"`
} `xml:"Genre"`
Director struct {
Text string `xml:",chardata"`
ID string `xml:"id,attr"`
Filter string `xml:"filter,attr"`
Tag string `xml:"tag,attr"`
} `xml:"Director"`
Writer []struct {
Text string `xml:",chardata"`
ID string `xml:"id,attr"`
Filter string `xml:"filter,attr"`
Tag string `xml:"tag,attr"`
} `xml:"Writer"`
Producer []struct {
Text string `xml:",chardata"`
ID string `xml:"id,attr"`
Filter string `xml:"filter,attr"`
Tag string `xml:"tag,attr"`
} `xml:"Producer"`
Country struct {
Text string `xml:",chardata"`
ID string `xml:"id,attr"`
Filter string `xml:"filter,attr"`
Tag string `xml:"tag,attr"`
} `xml:"Country"`
Role []struct {
Text string `xml:",chardata"`
ID string `xml:"id,attr"`
Filter string `xml:"filter,attr"`
Tag string `xml:"tag,attr"`
Role string `xml:"role,attr"`
Thumb string `xml:"thumb,attr"`
} `xml:"Role"`
} `xml:"Video"`
}

View File

@ -63,139 +63,28 @@ type PlexPyMediaInfo struct {
} `json:"response"` } `json:"response"`
} }
// XMLPlexAPI - This is the XML version of the struct below it. type XMLPlexLibraryType struct {
type XMLPlexAPI struct { XMLName xml.Name `xml:"MediaContainer"`
XMLName xml.Name `xml:"MediaContainer"` Text string `xml:",chardata"`
Text string `xml:",chardata"` Size string `xml:"size,attr"`
Size string `xml:"size,attr"` AllowSync string `xml:"allowSync,attr"`
AllowSync string `xml:"allowSync,attr"` Art string `xml:"art,attr"`
Identifier string `xml:"identifier,attr"` Content string `xml:"content,attr"`
LibrarySectionID string `xml:"librarySectionID,attr"` Identifier string `xml:"identifier,attr"`
LibrarySectionTitle string `xml:"librarySectionTitle,attr"` LibrarySectionID string `xml:"librarySectionID,attr"`
LibrarySectionUUID string `xml:"librarySectionUUID,attr"` MediaTagPrefix string `xml:"mediaTagPrefix,attr"`
MediaTagPrefix string `xml:"mediaTagPrefix,attr"` MediaTagVersion string `xml:"mediaTagVersion,attr"`
MediaTagVersion string `xml:"mediaTagVersion,attr"` Nocache string `xml:"nocache,attr"`
Video struct { Thumb string `xml:"thumb,attr"`
Text string `xml:",chardata"` Title1 string `xml:"title1,attr"`
RatingKey string `xml:"ratingKey,attr"` ViewGroup string `xml:"viewGroup,attr"`
Key string `xml:"key,attr"` ViewMode string `xml:"viewMode,attr"`
GUID string `xml:"guid,attr"` Directory []struct {
LibrarySectionTitle string `xml:"librarySectionTitle,attr"` Text string `xml:",chardata"`
LibrarySectionID string `xml:"librarySectionID,attr"` Key string `xml:"key,attr"`
LibrarySectionKey string `xml:"librarySectionKey,attr"` Title string `xml:"title,attr"`
Studio string `xml:"studio,attr"` Secondary string `xml:"secondary,attr"`
Type string `xml:"type,attr"` Prompt string `xml:"prompt,attr"`
Title string `xml:"title,attr"` Search string `xml:"search,attr"`
ContentRating string `xml:"contentRating,attr"` } `xml:"Directory"`
Summary string `xml:"summary,attr"`
Rating string `xml:"rating,attr"`
AudienceRating string `xml:"audienceRating,attr"`
Year string `xml:"year,attr"`
Tagline string `xml:"tagline,attr"`
Thumb string `xml:"thumb,attr"`
Art string `xml:"art,attr"`
Duration string `xml:"duration,attr"`
OriginallyAvailableAt string `xml:"originallyAvailableAt,attr"`
AddedAt string `xml:"addedAt,attr"`
UpdatedAt string `xml:"updatedAt,attr"`
AudienceRatingImage string `xml:"audienceRatingImage,attr"`
ChapterSource string `xml:"chapterSource,attr"`
PrimaryExtraKey string `xml:"primaryExtraKey,attr"`
RatingImage string `xml:"ratingImage,attr"`
Media struct {
Text string `xml:",chardata"`
VideoResolution string `xml:"videoResolution,attr"`
ID string `xml:"id,attr"`
Duration string `xml:"duration,attr"`
Bitrate string `xml:"bitrate,attr"`
Width string `xml:"width,attr"`
Height string `xml:"height,attr"`
AspectRatio string `xml:"aspectRatio,attr"`
AudioChannels string `xml:"audioChannels,attr"`
AudioCodec string `xml:"audioCodec,attr"`
VideoCodec string `xml:"videoCodec,attr"`
Container string `xml:"container,attr"`
VideoFrameRate string `xml:"videoFrameRate,attr"`
AudioProfile string `xml:"audioProfile,attr"`
VideoProfile string `xml:"videoProfile,attr"`
Part struct {
Text string `xml:",chardata"`
ID string `xml:"id,attr"`
Key string `xml:"key,attr"`
Duration string `xml:"duration,attr"`
File string `xml:"file,attr"`
Size string `xml:"size,attr"`
AudioProfile string `xml:"audioProfile,attr"`
Container string `xml:"container,attr"`
VideoProfile string `xml:"videoProfile,attr"`
Stream []struct {
Text string `xml:",chardata"`
ID string `xml:"id,attr"`
StreamType string `xml:"streamType,attr"`
Default string `xml:"default,attr"`
Codec string `xml:"codec,attr"`
Index string `xml:"index,attr"`
Bitrate string `xml:"bitrate,attr"`
Language string `xml:"language,attr"`
LanguageCode string `xml:"languageCode,attr"`
BitDepth string `xml:"bitDepth,attr"`
ChromaLocation string `xml:"chromaLocation,attr"`
ChromaSubsampling string `xml:"chromaSubsampling,attr"`
FrameRate string `xml:"frameRate,attr"`
HasScalingMatrix string `xml:"hasScalingMatrix,attr"`
Height string `xml:"height,attr"`
Level string `xml:"level,attr"`
Profile string `xml:"profile,attr"`
RefFrames string `xml:"refFrames,attr"`
ScanType string `xml:"scanType,attr"`
Title string `xml:"title,attr"`
Width string `xml:"width,attr"`
DisplayTitle string `xml:"displayTitle,attr"`
Selected string `xml:"selected,attr"`
Channels string `xml:"channels,attr"`
AudioChannelLayout string `xml:"audioChannelLayout,attr"`
SamplingRate string `xml:"samplingRate,attr"`
Key string `xml:"key,attr"`
} `xml:"Stream"`
} `xml:"Part"`
} `xml:"Media"`
Genre []struct {
Text string `xml:",chardata"`
ID string `xml:"id,attr"`
Filter string `xml:"filter,attr"`
Tag string `xml:"tag,attr"`
} `xml:"Genre"`
Director struct {
Text string `xml:",chardata"`
ID string `xml:"id,attr"`
Filter string `xml:"filter,attr"`
Tag string `xml:"tag,attr"`
} `xml:"Director"`
Writer []struct {
Text string `xml:",chardata"`
ID string `xml:"id,attr"`
Filter string `xml:"filter,attr"`
Tag string `xml:"tag,attr"`
} `xml:"Writer"`
Producer []struct {
Text string `xml:",chardata"`
ID string `xml:"id,attr"`
Filter string `xml:"filter,attr"`
Tag string `xml:"tag,attr"`
} `xml:"Producer"`
Country struct {
Text string `xml:",chardata"`
ID string `xml:"id,attr"`
Filter string `xml:"filter,attr"`
Tag string `xml:"tag,attr"`
} `xml:"Country"`
Role []struct {
Text string `xml:",chardata"`
ID string `xml:"id,attr"`
Filter string `xml:"filter,attr"`
Tag string `xml:"tag,attr"`
Role string `xml:"role,attr"`
Thumb string `xml:"thumb,attr"`
} `xml:"Role"`
} `xml:"Video"`
} }