Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #=========================================
- def WalkThePath(filepath):
- showname = ""
- # Open the error log file
- efile = open('errors.log',"w")
- lastroot = ''
- elist = []
- currentshow = ''
- currentseason = ''
- for root, dirs, files in os.walk(filepath,topdown=True):
- for file in [f for f in files if f.endswith (('.avi','mkv','mp4','m4v'))]:
- # Combine path and filename to create a single variable.
- if lastroot != root:
- lastroot = root
- if len(elist) > 0:
- Missing(elist,max(elist),currentseason,currentshow)
- elist = []
- currentshow = ''
- currentseason = ''
- fn = join(root,file)
- OriginalFilename,ext = os.path.splitext(file)
- fl = file
- isok,data = GetSeasonEpisode(fl)
- if isok:
- currentshow = showname = data[0]
- currentseason = season = data[1]
- episode = data[2]
- elist.append(int(episode))
- else:
- print(root,file)
- print("No Season/Episode - {0}".format(file))
- efile.writelines('---------------------------\n')
- efile.writelines('{0} has no series/episode informaiton\n'.format(file))
- efile.writelines('---------------------------\n\n')
- #--------------------------------
- #if root
- #--------------------------------
- sqlquery = 'SELECT count(pkid) as rowcount from TvShows where Filename = "%s";' % fl
- try:
- for x in cursor.execute(sqlquery):
- rcntr = x[0]
- if rcntr == 0: # It's not there, so add it
- try:
- sql = 'INSERT INTO TvShows (Series,RootPath,Filename,Season,Episode,tvrageid) VALUES (?,?,?,?,?,?)'
- cursor.execute(sql,(showname,root,fl,season,episode,-1))
- except:
- print("Error")
- print('Filename = {0}\n'.format(file))
- efile.writelines('---------------------------\n')
- efile.writelines('Error writing to database...\n')
- efile.writelines('Filename = {0}\n'.format(file))
- efile.writelines('---------------------------\n\n')
- except:
- print("Error")
- print(root,file)
- # Close the log file
- efile.close
- # End of WalkThePath
- #----------------------------------
- def Missing(eplist,shouldhave,season,showname):
- #----------------------------------
- # eplist is a list
- # shouldhave is an integer
- # season is an integer
- # showname is a string
- #----------------------------------
- temp = set(range(1,shouldhave+1))
- ret = list(temp-set(eplist))
- if len(ret) > 0:
- print('Missing Episodes for {0} Season {1} - {2}'.format(showname,season,ret))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement