]> src.bluestatic.org Git - armadillo.git/blob - src/tv_rename.go
Try to get the regex to work
[armadillo.git] / src / tv_rename.go
1 //
2 // Armadillo File Manager
3 // Copyright (c) 2011, Robert Sesek <http://www.bluestatic.org>
4 //
5 // This program is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free Software
7 // Foundation, either version 3 of the License, or any later version.
8 //
9
10 package tv_rename
11
12 import (
13 "fmt"
14 "os"
15 "path"
16 "regexp"
17 "./paths"
18 )
19
20 // Takes a full file path and renames the last path component as if it were a
21 // TV episode. This performs the actual rename as well.
22 func RenameEpisode(inPath string) (*string, os.Error) {
23 // Make sure a path was given.
24 if len(inPath) < 1 {
25 return nil, os.NewError("Invalid path")
26 }
27 // Check that it's inside the jail.
28 var safePath *string = paths.Verify(inPath)
29 if safePath == nil {
30 return nil, os.NewError("Path is invalid or outside of jail")
31 }
32 // Make sure that the file exists.
33 _, err := os.Stat(*safePath)
34 if err != nil {
35 return nil, err
36 }
37
38 // Parse the filename into its components.
39 _, fileName := path.Split(*safePath)
40 parseEpisodeName(fileName)
41
42 return safePath, nil
43 }
44
45 type episodeInfo struct {
46 showName string
47 season int
48 episode int
49 }
50
51 // Parses the last path component into a the component structure.
52 func parseEpisodeName(name string) episodeInfo {
53 regex := regexp.MustCompile("^([0-9]+_)?(.+)( |\\.)(S|s)?([0-9]+)[xeXE]([0-9]+)")
54 matches := regex.FindAllString(name, 0)
55 fmt.Printf("matches = %s\n", matches)
56 return episodeInfo{ "", 0, 0 }
57 }