Skip to content

Commit

Permalink
Add organiser
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenRCE0 committed Sep 25, 2024
1 parent 3b3b5ae commit eb0a6dd
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions organiser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os
import json
from pathlib import Path

def organize_songs(directory):
# Walk through the directory structure
for root, dirs, files in os.walk(directory, topdown=False):
for file in files:
if file.endswith('.pdf'):
# Get the full path of the file
file_path = Path(root) / file
# Extract the song name without extension
song_name = file_path.stem

# Create a new directory with the song name
new_dir = Path(directory) / song_name
new_dir.mkdir(parents=True, exist_ok=True)

# Move the PDF file into the new directory
new_file_path = new_dir / file
file_path.rename(new_file_path)

# Create the info.json file
tags = list(Path(root).relative_to(directory).parts)
info = {
"name": song_name,
"tags": tags
}

# Save info.json in the new song directory
info_path = new_dir / 'info.json'
with open(info_path, 'w') as json_file:
json.dump(info, json_file, indent=4)

# Example usage
# Replace 'some_directory_path' with the path of your directory
organize_songs(input('Enter root path: '))

0 comments on commit eb0a6dd

Please sign in to comment.