I'm attempting to write a python script that will execute in the current directory, iterate over all files, and then rename each file with a prefixed date (returned from the utility mediainfo and the tagged date of the video). As a result, each video would be renamed with a prefixed date based on the tagged date. (I'll probably use that info later to make symbolic links of each video by year in a folder). Below is my code. It currently renames the files with a 0 and prints out the date. I dont care what it prints out. I want it to rename it with the date. Any help is appreciated.
#!/usr/bin/env python
import os
import shutil
import re
def rename():
dirname = os.getcwd()
for item in os.listdir(dirname):
if os.path.isfile(os.path.join(dirname,item)):
if item.startswith('20'):
print ("Skipping File: %s" % (item))
else:
timeformat = os.system('mediainfo ' + item + " |grep -i tagged|tail -1|awk -F: '{print $2}'|awk '{print $2}'|tail -1")
timeformat = re.sub('0$','', str(timeformat))
newfile = str(timeformat) + str(item)
shutil.move(item, newfile)
def main():
rename()
main()