def write_movie(fulltitle, link, settings, parser, path, skip_nfo_exists=False, download_torrent=True): debug('+-------------------------------------------') filename = parser.make_filename() if filename: debug('fulltitle: ' + fulltitle.encode('utf-8')) debug('filename: ' + filename.encode('utf-8')) debug('-------------------------------------------+') from strmwriter import STRMWriter STRMWriter(parser.link()).write(filename, path, parser=parser, settings=settings) from nfowriter import NFOWriter NFOWriter(parser, movie_api=parser.movie_api()).write_movie( filename, path, skip_nfo_exists=skip_nfo_exists) if download_torrent: from downloader import TorrentDownloader TorrentDownloader(parser.link(), settings.torrents_path(), settings).download() return filesystem.relpath(filesystem.join( path, base.make_fullpath(filename, '.strm')), start=settings.base_path()) else: return None
def write(self, filename, path, seasonNumber = None, episodeNumber = None, cutname = None, index = None, parser = None, settings = None): strmFilename = make_fullpath(filename, u'.strm') strmFilename = filesystem.join(path, strmFilename) #------------------------------------------ link = u'plugin://script.media.aggregator/?action=play&torrent=' link += urllib2.quote(self.link.encode('utf-8')) if episodeNumber != None: link += u'&episodeNumber=' + str(episodeNumber - 1) if seasonNumber != None: link += u'&seasonNumber=' + str(seasonNumber) if cutname != None: link += u'&cutName=' + urllib2.quote(cutname) if index != None: link += u'&index=' + str(index) #------------------------------------------ if parser is not None: self.make_alternative(strmFilename, link, parser) # rank = get_rank(parser.get('full_title', ''), parser, settings), # debug('rank: ' + str(rank)) link_with_min_rank = STRMWriterBase.get_link_with_min_rank(strmFilename, settings) if not link_with_min_rank is None: link = link_with_min_rank #------------------------------------------ link += u'&nfo=' + urllib2.quote(make_fullpath(filename, '.nfo').encode('utf-8')) #------------------------------------------ if settings != None: path = filesystem.relpath(path, settings.base_path()) debug(path.encode('utf-8')) link += u'&path=' + urllib2.quote(path.encode('utf-8')) #------------------------------------------ if filesystem.exists(strmFilename): with filesystem.fopen(strmFilename, 'r') as f: old_link = f.read() if old_link.decode('utf-8') == link: return #------------------------------------------ try: with filesystem.fopen(strmFilename, 'w') as f: f.write(link.encode('utf-8')) except IOError: debug('Error write ' + strmFilename.encode('utf-8')) return
def write(self, filename, seasonNumber = None, episodeNumber = None, cutname = None, index = None, parser = None, settings = None): strmFilename = make_fullpath(filename, u'.strm') #------------------------------------------ link = u'plugin://script.media.aggregator/?action=play&torrent=' link += urllib2.quote(self.link.encode('utf-8')) if episodeNumber != None: link += u'&episodeNumber=' + str(episodeNumber - 1) if seasonNumber != None: link += u'&seasonNumber=' + str(seasonNumber) if cutname != None: link += u'&cutName=' + urllib2.quote(cutname) if index != None: link += u'&index=' + str(index) #------------------------------------------ if parser is not None: self.make_alternative(strmFilename, link, parser) # rank = get_rank(parser.get('full_title', ''), parser, settings), # debug('rank: ' + str(rank)) link_with_min_rank = STRMWriterBase.get_link_with_min_rank(strmFilename, settings) if not link_with_min_rank is None: link = link_with_min_rank #------------------------------------------ link += u'&nfo=' + urllib2.quote(make_fullpath(filename, '.nfo').encode('utf-8')) #------------------------------------------ if settings != None: path = filesystem.relpath(filesystem.getcwd(), settings.base_path()) debug(path.encode('utf-8')) link += u'&path=' + urllib2.quote(path.encode('utf-8')) #------------------------------------------ if filesystem.exists(strmFilename): with filesystem.fopen(strmFilename, 'r') as f: old_link = f.read() if old_link.decode('utf-8') == link: return #------------------------------------------ try: with filesystem.fopen(strmFilename, 'w') as f: f.write(link.encode('utf-8')) except IOError: debug('Error write ' + strmFilename.encode('utf-8')) return
def CreateSource( className, sourceName = "", namespace = "", varlist = [], create_output = False, header = "", functions=False, **kwargs ): # Construct the file name if it has not been specified: if sourceName == "": sourceName = className + ".cxx" if not header: header = className + ".h" fullClassName = className if namespace: fullClassName = namespace + "::" + className formdict = { "class":className, "namespace":namespace, "fullClassName":fullClassName } # Determine the relative path of the header using os.path.relpath import filesystem,os include = filesystem.relpath( header, os.path.dirname( sourceName ) ) # Now create all the lines to handle the variables inputVariableConnections = "" outputVariableConnections = "" outputVariableClearing = "" outputVariableFilling = "" mcBlockOpen=False for var in varlist: subs_dict = dict( formdict ) subs_dict['declare']=var.Declaration() subs_dict["commented"]=var.commented subs_dict["typename"]=var.typename subs_dict["cname"]=var.cname subs_dict["name"]=var.name subs_dict["pointer"]=var.pointer if var.mc and not mcBlockOpen: blockCTRL=templates.StartMCBlock mcBlockOpen=True elif not var.mc and mcBlockOpen: blockCTRL=templates.CloseMCBlock mcBlockOpen=False else: blockCTRL="" inputVariableConnections += blockCTRL+"%(commented)sConnectVariable( InTreeName.c_str(), \"%(name)s\", %(cname)s );\n" % subs_dict if create_output: outputVariableConnections += blockCTRL+"%(commented)sDeclareVariable( out_%(cname)s, \"%(name)s\" );\n" % subs_dict outputVariableFilling += blockCTRL+"%(commented)sout_%(cname)s = %(pointer)s%(cname)s;\n" % subs_dict if var.pointer and Is_stl_like( var.typename ): # Not all pointer-accessed types can do this, only stl-vectors outputVariableClearing += "%(commented)sout_%(cname)s.clear();\n" % subs_dict if mcBlockOpen: inputVariableConnections +=templates.CloseMCBlock if create_output: outputVariableConnections +=templates.CloseMCBlock outputVariableFilling +=templates.CloseMCBlock formdict[ "inputVariableConnections" ] = inputVariableConnections formdict[ "outputVariableConnections" ] = outputVariableConnections formdict[ "outputVariableClearing" ] = outputVariableClearing formdict[ "outputVariableFilling" ] = outputVariableFilling formdict[ "functionBodys" ] = "" if functions: formdict[ "functionBodys" ]+=templates.ConnectInputVariables_body%formdict formdict[ "inputVariableConnections" ] = templates.ConnectInputVariables_call if create_output: formdict[ "functionBodys" ]+=templates.DeclareOutputVariables_body%formdict formdict[ "outputVariableConnections" ] = templates.DeclareOutputVariables_call if outputVariableClearing: formdict[ "functionBodys" ]+=templates.ClearOutputVariables_body%formdict formdict[ "outputVariableClearing" ] = templates.ClearOutputVariables_call # Some printouts: print "CreateSource:: Cycle name =", className print "CreateSource:: File name =", sourceName # Create a backup of an already existing source file: Backup( sourceName ) #Construct the contents of the source file: body = templates.source_Body % formdict if namespace: ns_body = templates.namespace % { "namespace":namespace, "body":templates.Indent( body ) } else: ns_body = body full_contents = templates.source_Frame % { "body":ns_body, "fullClassName":fullClassName, "header":include } # Write the source file: output = open( sourceName, "w" ) output.write( full_contents ) output.close() return