I am trying to find file names with ts extensions but for some reason, its failing. The movie files with ts extension is in the movie_path. From the XML, i can get only the filename without extension. Even with the correct filename with ts extension, the check if u'{c}.ts'.format(c=movie_id) not in movie_path: is failing.
import os, re, csv
files = {}
xml_path = '/Users/roradhak/eVision/failed_assets/'
movie_path = os.listdir('/Users/roradhak/eVision/ts_check/')
movie_id = ""
movie_title = ""
content_id = ""
reason_1= ""
reason_2 = ""
xml_details = []
filecount =0
if os.path.exists("/Users/roradhak/eVision/xml_validate.csv"):
os.remove("/Users/roradhak/eVision/xml_validate.csv")
for filename in os.listdir(xml_path):
#if filename.endswith(".xml"):
MOVIE_ERROR = "NO"
TRAILER_ERROR = "NO"
with open(xml_path + filename, "r") as f:
filecount+=1
print "Processed File ", filename, "Filecount:", filecount
check_title=0
for line in f:
if "Content ID" in line:
content_id =re.search('.*>(.+)<',line)
movie_id = content_id.group(1)
print movie_id
if "CDATA" in movie_id:
content_id= re.search('.*<!*\[CDATA\[(.+)\]\]', movie_id)
movie_id = content_id.group(1)
print movie_id
print movie_id
if u'{c}.ts'.format(c=movie_id) not in movie_path:
MOVIE_ERROR = "YES"
reason_1 = "No Movie file"
if "name title=\"Name\"" in line:
if check_title ==0:
title = re.search('.*>(.+)<',line)
movie_title = title.group(1)
check_title = 1
if "CDATA" in movie_title:
movie_title = re.search('.*<!*\[CDATA\[(.+)\]\]', movie_title)
movie_title = movie_title.group(1)
if "\"Has_Trailer\">Y<" in line:
trailer_id = str(content_id.group(1))
trailer_id=trailer_id.replace('M','T',1)
print trailer_id
if u'{c}.ts'.format(c=trailer_id) not in movie_path:
TRAILER_ERROR = "YES"
reason_2 = "No Trailer file"
if MOVIE_ERROR =="YES" or TRAILER_ERROR =="YES":
with open("xml_validate.csv", mode='a') as file:
fieldnames = ['Movie ID', 'Movie Title', 'Comment1', 'Comment2']
writer = csv.DictWriter(file,fieldnames=fieldnames)
writer.writerow({'Movie ID': movie_id, 'Movie Title': movie_title,'Comment1':reason_1,'Comment2':reason_2})
f.close()
i am using this code to search file with specific extension from specific directory in python:
import glob, os
os.chdir(os.getcwd())
for file in glob.glob("*.ts"):
print(file)
you can replace os.getcwd()
with your directory name in which you want to search
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.