I have a large amount of movies on my home server (4000 circa). The files are all named Title - Subtitle (year).extension
. I would like to create a database (even i
This is a pretty broad question and not really appropriate here (this is more of a tutorial than a quick code question), but here's some strategic advice:
Note that if you really want a database proper, Python again is a nice choice—SQLite is part of the standard install.
Cheers, good luck
UPDATE: Haha, you edited the question whilst I answered. It seems like everything you need is in the file name, but if you're planning on using metadata, here's a caution. Pulling the metadata out of your files can get trickier if they've not all come from the same source; not every media type has the same metadata structure, not every application that creates the files provides the same. So the logic of getting your metadata can get messy.
Is there a reason you can't use extant programs to do this?
Finally you mention getting it on your web-server; once again deferring to Python, the capacity to make the requests of your server you need is also built into the standard package.
Final Update
Can't help you with bash; I'm all thumbs there, and I'm no expert in Python either but your goals are pretty simple. I haven't tested this—there is probably a typo or two, consider it pseudo-code that is mostly python-ready.
# import the standard libraries you'll need
import os # https://docs.python.org/2/library/os.html
import re # https://docs.python.org/2/library/re.html
# this function will walk your directories and output a list of file paths
def getFilePaths(directory):
file_paths = []
for root, directories, files in os.walk(directory):
for filename in files:
filepath = os.path.join(root, filename)
file_paths.append(filepath)
return file_paths
video_file_paths = getFilePaths("path/to/video/library")
output_to_csv = [];
for video_file in video_file_paths:
base_path, fname = os.path.split(video_file)
""" This is a super simple bit of regex that, provided your files are all formatted as
written, will parse out title, subtitle, year and file extension. If your file names
turn out to have more exceptions than you expect (I'd be shocked if not), you may need
to make this part more robust, either with much more savvy regex, or else some conditional
logic—maybe a recursive try... catch loop"""
reg_ex = re.compile("/^(.*) - (.*) \((.*)\)\.(.*)$/");
# now apply the compiled regex to each path
name_components = reg_ex.match(fname);
"""Each output is a row of your CSV file; .join() will join the 4 elements of the regex
match (assuming, again, that your filenames are as clean as you claim), and then add
the basepath, so you should be building, in this loop, a list with elements like:
title, subtitle, year, file_extension, full path"""
output_to_csv.append("{0},{1}".format(name_components.join(","), base_path));
#create the file, making sure the location is writeable
csv_doc = open("my_video_database.csv", "w");
# now join all the rows with line breaks and write the compiled text to the file
csv_doc.write( ouput_to_csv.join("\n") );
#close your new database
csv_doc.close()