Mercurial > codedump
changeset 31:b5cf08125fd5
add deleteautosave.py
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sat, 05 Jun 2021 16:32:38 -0400 |
parents | 6f784c5d13ce |
children | fdbafd3e86d9 |
files | README.md deleteautosave.py getlist.py rename.py |
diffstat | 4 files changed, 42 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/README.md Mon May 31 15:37:50 2021 -0400 +++ b/README.md Sat Jun 05 16:32:38 2021 -0400 @@ -3,6 +3,9 @@ ### decodeurl.cpp pretty self explanatory, compiled with libcurl and the likes +### deleteautosave.py +deletes openmpt autosave files, made cause they cluttered up my modules folder + ### garf.cpp this was a joke program i made when garf wanted to put ads on 1123.best
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/deleteautosave.py Sat Jun 05 16:32:38 2021 -0400 @@ -0,0 +1,6 @@ +import os, sys + +for file in os.listdir("./"): + name = os.path.splitext(file)[0][:-16][-8:] + if name == "AutoSave": + os.remove(file)
--- a/getlist.py Mon May 31 15:37:50 2021 -0400 +++ b/getlist.py Sat Jun 05 16:32:38 2021 -0400 @@ -1,6 +1,8 @@ import urllib.request, json, re, sys -id = input("What is the MyAnimeList ID for your anime?: ") +id = sys.argv[1] +if not 'id' in locals() or not 'id' in globals(): + id = input("What is the MyAnimeList ID for your anime?: ") try: temp = int(id) except: @@ -10,11 +12,11 @@ with urllib.request.urlopen(f"https://api.jikan.moe/v3/anime/{str(id)}/episodes") as url: data = json.loads(url.read().decode()) count = 0 + f = open("list.txt", "w", encoding="utf-8") + f.write("") + f.close() for i in range(len(data["episodes"])): - if count == 0: - f = open("list.txt", "w", encoding="utf-8") - else: - f = open("list.txt", "a", encoding="utf-8") + f = open("list.txt", "a", encoding="utf-8") """ this is really hard to read at first glance so i'll break it down it replaces "?" and ":" with legal counterparts so windows stops screaming
--- a/rename.py Mon May 31 15:37:50 2021 -0400 +++ b/rename.py Sat Jun 05 16:32:38 2021 -0400 @@ -1,14 +1,26 @@ -import os - -titles = open('list.txt', 'r') -titlelist = titles.readlines() -titles.close() - -count = 1 -for line in titlelist: - line = line.rstrip("\n") - if int(count) <= 9: - os.rename(f'Lucky☆Star - 0{count}.mkv', f'Lucky☆Star - 0{count} [{line}].mkv') - else: - os.rename(f'Lucky☆Star - {count}.mkv', f'Lucky☆Star - {count} [{line}].mkv') - count += 1 +import os, sys + +# valid filename: "[title] - [episode number].mkv" +for file in os.listdir("./"): + if file.endswith(".mkv"): + name = file[:-9] + +try: + throwaway = open(f"{name} - 01.mkv", 'rb') +except OSError: + print(f'Could not open "{name} - 01.mkv". Are you sure the file exists?') + sys.exit() +throwaway.close() + +titles = open('list.txt', 'r', encoding='utf-8') +titlelist = titles.readlines() +titles.close() + +count = 1 +for line in titlelist: + line = line.rstrip("\n") + if int(count) <= 9: + os.rename(f'{name} - 0{count}.mkv', f'{name} - 0{count} [{line}].mkv') + else: + os.rename(f'{name} - {count}.mkv', f'{name} - {count} [{line}].mkv') + count += 1