fix temp dir overwrite bug when running concurrent tasks
This commit is contained in:
parent
3f5ee7116d
commit
2de40f2d25
39
mur.py
39
mur.py
@ -1,19 +1,20 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
# Sorrow446
|
# Sorrow446
|
||||||
|
|
||||||
import os
|
|
||||||
import re
|
|
||||||
import sys
|
|
||||||
import json
|
|
||||||
import shutil
|
|
||||||
import zipfile
|
|
||||||
import argparse
|
import argparse
|
||||||
|
import img2pdf
|
||||||
|
import json
|
||||||
|
import os
|
||||||
import platform
|
import platform
|
||||||
|
import random
|
||||||
|
import re
|
||||||
|
from requests.exceptions import HTTPError
|
||||||
|
import shutil
|
||||||
|
import sys
|
||||||
|
from tqdm import tqdm
|
||||||
|
import zipfile
|
||||||
|
|
||||||
import api
|
import api
|
||||||
import img2pdf
|
|
||||||
from tqdm import tqdm
|
|
||||||
from requests.exceptions import HTTPError
|
|
||||||
from api.exceptions import IneligibleError
|
from api.exceptions import IneligibleError
|
||||||
|
|
||||||
client = api.Client()
|
client = api.Client()
|
||||||
@ -70,6 +71,12 @@ def parse_args():
|
|||||||
required=False,
|
required=False,
|
||||||
action='store_true'
|
action='store_true'
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'-n', '--nextNum',
|
||||||
|
help="Download n number of issues after given issue",
|
||||||
|
required=False,
|
||||||
|
action='store_true'
|
||||||
|
)
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
def parse_cookies(cd, out_cookies={}):
|
def parse_cookies(cd, out_cookies={}):
|
||||||
@ -146,13 +153,14 @@ def main():
|
|||||||
cd = os.path.dirname(sys.executable)
|
cd = os.path.dirname(sys.executable)
|
||||||
else:
|
else:
|
||||||
cd = os.path.dirname(__file__)
|
cd = os.path.dirname(__file__)
|
||||||
tmp_dir = os.path.join(cd, 'mur_tmp')
|
tmp_dir = os.path.join(cd, f'mur_tmp_{random.randint(1000,9999)}')
|
||||||
dl_dir = os.path.join(cd, 'MUR downloads')
|
dl_dir = os.path.join(cd, 'MUR downloads')
|
||||||
dir_setup(tmp_dir, dl_dir)
|
dir_setup(tmp_dir, dl_dir)
|
||||||
parse_cookies(cd)
|
parse_cookies(cd)
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
tot = len(args.url)
|
tot = len(args.url)
|
||||||
cur = 0
|
cur = 0
|
||||||
|
next_count = 0
|
||||||
urls = [] + args.url
|
urls = [] + args.url
|
||||||
|
|
||||||
for url in urls:
|
for url in urls:
|
||||||
@ -171,10 +179,12 @@ def main():
|
|||||||
id = url
|
id = url
|
||||||
fmt = args.format
|
fmt = args.format
|
||||||
meta = client.get_comic_meta(id)
|
meta = client.get_comic_meta(id)
|
||||||
if args.all:
|
if args.all or (args.nextNum and next_count < args.nextNum):
|
||||||
next_id = client.get_next_comic(id)
|
next_id = client.get_next_comic(id)
|
||||||
if next_id:
|
if next_id:
|
||||||
urls.append(next_id)
|
urls.append(next_id)
|
||||||
|
next_count += 1
|
||||||
|
|
||||||
title = meta['title']
|
title = meta['title']
|
||||||
title_s = sanitize(title)
|
title_s = sanitize(title)
|
||||||
print(str(title) + "\n")
|
print(str(title) + "\n")
|
||||||
@ -190,8 +200,7 @@ def main():
|
|||||||
except IneligibleError as e:
|
except IneligibleError as e:
|
||||||
print(e)
|
print(e)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
#input("Press Enter to continue...")
|
|
||||||
##NEW
|
|
||||||
sourcedir = "tmp_dir"; number_ofdigits = 5; extensions = (".jpg", ".jpeg")
|
sourcedir = "tmp_dir"; number_ofdigits = 5; extensions = (".jpg", ".jpeg")
|
||||||
|
|
||||||
files = os.listdir(tmp_dir)
|
files = os.listdir(tmp_dir)
|
||||||
@ -200,8 +209,7 @@ def main():
|
|||||||
name = item.split("."); zeros = number_ofdigits-len(name[0])
|
name = item.split("."); zeros = number_ofdigits-len(name[0])
|
||||||
newname = str(zeros*"0")+name[0]+"."+name[1]
|
newname = str(zeros*"0")+name[0]+"."+name[1]
|
||||||
shutil.move(tmp_dir+"/"+item, tmp_dir+"/"+newname)
|
shutil.move(tmp_dir+"/"+item, tmp_dir+"/"+newname)
|
||||||
##END NEW
|
|
||||||
#input("Press Enter to continue...")
|
|
||||||
images = [os.path.join(tmp_dir, i) for i in os.listdir(tmp_dir)]
|
images = [os.path.join(tmp_dir, i) for i in os.listdir(tmp_dir)]
|
||||||
print('Converting to {}...'.format(fmt.upper()))
|
print('Converting to {}...'.format(fmt.upper()))
|
||||||
if fmt == 'pdf':
|
if fmt == 'pdf':
|
||||||
@ -214,6 +222,7 @@ def main():
|
|||||||
write_meta(meta_abs, meta)
|
write_meta(meta_abs, meta)
|
||||||
for i in images:
|
for i in images:
|
||||||
os.remove(i)
|
os.remove(i)
|
||||||
|
os.rmdir(tmp_dir)
|
||||||
except HTTPError as e:
|
except HTTPError as e:
|
||||||
err(e, cur, tot)
|
err(e, cur, tot)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user