Ejemplo n.º 1
0
func (self *Config) LoadConfig() {
	path := filepath.Join(self.DataDir, "config.json")
	file, err := os.Open(path)
	if err != nil {
		mlog.Warning("Config file %s doesn't exist. Creating one ...", path)

		self.Host = ""
		self.Port = "3267"
		self.MediaFolders = make([]string, 0)

		self.Save()

		return
	}
	defer file.Close()

	decoder := json.NewDecoder(file)

	config := Config{}
	err = decoder.Decode(&config)
	if err != nil {
		mlog.Fatalf("Unable to load configuration: %s", err)
	}

	self.Host = config.Host
	self.Port = config.Port
	self.MediaFolders = config.MediaFolders
}
Ejemplo n.º 2
0
func (self *Config) LoadRegex() {
	path := filepath.Join(self.DataDir, "regex.txt")
	content, err := ioutil.ReadFile(path)
	if err != nil {
		mlog.Warning("Regex file %s doesn't exist. Creating one ...", path)

		self.MediaRegexs = []string{
			`(?i)(?P<Resolution>.*?)/(?P<Name>.*?)\s\((?P<Year>\d\d\d\d)\)/(?:.*/)*bdmv/index.(?P<FileType>bdmv)$`,
			`(?i)(?P<Resolution>.*?)/(?P<Name>.*?)\s\((?P<Year>\d\d\d\d)\)/(?:.*/)*.*\.(?P<FileType>iso|img|nrg|mkv|avi|xvid|ts|mpg|dvr-ms|mdf|wmv)$`,
			`(?i)(?P<Resolution>.*?)/(?P<Name>.*?)\s\((?P<Year>\d\d\d\d)\)/(?:.*/)*(?:video_ts|hv000i01)\.(?P<FileType>ifo)$`,
			`(?i)(?P<Name>.*?)\s\((?P<Year>\d\d\d\d)\)/(?:.*/)*bdmv/index.(?P<FileType>bdmv)$`,
			`(?i)(?P<Name>.*?)\s\((?P<Year>\d\d\d\d)\)/(?:.*/)*.*\.(?P<FileType>iso|img|nrg|mkv|avi|xvid|ts|mpg|dvr-ms|mdf|wmv)$`,
			`(?i)(?P<Name>.*?)\s\((?P<Year>\d\d\d\d)\)/(?:.*/)*(?:video_ts|hv000i01)\.(?P<FileType>ifo)$`,
			`(?i)(?P<Name>.*?)\s\((?P<Year>\d\d\d\d)\)\.(?P<FileType>iso|img|nrg|mkv|avi|xvid|ts|mpg|dvr-ms|mdf|wmv)$`,
		}

		var file *os.File
		if file, err = os.Create(path); err != nil {
			mlog.Warning("Unable to write to %s: %s", path, err)
			return
		}
		defer file.Close()

		for _, item := range self.MediaRegexs {
			_, err := file.WriteString(item + "\n")
			if err != nil {
				mlog.Warning("Unable to write to %s: %s", path, err)
				break
			}
		}

		return
	}

	self.MediaRegexs = strings.Split(string(content), "\n")
}