<commit_before>#! /usr/bin/env python

from .version import __version__
from .Utils import (
  get_HOME,
  file_exist,
  get_os_type,
  fix_path,
  makedir
)

SETTINGS_FILENAME = 'settings'
LINUX_FILES_PATH = get_HOME() + '/.youtube-dl-gui'
WINDOWS_FILES_PATH = get_HOME() + '\\youtube-dl-gui'

class OptionsHandler():
  
  settings_abs_path = ''
  
  def __init__(self, statusBarWrite):
    self.statusBarWrite = statusBarWrite
    self.set_settings_path()
    self.load_default()
    self.load_settings()
  
  def load_settings(self):
    if not file_exist(self.get_config_path()):
      makedir(self.get_config_path())
    if file_exist(self.settings_abs_path):
      self.load_from_file()
  
  def load_default(self):
    self.savePath = get_HOME()
    self.videoFormat = "default"
    self.dashAudioFormat = "NO SOUND"
    self.clearDashFiles = False
    self.toAudio = False
    self.keepVideo = False
    self.audioFormat = "mp3"
    self.audioQuality = 5
    self.startTrack = 1
    self.endTrack = 0
    self.maxDownloads = 0
    self.minFileSize = "0"
    self.maxFileSize = "0"
    self.writeSubs = False
    self.writeAllSubs = False
    self.writeAutoSubs = False
    self.embedSubs = False
    self.subsLang = "English"
    self.idAsName = False
    self.ignoreErrors = True
    self.writeDescription = False
    self.writeInfo = False
    self.writeThumbnail = False
    self.retries = 10
    self.userAgent = ""
    self.referer = ""
    self.proxy = ""
    self.username = ""
    self.password = ""
    self.videoPass = ""
    self.updatePath = self.get_config_path()
    self.autoUpdate = False
    self.cmdArgs = ""
    self.enableLog = True
    self.writeTimeToLog = True
  
  def get_config_path(self):
    if get_os_type() == 'nt':
      return WINDOWS_FILES_PATH
    else:
      return LINUX_FILES_PATH
  
  def set_settings_path(self):
    self.settings_abs_path = self.get_config_path()
    self.settings_abs_path = fix_path(self.settings_abs_path)
    self.settings_abs_path += SETTINGS_FILENAME
  
  def read_from_file(self):
    f = open(self.settings_abs_path, 'r')
    options = f.readlines()
    f.close()
    return options
  
  def extract_options(self, options):
    opts = []
    for option in options:
      opt = option.split('=')
      if not len(opt) < 2:
	opts.append(opt[1].rstrip('\n'))
    return opts
  
  def check_settings_file_version(self, options):
    data = options.pop(0).rstrip('\n')
    name, version = data.split('=')
    if name == 'Version' and version == __version__:
      return True
    else:
      return False
  
  def load_from_file(self):
    options = self.read_from_file()
    if self.check_settings_file_version(options):
      opts = self.extract_options(options)
      try:
	self.savePath = opts[0].decode('utf8')
	self.videoFormat = opts[1]
	self.dashAudioFormat = opts[2]
	self.clearDashFiles = opts[3] in ['True']
	self.toAudio = opts[4] in ['True']
	self.keepVideo = opts[5] in ['True']
	self.audioFormat = opts[6]
	self.audioQuality = int(opts[7])
	self.startTrack = int(opts[8])
	self.endTrack = int(opts[9])
	self.maxDownloads = int(opts[10])
	self.minFileSize = opts[11]
	self.maxFileSize = opts[12]
	self.writeSubs = opts[13] in ['True']
	self.writeAllSubs = opts[14] in ['True']
	self.writeAutoSubs = opts[15] in ['True']
	self.embedSubs = opts[16] in ['True']
	self.subsLang = opts[17]
	self.idAsName = opts[18] in ['True']
	self.ignoreErrors = opts[19] in ['True']
	self.writeDescription = opts[20] in ['True']
	self.writeInfo = opts[21] in ['True']
	self.writeThumbnail = opts[22] in ['True']
	self.retries = int(opts[23])
	self.userAgent = opts[24]
	self.referer = opts[25]
	self.proxy = opts[26]
	self.username = opts[27]
	self.updatePath = opts[28].decode('utf8')
	self.autoUpdate = opts[29] in ['True']
	self.cmdArgs = opts[30]
	self.enableLog = opts[31] in ['True']
	self.writeTimeToLog = opts[32] in ['True']
      except:
	self.statusBarWrite('Error while loading settings file. Loading default settings.')
	self.load_default()
    else:
      self.statusBarWrite('Old settings file. Loading default settings.')
      self.load_default()
    
  def save_to_file(self):
    f = open(self.settings_abs_path, 'w')
    f.write('Version='+__version__+'\n')
    f.write('SavePath='+self.savePath.encode('utf-8')+'\n')
    f.write('VideoFormat='+str(self.videoFormat)+'\n')
    f.write('DashAudioFormat='+str(self.dashAudioFormat)+'\n')<commit_msg>Change settings file version check message<commit_after>#! /usr/bin/env python

from .version import __version__
from .Utils import (
  get_HOME,
  file_exist,
  get_os_type,
  fix_path,
  makedir
)

SETTINGS_FILENAME = 'settings'
LINUX_FILES_PATH = get_HOME() + '/.youtube-dl-gui'
WINDOWS_FILES_PATH = get_HOME() + '\\youtube-dl-gui'

class OptionsHandler():
  
  settings_abs_path = ''
  
  def __init__(self, statusBarWrite):
    self.statusBarWrite = statusBarWrite
    self.set_settings_path()
    self.load_default()
    self.load_settings()
  
  def load_settings(self):
    if not file_exist(self.get_config_path()):
      makedir(self.get_config_path())
    if file_exist(self.settings_abs_path):
      self.load_from_file()
  
  def load_default(self):
    self.savePath = get_HOME()
    self.videoFormat = "default"
    self.dashAudioFormat = "NO SOUND"
    self.clearDashFiles = False
    self.toAudio = False
    self.keepVideo = False
    self.audioFormat = "mp3"
    self.audioQuality = 5
    self.startTrack = 1
    self.endTrack = 0
    self.maxDownloads = 0
    self.minFileSize = "0"
    self.maxFileSize = "0"
    self.writeSubs = False
    self.writeAllSubs = False
    self.writeAutoSubs = False
    self.embedSubs = False
    self.subsLang = "English"
    self.idAsName = False
    self.ignoreErrors = True
    self.writeDescription = False
    self.writeInfo = False
    self.writeThumbnail = False
    self.retries = 10
    self.userAgent = ""
    self.referer = ""
    self.proxy = ""
    self.username = ""
    self.password = ""
    self.videoPass = ""
    self.updatePath = self.get_config_path()
    self.autoUpdate = False
    self.cmdArgs = ""
    self.enableLog = True
    self.writeTimeToLog = True
  
  def get_config_path(self):
    if get_os_type() == 'nt':
      return WINDOWS_FILES_PATH
    else:
      return LINUX_FILES_PATH
  
  def set_settings_path(self):
    self.settings_abs_path = self.get_config_path()
    self.settings_abs_path = fix_path(self.settings_abs_path)
    self.settings_abs_path += SETTINGS_FILENAME
  
  def read_from_file(self):
    f = open(self.settings_abs_path, 'r')
    options = f.readlines()
    f.close()
    return options
  
  def extract_options(self, options):
    opts = []
    for option in options:
      opt = option.split('=')
      if not len(opt) < 2:
	opts.append(opt[1].rstrip('\n'))
    return opts
  
  def check_settings_file_version(self, options):
    data = options.pop(0).rstrip('\n')
    name, version = data.split('=')
    if name == 'Version' and version == __version__:
      return True
    else:
      return False
  
  def load_from_file(self):
    options = self.read_from_file()
    if self.check_settings_file_version(options):
      opts = self.extract_options(options)
      try:
	self.savePath = opts[0].decode('utf8')
	self.videoFormat = opts[1]
	self.dashAudioFormat = opts[2]
	self.clearDashFiles = opts[3] in ['True']
	self.toAudio = opts[4] in ['True']
	self.keepVideo = opts[5] in ['True']
	self.audioFormat = opts[6]
	self.audioQuality = int(opts[7])
	self.startTrack = int(opts[8])
	self.endTrack = int(opts[9])
	self.maxDownloads = int(opts[10])
	self.minFileSize = opts[11]
	self.maxFileSize = opts[12]
	self.writeSubs = opts[13] in ['True']
	self.writeAllSubs = opts[14] in ['True']
	self.writeAutoSubs = opts[15] in ['True']
	self.embedSubs = opts[16] in ['True']
	self.subsLang = opts[17]
	self.idAsName = opts[18] in ['True']
	self.ignoreErrors = opts[19] in ['True']
	self.writeDescription = opts[20] in ['True']
	self.writeInfo = opts[21] in ['True']
	self.writeThumbnail = opts[22] in ['True']
	self.retries = int(opts[23])
	self.userAgent = opts[24]
	self.referer = opts[25]
	self.proxy = opts[26]
	self.username = opts[27]
	self.updatePath = opts[28].decode('utf8')
	self.autoUpdate = opts[29] in ['True']
	self.cmdArgs = opts[30]
	self.enableLog = opts[31] in ['True']
	self.writeTimeToLog = opts[32] in ['True']
      except:
	self.statusBarWrite('Error while loading settings file. Loading default settings.')
	self.load_default()
    else:
      self.statusBarWrite('Settings file version problem. Loading default settings.')
      self.load_default()
    
  def save_to_file(self):
    f = open(self.settings_abs_path, 'w')
    f.write('Version='+__version__+'\n')
    f.write('SavePath='+self.savePath.encode('utf-8')+'\n')
    f.write('VideoFormat='+str(self.videoFormat)+'\n')
    f.write('DashAudioFormat='+str(self.dashAudioFormat)+'\n')
{'fraction_non_alphanumeric': 0.1361338874536673, 'fraction_numerical': 0.015949679883185443, 'mean_word_length': 3.5129244804865687, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4870740', 'n_tokens_mistral': 3241, 'n_tokens_neox': 3168, 'n_words': 615}