From e61981efa2ee7c752214b41ee5e44fd8f9cb09dc Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 13 Oct 2012 17:42:09 -0400 Subject: [PATCH] tv_rename.RenameTVEpisode should not return a |*string| just |string|. This also reports errors up from parseResponse(). --- server/server.go | 2 +- server/tv_rename.go | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/server/server.go b/server/server.go index 66c3c3c..da47cc7 100644 --- a/server/server.go +++ b/server/server.go @@ -102,7 +102,7 @@ func serviceHandler(response http.ResponseWriter, request *http.Request) { errorResponse(response, err.Error()) } else { data := map[string]interface{}{ - "path": *newPath, + "path": newPath, "error": 0, } okResponse(response, data) diff --git a/server/tv_rename.go b/server/tv_rename.go index d902f4d..27ab94b 100644 --- a/server/tv_rename.go +++ b/server/tv_rename.go @@ -26,32 +26,33 @@ import ( // Takes a full file path and renames the last path component as if it were a // TV episode. This performs the actual rename as well. -func RenameTVEpisode(inPath string) (*string, error) { +func RenameTVEpisode(inPath string) (string, error) { // Parse the filename into its components. dirName, fileName := path.Split(inPath) info := parseEpisodeName(fileName) if info == nil { - return nil, errors.New("Could not parse file name") + return "", errors.New("Could not parse file name") } // Create the URL and perform the lookup. queryURL := buildURL(info) response, err := performLookup(queryURL) if err != nil { - return nil, err + return "", err } // Parse the response into the fullEpisodeInfo struct. fullInfo := parseResponse(response) + if fullInfo == nil { + return "", errors.New("Error parsing response from TV database service") + } // Create the new path. newName := fmt.Sprintf("%s - %dx%02d - %s", fullInfo.episode.showName, fullInfo.episode.season, fullInfo.episode.episode, fullInfo.episodeName) newName = strings.Replace(newName, "/", "_", -1) newName += path.Ext(fileName) - newPath := path.Join(dirName, newName) - - return &newPath, nil + return path.Join(dirName, newName), nil } type episodeInfo struct { -- 2.43.5