Skip to content

Commit

Permalink
Switch NZB handling from JSON to XML parsing
Browse files Browse the repository at this point in the history
Replaced JSON with XML for NZB search requests and response parsing to align with updated data format. Removed redundant JSON-specific query parameters and added debug logging for deletion actions.
  • Loading branch information
amaumene committed Jan 16, 2025
1 parent ed50775 commit baf8872
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/clean_watched.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,6 @@ func (app App) removeMedia(IMDB string) error {
if err != nil {
return fmt.Errorf("deleting database entry for %s: %v", IMDB, err)
}
fmt.Printf("Deleted %s\n", media.File)
return nil
}
5 changes: 3 additions & 2 deletions src/newsnab/newsnab.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

func SearchTVShow(TVDB int64, showSeason int64, showEpisode int64, newsNabHost string, newsNabApiKey string) (string, error) {
// Construct the URL with the provided arguments
url := fmt.Sprintf("https://%s/api?apikey=%s&t=tvsearch&tvdbid=%d&season=%d&ep=%d&o=json", newsNabHost, newsNabApiKey, TVDB, showSeason, showEpisode)
url := fmt.Sprintf("https://%s/api?apikey=%s&t=tvsearch&tvdbid=%d&season=%d&ep=%d", newsNabHost, newsNabApiKey, TVDB, showSeason, showEpisode)
// Make the HTTP GET request
resp, err := http.Get(url)
if err != nil {
Expand Down Expand Up @@ -37,7 +37,8 @@ func SearchMovie(IMDB string, newsNabHost string, newsNabApiKey string) (string,
return "", fmt.Errorf("invalid IMDB ID")
}
// Construct the URL with the provided arguments
url := fmt.Sprintf("https://%s/api?apikey=%s&t=movie&imdbid=%s&o=json", newsNabHost, newsNabApiKey, IMDB)
url := fmt.Sprintf("https://%s/api?apikey=%s&t=movie&imdbid=%s", newsNabHost, newsNabApiKey, IMDB)
fmt.Println(url)
// Make the HTTP GET request
resp, err := http.Get(url)
if err != nil {
Expand Down
14 changes: 7 additions & 7 deletions src/nzb.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package main

import (
"bufio"
"encoding/json"
"encoding/xml"
"fmt"
"github.com/amaumene/momenarr/bolthold"
"github.com/amaumene/momenarr/newsnab"
Expand Down Expand Up @@ -47,22 +47,22 @@ func (app App) getNzbFromDB(IMDB string) (NZB, error) {
func (app App) searchNZB(media Media) (newsnab.Feed, error) {
var feed newsnab.Feed
if media.Number > 0 && media.Season > 0 {
jsonResponse, err := newsnab.SearchTVShow(media.TVDB, media.Season, media.Number, app.Config.NewsNabHost, app.Config.NewsNabApiKey)
xmlResponse, err := newsnab.SearchTVShow(media.TVDB, media.Season, media.Number, app.Config.NewsNabHost, app.Config.NewsNabApiKey)
if err != nil {
return feed, fmt.Errorf("searching NZB for episode: %v", err)
}
err = json.Unmarshal([]byte(jsonResponse), &feed)
err = xml.Unmarshal([]byte(xmlResponse), &feed)
if err != nil {
return feed, fmt.Errorf("unmarshalling JSON NZB episode: %v", err)
return feed, fmt.Errorf("unmarshalling XML NZB episode: %v", err)
}
} else {
jsonResponse, err := newsnab.SearchMovie(media.IMDB, app.Config.NewsNabHost, app.Config.NewsNabApiKey)
xmlResponse, err := newsnab.SearchMovie(media.IMDB, app.Config.NewsNabHost, app.Config.NewsNabApiKey)
if err != nil {
return feed, fmt.Errorf("searching NZB for movie: %v", err)
}
err = json.Unmarshal([]byte(jsonResponse), &feed)
err = xml.Unmarshal([]byte(xmlResponse), &feed)
if err != nil {
return feed, fmt.Errorf("unmarshalling JSON NZB movie: %v", err)
return feed, fmt.Errorf("unmarshalling XML NZB movie: %v", err)
}
}
return feed, nil
Expand Down

0 comments on commit baf8872

Please sign in to comment.