Skip to content

Commit

Permalink
added limit flag for compression and decompression
Browse files Browse the repository at this point in the history
  • Loading branch information
blawar committed Aug 27, 2024
1 parent 0e7ef8c commit 5e88b67
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 2 additions & 0 deletions nut/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
autoUpdateTitleDb = True
allowNoMetadata = True
cdnCacheOnly = False
limit = 0
limitCount = 0

region = None

Expand Down
26 changes: 26 additions & 0 deletions nut/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ def compress(filePath, compressionLevel=19, outputDir=None, copy = False):
f.write(buffer)

newNsp.close()
container.close()

if copy:
os.unlink(tmpFilePath)
Expand Down Expand Up @@ -367,6 +368,12 @@ def compressAll(level=19, copy = False):
if Config.download.fileSizeMin is not None and lastestNsp.getFileSize() < Config.download.fileSizeMin:
continue

if Config.limit:
Config.limitCount += 1

if Config.limitCount > Config.limit:
continue

q.put(lastestNsp.path)

except BaseException as e:
Expand Down Expand Up @@ -455,6 +462,12 @@ def decompressAll():
if Config.download.fileSizeMin is not None and lastestNsz.getFileSize() < Config.download.fileSizeMin:
continue

if Config.limit:
Config.limitCount += 1

if Config.limitCount > Config.limit:
continue

q.put(lastestNsz.path)

except BaseException as e:
Expand Down Expand Up @@ -775,6 +788,13 @@ def _ftpsync(url):
if path[-3:] == 'nsx':
if len(Titles.get(nsp.titleId).getFiles('nsp')) or len(Titles.get(nsp.titleId).getFiles('nsz')):
continue

if Config.limit:
Config.limitCount += 1

if Config.limitCount > Config.limit:
continue

q.put(nsp)
except BaseException as e:
Print.error(str(e))
Expand Down Expand Up @@ -1269,6 +1289,12 @@ def extractNcaMeta(files = []):
if hasCnmt(nsp.titleId, nsp.version):
continue

if Config.limit:
Config.limitCount += 1

if Config.limitCount > Config.limit:
continue

q[path] = nsp
except BaseException:
Print.info('exception: %s' % (path))
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pycryptodome~=3.14.1
pycryptoplus~=0.0.1
pyopenssl~=22.0.0
Flask~=2.0.3
Pillow~=9.0.1
Pillow~=10.4.0
zstandard==0.15.2
future~=0.18.2
asn1~=2.4.2
Expand Down

0 comments on commit 5e88b67

Please sign in to comment.