Last active
April 10, 2020 05:07
-
-
Save x1ppy/38e6b7fd1ae653036e3887ca720cc17e to your computer and use it in GitHub Desktop.
red-origin to gazelle-origin migration script
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
import subprocess | |
import time | |
from pathlib import Path | |
# Replaces origin.txt with origin.yaml in every directory under DIR. | |
# Directory containing albums. | |
# Set this manually. | |
DIR = '~/music' | |
root = Path(DIR).expanduser() | |
for dir in root.iterdir(): | |
print(dir) | |
txt = dir / 'origin.txt' | |
if not txt.exists(): | |
print('...no origin.txt, skipping') | |
continue | |
yaml = dir / 'origin.yaml' | |
if yaml.exists(): | |
print('...origin.yaml exists, skipping') | |
continue | |
with open(txt) as f: | |
lines = f.readlines() | |
for line in lines: | |
if line.startswith('Info hash'): | |
hash = line.split(' ', 1)[1].strip() | |
output = subprocess.check_output('gazelle-origin {0}'.format(hash), shell=True) | |
with open(yaml, 'wb') as f: | |
f.write(output) | |
txt.unlink() | |
time.sleep(1) | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment