]>
src.bluestatic.org Git - armadillo.git/blob - src/tv_rename.go
2 // Armadillo File Manager
3 // Copyright (c) 2011, Robert Sesek <http://www.bluestatic.org>
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.
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.
25 return nil, os
.NewError("Invalid path")
27 // Check that it's inside the jail.
28 var safePath
*string = paths
.Verify(inPath
)
30 return nil, os
.NewError("Path is invalid or outside of jail")
32 // Make sure that the file exists.
33 _
, err
:= os
.Stat(*safePath
)
38 // Parse the filename into its components.
39 _
, fileName
:= path
.Split(*safePath
)
40 parseEpisodeName(fileName
)
45 type episodeInfo
struct {
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 }