Advertisement
Guest User

Untitled

a guest
Apr 7th, 2021
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.45 KB | None | 0 0
  1. import re
  2. from os import listdir, rename, remove, mkdir, path
  3. from os.path import join, isdir
  4.  
  5. BASE_PATH = path.abspath(path.dirname(__file__))
  6. SOURCE_PATH = BASE_PATH + "/new"
  7. CURRENT_PATH = BASE_PATH + "/sorted"
  8.  
  9. # NAME_RE = r"(^\[.+?\])\s*?(.+$)"
  10. NAME_RE = r"(^\[.+?\])\s*?(.+)\s*?(\(.+?\))\s*?(\{.+?})(.+$)"
  11.  
  12.  
  13. if "sorted" not in listdir(BASE_PATH):
  14.     mkdir(join(BASE_PATH, "sorted"))
  15.  
  16. current_artists = [f for f in listdir(CURRENT_PATH) if isdir(join(CURRENT_PATH, f))]
  17. mangas = dict((f, join(SOURCE_PATH, f)) for f in listdir(SOURCE_PATH) if isdir(join(SOURCE_PATH, f)))
  18. artists_name = set([re.match(NAME_RE, name).group(1).strip("[] ") for name in list(mangas.keys())])
  19. print(mangas.keys())
  20.  
  21. for artist_name in artists_name:
  22.     if artist_name not in current_artists:
  23.         mkdir(join(CURRENT_PATH, artist_name))
  24.  
  25.  
  26. for name, manga_path in mangas.items():
  27.     artist_name = re.match(NAME_RE, name).group(1).strip("[] ")
  28.     artist = re.match(NAME_RE, name).group(1)
  29.     manga_name = re.match(NAME_RE, name).group(2).strip()
  30.     comic_name = re.match(NAME_RE, name).group(3)
  31.     tags_ = re.match(NAME_RE, name).group(4)
  32.     ext_type = re.match(NAME_RE, name).group(5)
  33.  
  34.     artist_path = join(CURRENT_PATH, artist_name)
  35.     current_mangas = [f for f in listdir(artist_path) if isdir(join(artist_path, f))]
  36.     if manga_name in current_mangas:
  37.         continue
  38.  
  39.     print(manga_name)
  40.     # rename(manga_path, join(artist_path, manga_name))
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement