def _fixes( self ): found_show = False fixes_dir = os.path.join( p_folderpath, 'data', 'fixes' ) try: shows = os.listdir( fixes_dir ) except: return lw.log( ['there are potential shows to fix'] ) lw.log( shows ) throwaway, show = os.path.split( self.FOLDERPATH ) if show.lower() in map( str.lower, shows ): lw.log( ['matched %s with shows to fix' % show] ) show_fixdir = os.path.join( fixes_dir, show ) found_show = True elif "default" in map( str.lower, shows ): lw.log( ['found default fix, applying to %s' % show] ) show_fixdir = os.path.join( fixes_dir, 'default' ) found_show = True if found_show: nfopath = os.path.join( show_fixdir, 'episode.nfo') jsonpath = os.path.join( show_fixdir, 'episode.json') exists, loglines = checkPath( jsonpath, create=False ) lw.log( loglines ) if exists: self._jsonfix( show, jsonpath ) return exists, loglines = checkPath( nfopath, create=False ) lw.log( loglines ) if exists: self._nfofix( show, nfopath )
def _make_dirs( self ): exists, loglines = checkPath( os.path.join( xbmc.translatePath('special://profile/addon_data/%s' % addonname ).decode('utf-8'), '' ) ) lw.log( loglines ) if self.HASHLISTFOLDER: exists, loglines = checkPath( self.HASHLISTFOLDER ) lw.log( loglines ) if self.MIGRATEFOLDER: exists, loglines = checkPath( self.MIGRATEFOLDER ) lw.log( loglines )
def _make_dirs( self ): exists, loglines = checkPath( os.path.join( self.InitDir, '' ) ) lw.log( loglines ) exists, loglines = checkPath( os.path.join( self.DATAROOT, '' ) ) lw.log( loglines ) thedirs = ['temp', 'ArtistSlideshow', 'ArtistInformation', 'transition', 'merge'] for onedir in thedirs: exists, loglines = checkPath( os.path.join( self.DATAROOT, onedir, '' ) ) lw.log( loglines )
def _nas_copy( self ): nas_fail = True try: lw.log( ['getting list of files from ' + self.FOLDERPATH] ) files = os.listdir( self.FOLDERPATH ) except OSError: lw.log( ['directory %s not found' % self.FOLDERPATH] ) return lw.log( ['found: ', files] ) for onefile in files: nas_fail = False if (os.path.splitext( onefile )[1] in settings.video_exts): filename = onefile org = os.path.join( self.FOLDERPATH, onefile ) dest = os.path.join( settings.nas_mount, self.TYPE, self.SHOW, onefile ) exists, loglines = checkPath( os.path.join( settings.nas_mount, self.TYPE, self.SHOW), create=True ) lw.log( loglines ) try: shutil.move( org, dest ) except shutil.Error, e: lw.log( ['shutil error copying %s to %s' % (org, dest), e] ) nas_fail = True break except Exception, e: lw.log( ['unknown error copying %s to %s' % (org, dest), e] ) nas_fail = True break
def _jsonfix( self, show, jsonpath ): video_files = [] nfo_files = [] ext_dict = {} try: items = os.listdir( self.FOLDERPATH ) except OSError: err_str = 'directory %s not found' % self.FOLDERPATH lw.log( [err_str, 'script stopped'] ) sys.exit( err_str ) jsondata = readFile( jsonpath ) lw.log( ['-----JSON data-----', jsondata[1]] ) episodes = _json.loads( jsondata[1] ) for item in items: fileroot, ext = os.path.splitext( item ) processfilepath = os.path.join( self.FOLDERPATH, item ) last_mod = time.strftime( '%Y-%m-%d', time.localtime( os.path.getmtime( processfilepath ) ) ) if ext in settings.video_exts : for key in episodes: episode = episodes[key] lw.log( ['comparing file last mod of %s with json record date of %s' % (last_mod, episode['record-date'])] ) if last_mod == episode['record-date']: newfilename = '%s.S%sE%s.%s%s' % (show, episode['season'], episode['episode'], episode['title'], ext) newfilepath = os.path.join( self.FOLDERPATH, newfilename ) exists, loglines = checkPath( newfilepath, create=False ) lw.log( loglines ) if not exists: success, loglines = renameFile( processfilepath, newfilepath ) lw.log( loglines ) if success: self._update_db( newfilepath ) else: lw.log( ['%s already has the correct file name' % processfilepath] ) break
def _write_nfofile( self, nfotemplate, ep_info, newnfoname ): newnfopath = os.path.join( self.FOLDERPATH, newnfoname ) replacement_dic = { '[SEASON]': ep_info['season'], '[EPISODE]' : ep_info['episode'], '[TITLE]' : ep_info['title'], '[DESC]' : ep_info['description'], '[AIRDATE]' : ep_info["airdate"]} exists, loglines = checkPath( newnfopath, create=False ) lw.log( loglines ) if exists: success, loglines = deleteFile( newnfopath ) lw.log( loglines ) loglines, fin = readFile( nfotemplate ) lw.log (loglines ) if fin: newnfo = replaceWords( fin, replacement_dic ) success, loglines = writeFile( newnfo, newnfopath ) lw.log( loglines )
def Upload(self, files): if not self.REMOTEPATH: return False, ['no remote directory path defined, aborting'] loglines = [] overall_success = True for file in files: srcpath = os.path.join(self.LOCALDOWNLOADPATH, file) remotefolder = os.path.join(self.REMOTEPATH, self.SOURCEFOLDER) success, cloglines = checkPath(remotefolder) if not success: loglines.extend(cloglines) destpath = os.path.join(remotefolder, file) success, cloglines = copyFile(src=srcpath, dst=destpath) loglines.extend(cloglines) if not success: overall_sucess = False if not overall_success: loglines.append(['one or more files was not copied']) return overall_success, loglines
def _init_vars( self ): self.DATAROOT = os.path.join( p_folderpath, 'data' ) thedirs = ['keys', 'downloads'] for onedir in thedirs: exists, loglines = checkPath( os.path.join( self.DATAROOT, onedir, '' ) ) lw.log( loglines ) settings = {} for source in config.Get( 'sources' ): if source['name'] == self.ARGS.source: settings = source break if not settings: lw.log( ['no matching source for ' + self.AGRGS.source], 'info' ) return False if self.ARGS.filter: settings['override_date'] = self.ARGS.filter settings['dataroot'] = self.DATAROOT try: self.SOURCE = connection_modules.get( settings.get( 'type', 'NOTHING' ), 'NOTHING' ).Connection( config, settings ) except UnboundLocalError as e: lw.log( ['no %s type module for source %s found' % (settings.get( 'type' ), self.ARGS.source)], 'info' ) return False except AttributeError as e: lw.log( ['it looks like you either have no data/settings.py folder or it is malformed', e], 'info' ) return False settings_list = [] for destination in config.Get( 'destinations' ): if destination['name'] in self.ARGS.destination: settings_list.append( destination ) self.DESTINATIONS = [] for settings in settings_list: settings['sourcefolder_default'] = self.ARGS.source settings['override_date'] = self.ARGS.filter settings['dataroot'] = self.DATAROOT self.DESTINATIONS.append( [connection_modules[settings['type']].Connection( config, settings ), settings] ) return True
# * v.1.5.1 # * original exautomation code by Kyle Johnson import atexit, argparse, os, pathlib, random, re, sys, time import resources.config as config from resources.common.xlogger import Logger from resources.common.fileops import checkPath, deleteFile, renameFile, writeFile from resources.common.remotesites import _parse_items import resources.connections, resources.transforms if sys.version_info < (3, 0): from ConfigParser import * else: from configparser import * p_folderpath, p_filename = os.path.split( os.path.realpath(__file__) ) checkPath( os.path.join( p_folderpath, 'data', 'logs', '' ) ) lw = Logger( logfile=os.path.join( p_folderpath, 'data', 'logs', 'logfile.log' ), logconfig='timed', numbackups=config.Get( 'logbackups' ), logdebug=str( config.Get( 'debug' ) ) ) connection_modules = {} for module in resources.connections.__all__: full_plugin = 'resources.connections.' + module __import__( full_plugin ) imp_plugin = sys.modules[ full_plugin ] lw.log( ['loaded plugin ' + module] ) connection_modules[module] = imp_plugin transform_modules = {} for module in resources.transforms.__all__: full_plugin = 'resources.transforms.' + module __import__( full_plugin ) imp_plugin = sys.modules[ full_plugin ]
if artist_start: pDialog.update(int(100*(count/total)), smartUTF8( language(32003) ), smartUTF8( artist_start ) ) if self.ENABLEFUZZYSEARCH == 'true': artist_name = '' lw.log( ['the illegal characters are ', self.ILLEGALCHARS, 'the replacement is ' + self.ILLEGALREPLACE] ) for c in list( self._remove_trailing_dot( artist_start ) ): if c in self.ILLEGALCHARS: artist_name = artist_name + self.ILLEGALREPLACE else: artist_name = artist_name + c else: artist_name = artist_start old_folder = os.path.join( self.ASCACHEFOLDER, folder ) new_folder = os.path.join( self.MIGRATEFOLDER, artist_name, 'extrafanart' ) if self.MIGRATETYPE == 'copy' or self.MIGRATETYPE == 'move': exists, loglines = checkPath( new_folder ) lw.log( loglines ) try: throwaway, files = xbmcvfs.listdir( old_folder ) except OSError: lw.log( ['no directory found: ' + old_folder] ) return except Exception, e: lw.log( ['unexpected error while getting file list', e] ) return lw.log( ['%s %s to %s' % (self.MIGRATETYPE, folder, new_folder)] ) for file in files: old_file = os.path.join(old_folder, file) new_file = os.path.join(new_folder, file) if self.MIGRATETYPE == 'move':
def _set_thedir(self, theartist, dirtype): CacheName = itemHash(theartist) thedir = xbmc.translatePath('special://profile/addon_data/%s/%s/%s/' % ( addonname , dirtype, CacheName, )).decode('utf-8') exists, loglines = checkPath( thedir ) lw.log( loglines ) return thedir