Skip to content

Instantly share code, notes, and snippets.

@Awlexus
Last active November 19, 2020 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Awlexus/3f092f942cecad527a1f0feee6e5e898 to your computer and use it in GitHub Desktop.
Save Awlexus/3f092f942cecad527a1f0feee6e5e898 to your computer and use it in GitHub Desktop.
A small script that will search for bandicamp zip files in the search directory and extract them in the given extract them in the extract directory under <artist>/<album>
#!/bin/python3
import sys
import os
import zipfile
import re
search_dir = os.path.expanduser(sys.argv[1])
extract_dir = os.path.expanduser(sys.argv[2])
regex = re.compile('(.+) - (.+)\.zip$')
for x in os.listdir(search_dir):
match = regex.match(x)
if match != None:
zip_file = '/'.join([search_dir, match.group()])
artist = match.group(1)
album = match.group(2)
extract_path = '/'.join([extract_dir, artist, album])
os.makedirs(extract_path, mode=0o755)
with zipfile.ZipFile(zip_file, 'r') as zip_ref:
zip_ref.extractall(extract_path)
os.remove(zip_file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment