tv_rename.RenameTVEpisode should not return a |*string| just |string|.
authorRobert Sesek <rsesek@bluestatic.org>
Sat, 13 Oct 2012 21:42:09 +0000 (17:42 -0400)
committerRobert Sesek <rsesek@bluestatic.org>
Sat, 13 Oct 2012 21:42:09 +0000 (17:42 -0400)
This also reports errors up from parseResponse().

server/server.go
server/tv_rename.go

index 66c3c3c6c9ff6ef57d0369ddae93e97e8511fcea..da47cc738fcbbc113a4a6c18a6627132a4c6764d 100644 (file)
@@ -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)
index d902f4dbf5743b637b275d5b197ceb43ebc46608..27ab94b14c7f89ec4341928398b4b5d8926b1916 100644 (file)
@@ -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 {