Last active
November 19, 2020 22:17
-
-
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>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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