Untitled

mail@pastecode.io avatar
unknown
python
2 years ago
445 B
6
Indexable
Never
#!/usr/bin/env python3
import os

videos = []

path = '/path/to/movies'

for root, _, _ in os.walk(path):
    splitted = [i for i in root.split('/')[-1].split('.')]
    year = 0
    name = []
    for part in splitted:
        try:
            if int(part):
                year = int(part)
            break
        except:
            name.append(part)
    name = ' '.join(name)
    videos.append({ 'name': name, 'year': year })

print(videos)