def make_dest(self) : dirname, basename, extension = Tools.split_path(self.src) pattern = '^\[(?P<time>[0-9]+)\]' \ + '__' \ + '(?P<name>[^[^_]+)' \ + '__' \ + '(?P<vendor>\[.*\])' \ + '(?P<painter>\[.*\])' \ + '(?P<number>\[枚\])' \ + '(?P<conf>\|[0-9]+\|)?$' match = re.match(pattern, basename) if match is not None : #print('Skipping : {0}'.format(basename)) return None basename = re.sub('\(18禁ゲームCG\)', '', basename).strip() basename = re.sub('\(C[0-9]+\)', '', basename).strip() pattern = '\[(?P<time>[0-9]+)\]' match = re.search(pattern, basename) if match is not None : time = match.group('time').strip() else : time = '' basename = re.sub('\[[0-9]+\]', '', basename).strip() basename = re.sub('^[_]+', '', basename) pattern = '^\[(?P<vendor>[^]]+)\]' match = re.match(pattern, basename) if match is not None : vendor = match.group('vendor').strip() basename = basename.replace('[{0}]'.format(vendor), '').strip() else : vendor = '' pattern = '^(?P<name>[^[^(^_]+)' match = re.match(pattern, basename) if match is not None : name = match.group('name').strip() basename = basename.replace(name, '').strip() else : print("Name can't be none : {0}".format(self.src)) return None dest = '[{0}]__{1}__[{2}][][枚]{3}'.format(time, name, vendor, extension) return os.path.join(dirname, dest)
def db_exists(self, name) : dirname, basename, extension = Tools.split_path(name) pattern = '^(?P<vendor>.*)__(?P<id>[^]^[^_]*)__\[n\]__\[s\](\[[0-9]+\])?$' match = re.match(pattern, basename) if match is None : print("Can't parse : {0}".format(name)) return False values = {'product_id':match.group('id')} for hit in self.sql.find(values, 'path') : return True return False
def parse_name(self) : dirname, basename, extension = Tools.split_path(self.src) pattern = '\[+(?P<time>[0-9]*)\]+' \ + '[_]+' \ + '(?P<name>[^_]*)' \ + '[_]+' \ + '\[+(?P<vendor>[^]]*)\]+' \ + '\[+(?P<painter>[^]]*)\]+' \ + '\[+(?P<number>[^]]*)\]+' \ + '(?P<rank>\+)?$' match = re.match(pattern, basename) if match is None : print("Can't paring : {0}".format(self.src)) return None parsed['path'] = self.src parsed['basename'] = basename for feild in ['time', 'name', 'vendor', 'painter', 'number'] : parsed[feild] = match.group(feild).strip() if match.group('rank') is None : parsed['rank'] = 'None' else : parsed['rnak'] = match.group('rank').strip() # rename strip name dest = '[{0}]__{1}__[{2}][{3}][{4}]'.format(\ parsed['time'], parsed['name'], \ parsed['vendor'], parsed['painter'], \ parsed['number']) if parsed['rank'] != 'None' : dest = '{0}{1}'.format(dest, parsed['rank']) dest = '{0}{1}'.format(dest, extension) dest = os.path.join(dirname, dest) if dest != self.src : tool = Tools(self.src, dest) tool.move() return parsed
def parse_name(self) : dirname, basename, extension = Tools.split_path(self.src) pattern = '^(?P<vendor>[^_]*)' \ + '_+' \ + '(?P<id>[^_]*)' \ + '_+' \ + '(?P<name>[^_]*)' \ + '(_+(?P<performer>.*))?' match = re.match(pattern , basename) if match is None : print("Can't parse {0}".format(self.src)) return None parsed = {} parsed['path'] = self.src parsed['basename'] = basename parsed['vendor'] = match.group('vendor').strip() parsed['product_id'] = match.group('id').strip() parsed['name'] = match.group('name').strip() performer = match.group('performer') if performer == None : performer = 'None' else : performer = performer.replace('、', '|').strip() performer = re.sub('[ ]+', '', performer) parsed['performer'] = performer # rename strip name dest = '{0}__{1}__{2}'.format(parsed['vendor'], parsed['product_id'], parsed['name']) if parsed['performer'] != 'None' : dest = '{0}__{1}'.format(dest, parsed['performer'].replace('|', '、')) dest = '{0}{1}'.format(dest, extension.lower()) dest = os.path.join(dirname, dest) if self.src != dest : tool = Tools(self.src, dest) tool.move() return parsed
def make_dest(self) : dirname, basename, extension = Tools.split_path(self.src) dest = None # checking is already renamed pattern = '^(?P<vendor>.*)__(?P<id>[^]^[^_]*)__\[n\]__\[s\](\[[0-9]+\])?$' match = re.match(pattern, basename) if match is not None : dest = match.group('id') else : patterns = [ '^www.av9.cc-(?P<id>.*)$', '^(?P<id>[A-Z]*-[0-9]*)$', '^(?P<id>[0-9]*-[A-Z]*)$', '^(?P<id>\w+)$'] # parsing names for p in patterns : match = re.match(p, basename) if match is not None : dest = match.group('id') break if dest is None : print("Can't parse {0}".format(self.src)) return None vendor = self.find_vendor_name(dest) if vendor is None : vendor = 'xx' dest = re.sub('([-]|[.]|[_])', '', dest) # pattern 'product__id__name__star.mkv dest = '{0}__{1}__[n]__[s]{2}'.format(vendor, dest.upper(), extension.lower()) return os.path.join(dirname, dest)