Guest User

Untitled

a guest
Mar 10th, 2022
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.46 KB | None | 0 0
  1. import glob
  2. import shutil
  3. import os
  4. import argparse
  5. import re
  6.  
  7. parser = argparse.ArgumentParser()
  8. parser.add_argument('-i', '--inputname', default="regular", help="Specify the png seqeunce prefix", nargs='?')
  9. parser.add_argument('-s', '--startnum', default=0, help="Specify the start number", nargs='?') # nargs='?" is needed to use the default value
  10. parser.add_argument('-e', '--endnum', default=1679, help="Specify the end number", nargs='?')
  11. parser.add_argument('-st', '--step', default=1, help="Specify the frame step (render every step frame)", nargs='?')
  12.  
  13. args = parser.parse_args()
  14. name = args.inputname
  15. startnum = int(args.startnum)
  16. endnum = int(args.endnum)
  17. step = int(args.step)
  18.  
  19. def nums_to_ranges(nums):
  20.   nums = sorted(set(nums))
  21.   gaps = [[s, e] for s, e in zip(nums, nums[1:]) if s+step < e]
  22.   edges = iter(nums[:1] + sum(gaps, []) + nums[-1:])
  23.   return list(zip(edges, edges))
  24.  
  25. def hrs(size, decimal_places=2):
  26.   for unit in ['B','KB','MB','GB','TB']:
  27.     if size < 1024.0:
  28.       break
  29.     size /= 1024.0
  30.   return f"{size:.{decimal_places}f} {unit}"
  31.  
  32. def getranges():
  33.   names = []
  34.   allpngs = glob.glob("*.png")
  35.   if len(allpngs) == 0: # render everything if no pngs were found
  36.     os.chdir(orig_dir)
  37.     return [(self.startnum, self.endnum)]
  38.   for png in allpngs:
  39.     regex = r'(.*)\d{4,}\.png'
  40.     prefix = re.search(regex, png).group(1)
  41.     if prefix not in names:
  42.       names.append(prefix)
  43.  
  44.   all_obtained = []
  45.   all_missing = []
  46.   filesizes = []
  47.  
  48.   for name in names:
  49.     pngs = glob.glob(f"{name}*.png")
  50.     obtained = []
  51.     missing = []
  52.     filesize = 0
  53.     for ii, png in enumerate(pngs):
  54.      
  55.       regex = r'.*(\d{4,})\.png'
  56.       val = int(re.search(regex, png).group(1))
  57.       obtained.append(val)
  58.       # filesize += os.stat(png).st_size
  59.       filesize += os.path.getsize(png)
  60.  
  61.     missing = list(set(range(startnum, endnum+1, step)) - set(obtained))
  62.     all_obtained.append(obtained)
  63.     all_missing.append(missing)
  64.     filesizes.append(hrs(filesize))
  65.  
  66.   res = all(ii == all_obtained[0] for ii in all_obtained) # check if all elements in list are identical
  67.   for name, obtained, missing, size in list(zip(names, all_obtained, all_missing, filesizes)):
  68.     print(name)
  69.     print(f"Obtained: {nums_to_ranges(obtained)} : {size}")
  70.     print(f"Missing:  {nums_to_ranges(missing)}")
  71.     print("-"*80)
  72.  
  73.   if res:
  74.     print("All ranges are identical!")
  75.   else:
  76.     print("Some frames are missing!")
  77.  
  78. getranges()
Advertisement
Add Comment
Please, Sign In to add comment