def move_movie(self, movie, old_path, new_path): ## Update file with new id # Create query query = "UPDATE files \ SET idPath=? \ WHERE idFile=?" # Create values value = new_path.meta, movie.meta # Create a cursor c = self.db.create_cursor() # Launch query c.execute(query, value) ### Move file ## Get filename # Create query query = "SELECT f.strFilename \ FROM files f \ WHERE f.idFile = ?" # Create values value = (movie.meta,) # Launch query c.execute(query, value) # Build result mfile = unicode(c.fetchone()[0]) # mfile = unicode( c.fetchone()[0] ) ## Deal with stacked files if mfile.startswith("stack://"): logging.dbg("Dealing with stacked files") # Update db file with new values query = "UPDATE files \ SET strFilename=? WHERE idFile=?" # Create values strfn = mfile.replace(old_path, new_path) value = strfn, movie.meta # Launch query c.execute(query, value) # Get fanart cache filename and move it srcfn = xbmc.translatePath("special://thumbnails/Video") + "/Fanart/" + xbmc.getCacheThumbName(mfile) dstfn = xbmc.translatePath("special://thumbnails/Video") + "/Fanart/" + xbmc.getCacheThumbName(strfn) try: shutil.move(srcfn, dstfn) logging.dbg("move %s %s" % (srcfn, dstfn)) except IOError, e: logging.err("Error moving %s %s: %s" % (srcfn, dstfn, e)) pass # Create file list with removed whites spaces arround names mfiles = map(lambda x: x.strip(), mfile[8:].split(","))
def move_episode( self, episode, old_path, new_path ): logging.dbg( "moving episode '%s' from '%s' to '%s'" % ( episode, old_path, new_path ) ) # Create a cursor c = self.db.create_cursor() ## Get filename, path, show and episode id and season number # Create query query = "SELECT e.idEpisode, f.strFilename, p.strPath, p.idPath, \ tsle.idShow, e.c12 \ FROM episode e, files f, path p, tvshowlinkepisode tsle \ WHERE e.idFile = f.idFile AND f.idPath = p.idPath \ AND tsle.idEpisode = e.idEpisode AND f.idFile = ?" # Create values value = episode.meta, # Launch query c.execute( query, value ) # Build result res = c.fetchone() eid = res[0] efile = unicode( res[1] ) epath = unicode( res[2] ) eidpath = res[3] eidshow = res[4] season = int( res[5] ) logging.dbg( "filename: '%s'" % ( epath+efile ) ) # Compute new path new_epath = epath.replace( old_path, new_path ) ## Check if new path exists on DB # Create query query = "SELECT p.idPath \ FROM path p \ WHERE p.strPath = ?" # Create values value = new_epath, # Launch query c.execute( query, value ) # Build result res = c.fetchone() if res: new_eidpath = res[0] else: logging.dbg( "Path does not exist on db" ) ## Insert new path on DB # Create query query = "INSERT INTO path \ ( strPath, strContent, strScraper) \ VALUES ( ?, '', '')" # Create values value = new_epath, # Launch query c.execute( query, value ) # Get new id new_eidpath = c.lastrowid logging.dbg( "New path id: %d" %( new_eidpath ) ) # Try to Create new path on system try: os.makedirs( new_epath ) logging.dbg( "Creating directory '%s'" % ( new_epath ) ) except OSError, e: if e.errno == errno.EEXIST: pass else: logging.err( "Error Creating directory '%s': %s" % ( new_epath, e.strerror ) ) return
# replace braces on filename for [[] and []] to be able to use glob root, ext = os.path.splitext(src) srcfn = glob.glob(re.sub(r"(\[|])", r"[\1]", root) + ".*") dstfn = map(lambda x: x.replace(old_path, new_path), srcfn) # Get thumbnail fname srcfn.append(xbmc.translatePath("special://thumbnails/Video") + "/" + thsrc[0] + "/" + thsrc) dstfn.append(xbmc.translatePath("special://thumbnails/Video") + "/" + thdst[0] + "/" + thdst) # Get auto-thumbnail fname srcfn.append(xbmc.translatePath("special://thumbnails/Video") + "/" + thsrc[0] + "/auto-" + thsrc) dstfn.append(xbmc.translatePath("special://thumbnails/Video") + "/" + thdst[0] + "/auto-" + thdst) # get Fanart fname srcfn.append(xbmc.translatePath("special://thumbnails/Video") + "/Fanart/" + thsrc) dstfn.append(xbmc.translatePath("special://thumbnails/Video") + "/Fanart/" + thdst) # Move files for i in range(len(srcfn)): try: shutil.move(srcfn[i], dstfn[i]) logging.dbg("move %s %s" % (srcfn[i], dstfn[i])) except IOError, e: logging.err("Error moving %s %s: %s" % (srcfn[i], dstfn[i], e)) pass # Commit Changes self.db.commit() # Close cursor c.close()
srcfn.append( xbmc.translatePath( 'special://thumbnails/Video' ) + "/" + thsrc[0] + "/" + thsrc ) dstfn.append( xbmc.translatePath( 'special://thumbnails/Video' ) + "/" + thdst[0] + "/" + thdst ) # Get auto-thumbnail fname srcfn.append( xbmc.translatePath( 'special://thumbnails/Video' ) + "/" + thsrc[0] + "/auto-" + thsrc ) dstfn.append( xbmc.translatePath( 'special://thumbnails/Video' ) + "/" + thdst[0] + "/auto-" + thdst ) # Move files for i in range( len( srcfn ) ): try: shutil.move( srcfn[i], dstfn[i] ) logging.dbg( "move %s %s" % ( srcfn[i], dstfn[i] ) ) except IOError, e: logging.err( "Error moving %s %s: %s" % ( srcfn[i], dstfn[i], e ) ) pass # Commit Changes self.db.commit() # Close cursor c.close() def create_new_tvshow( self, old_idshow, old_path, new_path, c ): ## Create new record on tvshow table # Create query query = "INSERT INTO tvshow \ ( c00, c01, c02, c03, c04, c05, c06, c07, c08, c09, c10, c11,\ c12, c13, c14, c15, c16, c17, c18, c19, c20, c21 ) \ SELECT c00, c01, c02, c03, c04, c05, c06, c07, c08, c09, \