Skip to content

Instantly share code, notes, and snippets.

@x1ppy
Last active April 10, 2020 05:07
Show Gist options
  • Save x1ppy/38e6b7fd1ae653036e3887ca720cc17e to your computer and use it in GitHub Desktop.
Save x1ppy/38e6b7fd1ae653036e3887ca720cc17e to your computer and use it in GitHub Desktop.
red-origin to gazelle-origin migration script
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