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 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, \ c10, c11, c12, c13, c14, c15, c16, c17, c18, c19, \ c20, c21 \ FROM tvshow \ WHERE idShow = ? " # Create values value = old_idshow, # Launch query c.execute( query, value ) # Get new id new_idshow = c.lastrowid ## Get old tvshow path and compute the new one # Create query query = "SELECT p.strPath \ FROM tvshowlinkpath tslp, path p \ WHERE tslp.idPath = p.idPath AND tslp.idShow = ?" # Create values value = old_idshow, # Launch query c.execute( query, value ) # Build result old_tspath = unicode( c.fetchone()[0] ) new_tspath = old_tspath.replace( old_path, new_path ) ## Try to Create new path on system try: os.makedirs( new_tspath ) logging.dbg( "Creating directory '%s'" % ( new_tspath ) ) except OSError, e: if e.errno == errno.EEXIST: pass else: logging.dbg( "Error Creating directory '%s': %s" % ( new_tspath, e.strerror ) ) return None, None
#!/usr/bin/env python import sys import xbmc from resources.lib.logging import logging try: from sqlite3 import dbapi2 as sqlite logging.dbg( "Loading sqlite3 as DB engine" ) except: from pysqlite2 import dbapi2 as sqlite logging.dbg("Loading pysqlite2 as DB engine" ) class place( object ): xpos = None ypos = None xsize = None ysize = None class metaStr( unicode ): def __new__(cls,value,meta): obj = unicode.__new__(cls,value) obj.meta = meta return obj class dbMng( object ): def __init__(self):
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(",")) else: mfiles = [old_path + mfile] ## Do the move for mfile in mfiles: # Get movie file and related files (e.g. subtitles files) src = unicode(mfile) logging.dbg("srcfile: %s" % src) dst = mfile.replace(old_path, new_path) logging.dbg("dstfile: %s" % dst) # Get cache file names thsrc = xbmc.getCacheThumbName(src) logging.dbg("srcthumb: %s" % thsrc) thdst = xbmc.getCacheThumbName(dst) logging.dbg("dstthumb: %s" % thdst) # 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
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
thsrc = xbmc.getCacheThumbName( src ) thdst = xbmc.getCacheThumbName( dst ) # Get thumbnail fname srcfn = xbmc.translatePath( 'special://thumbnails/Video' ) + "/" + thsrc[0] + "/" + thsrc dstfn = xbmc.translatePath( 'special://thumbnails/Video' ) + "/" + thdst[0] + "/" + thdst # Copy files try: shutil.copy( srcfn, dstfn ) logging.dbg( "copy %s %s" % ( srcfn, dstfn ) ) except IOError, e: logging.err( "Error copying '%s' to '%s': %s" % ( srcfn, dstfn, e ) ) pass ## Do the move src = epath+efile logging.dbg( "srcfile: %s" % src ) dst = src.replace( old_path, new_path ) logging.dbg( "dstfile: %s" % dst ) # Get cache file names thsrc = xbmc.getCacheThumbName( src ) thdst = xbmc.getCacheThumbName( dst ) # 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