Last active
September 1, 2020 02:30
-
-
Save akyag/1205819121757d3eb7ffda062f707bc8 to your computer and use it in GitHub Desktop.
extracting from movie.nfo
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
#! /usr/bin/python | |
import sys | |
import os | |
import re | |
from pathlib import Path | |
info = [] | |
my_dir = "<path>" | |
for item in Path(my_dir).glob('./**/*.nfo'): | |
M = str(item) | |
attributes = [] | |
genre = [] | |
directors = [] | |
codec = [] | |
tags = [] | |
with open(M, "r") as f: | |
for i in f: | |
for j in re.findall("<title>(.+)</title>", i): | |
attributes.append(j) | |
for j in re.findall("<rating>(.+)</rating>", i): | |
attributes.append(j) | |
for j in re.findall("<year>(.+)</year>", i): | |
attributes.append(j) | |
for j in re.findall("<runtime>(.+)</runtime>", i): | |
attributes.append(j) | |
with open(M, "r") as f: | |
for i in f: | |
for j in re.findall("<genre>(.+)</genre>", i): | |
genre.append(j) | |
attributes.append(', '.join(genre)) | |
with open(M, "r") as f: | |
for i in f: | |
for j in re.findall("<director>(.+)</director>", i): | |
directors.append(j) | |
attributes.append(', '.join(directors)) | |
with open(M, "r") as f: | |
for i in f: | |
for j in re.findall("<codec>(.+)</codec>", i): | |
codec.append(j) | |
attributes.append(' / '.join(codec)) | |
with open(M, "r") as f: | |
for i in f: | |
for j in re.findall("<tag>(.+)</tag>", i): | |
tags.append(j) | |
attributes.append(' - '.join(tags)) | |
info.append('_'.join(attributes)) | |
with open("output", "w") as w: | |
for i in info: | |
w.write(i + "\n") | |
for i in info: | |
print (i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment