def download_artwork(self, args): print("Searching Artwork...") if not self.api: self.api = API() self.__get_games(self.__get_opl_games(args.opl_drive)) for game in self.games: if game.type != Game.UL: if not game.get("meta"): meta = self.api.get_metadata(game.get("id")) if meta: game.set("meta", meta) self.api.download_artwork(game, args.opl_drive, override=args.force) print("\nReading ul.cfg...") if is_file(args.opl_drive + "/ul.cfg"): ulcfg = ULConfig(os.path.join(args.opl_drive, "ul.cfg")) ulcfg.read() ulcfg.dump() for ulgame in ulcfg.ulgames: game=ULGameImage(ulcfg=ulcfg.ulgames[ulgame]) game.set("meta", self.api.get_metadata(game.get("opl_id"))) game.set("artwork", self.api.get_artwork(game)) game.dump() self.api.download_artwork(game, args.opl_drive, override=args.force) else: print("Skipped. No ul.cfg found on opl_drive.") return True
def __get_opl_games(self, opl_drive, type="DVD"): path = os.path.join(opl_drive, type) games = [] for f in os.listdir(path): filepath = os.path.join(path, f) # Skip parts of ul-files if re.match(r'^ul\..*\.[0-9][1-9]$', f): continue if is_file(filepath): games.append(filepath) return games
def delete(self, args): self.__get_games(self.__get_opl_games(args.opl_drive)) for game in self.games: if game.type != Game.UL: print(game.get('opl_id')) print("\nReading ul.cfg...") if is_file(args.opl_drive + "/ul.cfg"): ulcfg = ULConfig(os.path.join(args.opl_drive, "ul.cfg")) ulcfg.read() for ulgame in ulcfg.ulgames: game=ULGameImage(ulcfg=ulcfg.ulgames[ulgame]) print(game.get('opl_id'))
def to_UL(self, dest_path, force=False): file_part = 0 with open(self.get("filepath"), 'rb') as f: chunk = f.read(ULGameImage.CHUNK_SIZE) while chunk: filename = 'ul.%s.%s.%.2X' % ( self.get("crc32")[2:].upper(), \ self.get("opl_id"), file_part) filepath = path.join(dest_path, filename) if is_file(filepath) and not force: print( "Warn: File '%s' already exists! Use -f to force overwrite." % filename) return 0 print("Writing File '%s'..." % filepath) with open(filepath, 'wb') as outfile: outfile.write(chunk) file_part += 1 chunk = f.read(ULGameImage.CHUNK_SIZE) self.set("parts", file_part) return file_part
def add(self, args): self.api = API() for game in self.__get_games(args.src_file): if not game.get('id'): print("Error while parsing file: %s" % game.get("filepath")) continue if game.get("size") > 4000 or args.ul: print("Forced conversion to UL-Format...") game = game.to_ULGameImage() game.set_metadata(self.api, args.rename) game.dump() # UL Format, when splitting, or whatever... if game.type == Game.UL: print("Adding file in UL-Format...") fileparts = game.to_UL(args.opl_drive, args.force) if fileparts == 0: print("Something went wrong, skipping game '%s'!" % game.get('filename')) continue # Create OPL-Config for Game; read & merge ul.cfg game.ulcfg = ULConfigGame(game=game) cfg = ULConfig(os.path.join(args.opl_drive, "ul.cfg"), \ {game.get("opl_id"): game.ulcfg}) print("Reading ul.cfg...") cfg.read() cfg.dump() print("Writing ul.cfg...") cfg.write() print("Done! - Happy Gaming! :)") # Otherwise copy iso to opl_drive, optimizing the name for OPL else: if game.get("new_filename"): filename = game.get("new_filename") else: filename = game.get("filename") filename += "." + game.get("filetype") filepath = os.path.join(args.opl_drive, "DVD", filename) print("Copy file to " + str(filepath) + ", please wait...") if is_file(filepath) and not args.force: print("Warn: File '%s' already exists! Use -f to force overwriting." % game.get('filename')) print('Skipping game...') continue elif args.force: print("Overwriting forced!") copyfile(game.get("filepath"), filepath) # Finally download artwork print("Downloading Artwork...") self.api.download_artwork(game, args.opl_drive)