def _download( self, src, dst, dst2 ): if (not xbmc.abortRequested): tmpname = xbmc.translatePath('special://profile/addon_data/%s/temp/%s' % ( addonname , xbmc.getCacheThumbName(src) )) lw.log( ['the tmpname is ' + tmpname] ) if xbmcvfs.exists(tmpname): success, loglines = deleteFile( tmpname ) lw.log( loglines ) success, loglines, urldata = imgURL.Get( src, params=self.params ) lw.log( loglines ) if success: success, loglines = writeFile( urldata, tmpname ) lw.log( loglines ) if not success: return False if xbmcvfs.Stat( tmpname ).st_size() > 999: image_ext = getImageType( tmpname ) if not xbmcvfs.exists ( dst + image_ext ): lw.log( ['copying %s to %s' % (tmpname, dst2 + image_ext)] ) xbmcvfs.copy( tmpname, dst2 + image_ext ) lw.log( ['moving %s to %s' % (tmpname, dst + image_ext)] ) xbmcvfs.rename( tmpname, dst + image_ext ) return True else: lw.log( ['image already exists, deleting temporary file'] ) success, loglines = deleteFile( tmpname ) lw.log( loglines ) return False else: success, loglines = deleteFile( tmpname ) lw.log( loglines ) return False
def _trim_downloads( self ): download_max = config.Get( 'download_max' ) if download_max: download_path = os.path.join( self.DATAROOT, 'downloads') download_max = download_max*1024*1024 total_size = 0 filelist = [] for dirpath, dirnames, filenames in os.walk( download_path ): for file in filenames: filepath = os.path.join( dirpath, file ) filelist.append( filepath ) total_size += os.path.getsize( filepath ) if total_size > download_max: lw.log( ['trimming the download folder down to %s bytes' % download_max], 'info' ) try: filelist.sort( key=lambda x: os.path.getmtime( x ) ) except Exception as e: lw.log( ['unexpected error sorting download directory', e], 'info' ) return for file in filelist: if( total_size > download_max ): total_size = total_size - os.path.getsize( file ) success, dloglines = deleteFile( file ) lw.log( dloglines, 'info' ) else: break
def _check_analog( self ): folders, recordings = xbmcvfs.listdir( self.RECORDINGPATH ) if not any(".ts" in s for s in recordings): lw.log( ['no test recording found, servo needs to be triggered'], xbmc.LOGNOTICE ) self._trigger_servo() if self.SENDEMAIL == 'true': self._send_email( [] ) else: lw.log( ['test recording found, need to delete it'], xbmc.LOGNOTICE ) for recording in recordings: success, loglines = deleteFile( os.path.join( self.RECORDINGPATH, recording ) )
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 Download(self): if not self.REMOTEPATH: return False, ['no remote directory path defined, aborting'] loglines = [] dlist = [] try: dirlist = os.listdir(self.REMOTEPATH) except OSError as e: return False, [ 'unable to get directory listing for ' + self.REMOTEPATH, str(e) ] for file in dirlist: if re.search(self.REMOTEFILTER, file): srcpath = os.path.join(self.REMOTEPATH, file) dstpath = os.path.join(self.LOCALDOWNLOADPATH, file) success, cloglines = copyFile(src=srcpath, dst=dstpath) loglines.extend(cloglines) if success: dlist.append(file) if self.DELETEAFTERDOWNLOAD: success, dloglines = deleteFile(srcpath) loglines.extend(dloglines) return dlist, loglines
def _deletePID(): success, loglines = deleteFile(pidfile) lw.log(loglines)
def _nfofix( self, show, nfotemplate ): video_files = [] other_files = [] 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 ) for item in items: fileroot, ext = os.path.splitext( item ) if ext in settings.thumb_exts: for rename_end in settings.rename_ends: if fileroot.endswith( rename_end ): old_thumb = os.path.join( self.FOLDERPATH, item ) item = fileroot[:-len( rename_end )] + settings.thumb_end + ext new_thumb = os.path.join( self.FOLDERPATH, item ) success, loglines = renameFile( old_thumb, new_thumb ) lw.log( loglines ) if item in settings.protected_files: pass elif ext in settings.video_exts : video_files.append( item ) else: other_files.append( item ) lw.log( ['checking files to see if they need to be deleted'] ) lw.log( ['other files:', other_files, 'video files:', video_files] ) for one_file in other_files: match = False other_fileroot, throwaway = os.path.splitext( one_file ) for one_video in video_files: video_root, throwaway = os.path.splitext( one_video ) if (other_fileroot == video_root) or (other_fileroot == video_root + settings.thumb_end): match = True if not match: success, loglines = deleteFile( os.path.join( self.FOLDERPATH, one_file ) ) lw.log( loglines ) ep_info = {} ep_info['airdate'] = time.strftime( '%Y-%m-%d', time.localtime( os.path.getmtime( self.FILEPATH ) ) ) try: ep_info['season'] = self.EVENT_DETAILS["Event"]["Season"] ep_info['episode'] = self.EVENT_DETAILS["Event"]["Episode"] except KeyError: ep_info['season'] = '0' ep_info['episode'] = self._special_epnumber( show, video_files ) try: ep_info['title'] = self.EVENT_DETAILS["Event"]["SubTitle"] except KeyError: ep_info['title'] = ep_info['airdate'] if ep_info['title'] == None: ep_info['title'] = ep_info['airdate'] try: ep_info['description'] = self.EVENT_DETAILS["Event"]["Description"] except KeyError: ep_info['description'] = '' if ep_info['description'] == None: ep_info['description'] = '' lw.log( [ep_info] ) if ep_info['season'] == '0': self._specialseason( show, nfotemplate, ep_info ) else: self._write_nfofile( nfotemplate, ep_info, os.path.splitext( self.FILEPATH )[0] + '.nfo' )
break try: self._set_property("ArtistSlideshow.CleanupComplete", "True") except Exception, e: lw.log( ['unexpected error while setting property.', e] ) def _clean_dir( self, dir_path ): try: dirs, old_files = xbmcvfs.listdir( dir_path ) except Exception, e: lw.log( ['unexpected error while getting directory list', e] ) old_files = [] for old_file in old_files: if not old_file.endswith( '.nfo' ): success, loglines = deleteFile( os.path.join(dir_path, old_file.decode('utf-8')) ) def _clean_text( self, text ): text = re.sub('<a [^>]*>|</a>|<span[^>]*>|</span>','',text) text = re.sub('"','"',text) text = re.sub('&','&',text) text = re.sub('>','>',text) text = re.sub('<','<',text) text = re.sub('User-contributed text is available under the Creative Commons By-SA License and may also be available under the GNU FDL.','',text) text = re.sub('Read more about .* on Last.fm.','',text) return text.strip() def _clear_properties( self ): self.MBID = ''