本文整理汇总了Python中xbmcvfs.mkdirs函数的典型用法代码示例。如果您正苦于以下问题:Python mkdirs函数的具体用法?Python mkdirs怎么用?Python mkdirs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mkdirs函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self):
run = Prop("run")
if (run) and (time.time() < float(run) + 3):
return
Prop("run", str(time.time()))
Prop("stamp", _stamp)
self.once = True
self.abort = False
self.mesg = None
self.station = None
self.stations = None
self.songs = {}
self.pithos = mypithos.Pithos()
self.player = xbmc.Player()
self.playlist = xbmc.PlayList(xbmc.PLAYLIST_MUSIC)
self.ahead = {}
self.queue = collections.deque()
self.prof = Val("prof")
self.wait = {"auth": 0, "stations": 0, "flush": 0, "scan": 0, "next": 0}
self.silent = xbmc.translatePath("special://home/addons/%s/resources/media/silent.m4a" % _id)
musicbrainzngs.set_useragent("kodi.%s" % _id, Val("version"))
xbmcvfs.mkdirs(xbmc.translatePath(Val("cache")).decode("utf-8"))
xbmcvfs.mkdirs(xbmc.translatePath(Val("library")).decode("utf-8"))
示例2: download_subtitle
def download_subtitle(self, url):
url = BASE_URL + url
(response, srt) = self.__get_url(url)
if not hasattr(response, 'info') or 'Content-Disposition' not in response.info():
return
cd = response.info()['Content-Disposition']
r = re.search('filename="(.*)"', cd)
if r:
filename = r.group(1)
else:
filename = 'addic7ed_subtitle.srt'
filename = re.sub('[^\x00-\x7F]', '', filename)
final_path = os.path.join(kodi.get_setting('subtitle-folder'), filename)
final_path = kodi.translate_path(final_path)
if not xbmcvfs.exists(os.path.dirname(final_path)):
try:
try: xbmcvfs.mkdirs(os.path.dirname(final_path))
except: os.mkdir(os.path.dirname(final_path))
except:
log_utils.log('Failed to create directory %s' % os.path.dirname(final_path), log_utils.LOGERROR)
raise
with open(final_path, 'w') as f:
f.write(srt)
return final_path
示例3: mkdirs
def mkdirs(fle):
FileAccess.log('mkdirs ' + fle)
try:
xbmcvfs.mkdirs(fle)
return True
except:
return False
示例4: add2lib
def add2lib( url, name, infol, img, fanart, year ):
img = 'http://oi62.tinypic.com/dvgj1t.jpg'
addon.log('Add To Library %s , %s, %s' % (name,year,url))
path = xbmc.translatePath( addon.get_setting('movie-folder') )
string = 'plugin://plugin.video.mutttsnutz/?mode=playstream&url='+url+'&name='+name+'&infol='
filename = '%s.strm' % name
path = xbmc.makeLegalFilename( xbmc.translatePath(os.path.join( path, name, filename )))
if not xbmcvfs.exists(os.path.dirname(path)):
try:
try: xbmcvfs.mkdirs(os.path.dirname(path))
except: os.mkdir(os.path.dirname(path))
except:
addon.log('FAILED to create directory')
if xbmcvfs.exists(path):
addon.log( name+' Already in the library' )
notification( addon.get_name()+' allready added', name, img)
return
notification( addon.get_name()+' adding to library', name+' adding to library', img)
strm = xbmcvfs.File(path, 'w')
strm.write(string)
strm.close()
xbmc.executebuiltin("UpdateLibrary(video)")
示例5: writeConfig
def writeConfig(cfile, value=''):
cfgfile = os.path.join(configpath, cfile)
cfglockfile = os.path.join(configpath, cfile + '.lock')
if not xbmcvfs.exists(configpath):
xbmcvfs.mkdirs(configpath)
while True:
if not xbmcvfs.exists(cfglockfile):
l = xbmcvfs.File(cfglockfile, 'w')
l.write(str(time.time()))
l.close()
if value == '':
xbmcvfs.delete(cfgfile)
else:
f = xbmcvfs.File(cfgfile, 'w')
f.write(value.__str__())
f.close()
xbmcvfs.delete(cfglockfile)
xbmcvfs.delete(cfglockfile)
return True
else:
l = xbmcvfs.File(cfglockfile)
modified = float(l.read())
l.close()
if time.time() - modified > 0.1:
xbmcvfs.delete(cfglockfile)
示例6: Download
def Download(ID,lang,filename,key):
URLBASE=__addon__.getSetting("BASEURL")
url=URLBASE+"/he/api/subtitle/download/"+lang+"/?sub_id="+ID+"&v="+ urllib.quote(filename, safe='')+"&key="+key
subtitle_list = []
if xbmcvfs.exists(__temp__):
shutil.rmtree(__temp__)
xbmcvfs.mkdirs(__temp__)
the_page=get_token()
values = {'token' : the_page['token'], 'user': the_page['user'] }
data = urllib.urlencode(values)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
zipdata= response.read()
zipfilename=os.path.join(__temp__,filename)
output = open(zipfilename,'wb')
output.write(zipdata)
output.close()
zfobj = zipfile.ZipFile(zipfilename)
for subname in zfobj.namelist():
if subname.find(".srt") >0:
zfobj.extract(subname,__temp__)
subtitle_list.append(os.path.join(__temp__,subname))
return subtitle_list
示例7: playlist_path
def playlist_path(pcs_file_path, stream):
user_info = get_user_info()
user_name = user_info['username']
user_cookie = user_info['cookie']
user_tokens = user_info['tokens']
if stream:
playlist_data = pcs.get_streaming_playlist(user_cookie, pcs_file_path, stream)
if playlist_data:
raw_dir = os.path.dirname(pcs_file_path)
m = re.search('\/(.*)', raw_dir)
dirname = m.group(1)
basename = os.path.basename(pcs_file_path)
r = re.search('(.*)\.(.*)$', basename)
filename = ''.join([r.group(1), stream, '.m3u8'])
dirpath = os.path.join(utils.data_dir(), user_name, dirname)
if not xbmcvfs.exists(dirpath):
xbmcvfs.mkdirs(dirpath)
filepath = os.path.join(dirpath, filename)
tmpFile = xbmcvfs.File(filepath, 'w')
tmpFile.write(bytearray(playlist_data, 'utf-8'))
return filepath
else:
dialog.notification('', u'无法打开视频,请尝试其他清晰度', xbmcgui.NOTIFICATION_INFO, 6000)
return None
else:
url = pcs.get_download_link(user_cookie, user_tokens, pcs_file_path)
return url
示例8: setThumbnail
def setThumbnail(self, service, url=''):
#load cachePath if not already loaded
if self.cachePath == '':
self.cachePath = service.settings.cachePath
# there is no cache path setting or the setting is unset -- we should assume user does not want to use caching
if not service.settings.cacheThumbnails or self.cachePath == '':
if url == '':
return self.package.file.thumbnail
else:
return url
if url == '':
url = self.package.file.thumbnail
#simply no thumbnail
if url == '':
return ""
#user doesn't want to cache thumbnails
if not service.settings.cacheThumbnails:
return url
cachePath = str(self.cachePath) + str(self.package.file.id) + '/'
cacheFile = str(self.cachePath) + str(self.package.file.id) + '.jpg'
if not xbmcvfs.exists(cachePath):
xbmcvfs.mkdirs(cachePath)
if not xbmcvfs.exists(cacheFile):
cacheFile = service.downloadGeneralFile(url, cacheFile)
if cacheFile is None:
return url
return cacheFile
示例9: sync
def sync(self):
if self._state == self.OBJECT_SKIP:
return
try:
self._state = self.inSync()
if self._state == self.OBJECT_2_DOWNLOAD:
log_debug('Create folder: %s'%self._localPath)
xbmcvfs.mkdirs( self._localPath.encode("utf-8") )
self.updateTimeStamp()
elif self._state == self.OBJECT_2_UPLOAD:
log_error('Can\'t upload folder: %s'%self._localPath)
#TODO Add files if new files found local
#TODO: modify timestamp of dir...
elif self._state == self.OBJECT_2_REMOVE:
log_debug('Remove folder: %s'%self._localPath)
shutil.rmtree(self._localPath)
elif self._state == self.OBJECT_ADD_CHILD:
#TODO
pass
elif self._state == self.OBJECT_IN_SYNC:
pass
else:
log_error('Unknown folder status(%s) for : %s!'%(self._state, self.path))
except Exception, e:
log_error('Exception occurred for folder %s' % self._localPath)
log_error( traceback.format_exc() )
if(self._failure):
#failure happened before... So skip this item in all the next syncs!
self._state = self.OBJECT_SKIP
log_error('Skipping folder in next syncs: %s'% self._localPath)
self._failure = True
示例10: ensure_workdir
def ensure_workdir(workdir):
# Cleanup temp dir, we recommend you download/unzip your subs in temp
# folder and pass that to XBMC to copy and activate
if xbmcvfs.exists(workdir):
removeAll(workdir)
xbmcvfs.mkdirs(workdir)
return xbmcvfs.exists(workdir)
示例11: add_to_library
def add_to_library(video_type, url, title, img, year, imdbnum, movie_num=''):
try: IW_addon.log('Creating .strm for %s %s %s %s %s %s' % (video_type, title, imdbnum, url, img, year))
except: pass
if video_type == 'tvshow':
save_path = IW_addon.get_setting('tvshow-folder')
save_path = xbmc.translatePath(save_path)
strm_string = IW_addon.build_plugin_url(
{'mode': 'NightlyNewsSubMenu','dialog': '1'})
if year: title = '%s (%s)' % (title, year)
filename = filename_from_title(title + ' s1e1', 'movie')
title = re.sub(r'[^\w\-_\. ]', '_', title)
titles = title
final_path = os.path.join(save_path, title, filename)
final_path = xbmc.makeLegalFilename(final_path)
if not xbmcvfs.exists(os.path.dirname(final_path)):
try:
try: xbmcvfs.mkdirs(os.path.dirname(final_path))
except: os.path.mkdir(os.path.dirname(final_path))
except Exception, e:
try: IW_addon.log('Failed to create directory %s' % final_path)
except: pass
try:
file_desc = xbmcvfs.File(final_path, 'w')
file_desc.write(strm_string)
file_desc.close()
except Exception, e:
IW_addon.log('Failed to create .strm file: %s\n%s' % (final_path, e))
示例12: _make_dir
def _make_dir(self, path, dir):
subpath = os.path.join(path, dir)
try:
if not xbmcvfs.exists(subpath): xbmcvfs.mkdirs(subpath)
except:
if not os.path.exists(subpath): os.makedirs(subpath)
return subpath
示例13: setSRT
def setSRT(self, service):
if not constants.CONST.SRT:
return
#load cachePath if not already loaded
if not service.settings.cacheSRT and self.cachePath == '':
self.cachePath = service.settings.cachePath
#only makes sense to cache SRT if the cachePath exists
if service.settings.cacheSRT and self.cachePath != '':
cachePath = str(self.cachePath) + '/' + str(self.package.file.id)+'/'
if not xbmcvfs.exists(cachePath):
xbmcvfs.mkdirs(cachePath)
srt = service.getSRT(self.package)
if srt:
for file in srt:
if not xbmcvfs.exists(str(cachePath) + str(file[0])):
service.downloadGeneralFile(file[1], str(cachePath) + str(file[0]))
self.srt.append(str(cachePath) + str(file[0]))
#fetch SRT URLs but we won't cache the files
else:
srt = service.getSRT(self.package)
if srt:
for file in srt:
self.srt.append(str(file[1]) + '|' + service.getHeadersEncoded())
示例14: saveTorrent
def saveTorrent(self, torrentUrl):
#if not xbmcvfs.exists(torrentUrl) or re.match("^http.+$", torrentUrl):
if re.match("^magnet\:.+$", torrentUrl):
self.magnetLink = torrentUrl
self.magnetToTorrent(torrentUrl)
self.magnetLink = None
return self.torrentFile
else:
if not xbmcvfs.exists(self.torrentFilesPath): xbmcvfs.mkdirs(self.torrentFilesPath)
torrentFile = os.path.join(self.torrentFilesPath, self.md5(torrentUrl) + '.torrent')
try:
if not re.match("^[htps]+?://.+$|^://.+$", torrentUrl):
log('xbmcvfs.File for %s' % torrentUrl)
content = xbmcvfs.File(torrentUrl, "rb").read()
else:
log('request for %s' % torrentUrl)
content = self.makeRequest(torrentUrl)
localFile = xbmcvfs.File(torrentFile, "w+b")
localFile.write(content)
localFile.close()
except Exception, e:
log('Unable to rename torrent file from %s to %s in AnteoLoader::saveTorrent. Exception: %s' %
(torrentUrl, torrentFile, str(e)))
return
示例15: setCC
def setCC(self, service):
if not constants.CONST.CC:
return
#load cachePath if not already loaded
if self.cachePath == '':
self.cachePath = service.settings.cachePath
# there is no cache path setting or the setting is unset -- we should assume user does not want to use caching
# CC files need to be cached (so they can be converted to SRT) -- don't do anything if we don't have the cachePath
if self.cachePath == '':
return
else:
cachePath = str(self.cachePath) + '/' + str(self.package.file.id)+'/'
if not xbmcvfs.exists(cachePath):
xbmcvfs.mkdirs(cachePath)
cachePath = str(cachePath) + str(self.package.file.id)
cc = service.getTTS(self.package.file.srtURL)
if cc:
for file in cc:
if not xbmcvfs.exists(cachePath + str(file[0])):
service.downloadTTS(file[1], str(cachePath) + str(file[0]))
self.srt.append(str(cachePath) + str(file[0]))