Python xbmcvfs.mkdir() Examples

The following are 30 code examples of xbmcvfs.mkdir(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module xbmcvfs , or try the search function .
Example #1
Source File: utils.py    From plugin.video.emby with GNU General Public License v3.0 6 votes vote down vote up
def unzip(path, dest, folder=None):

    ''' Unzip file. zipfile module seems to fail on android with badziperror.
    '''
    path = urllib.quote_plus(path)
    root = "zip://" + path + '/'
    
    if folder:

        xbmcvfs.mkdir(os.path.join(dest, folder))
        dest = os.path.join(dest, folder)
        root = get_zip_directory(root, folder)

    dirs, files = xbmcvfs.listdir(root)

    if dirs:
        unzip_recursive(root, dirs, dest)

    for file in files:
        unzip_file(os.path.join(root, file.decode('utf-8')), os.path.join(dest, file.decode('utf-8')))

    LOG.warn("Unzipped %s", path) 
Example #2
Source File: playutils.py    From plugin.video.emby with GNU General Public License v3.0 6 votes vote down vote up
def download_external_subs(cls, src, filename):

        ''' Download external subtitles to temp folder
            to be able to have proper names to streams.
        '''
        temp = xbmc.translatePath("special://profile/addon_data/plugin.video.emby/temp/").decode('utf-8')

        if not xbmcvfs.exists(temp):
            xbmcvfs.mkdir(temp)

        path = os.path.join(temp, filename)

        try:
            response = requests.get(src, stream=True, verify=False)
            response.raise_for_status()
        except Exception as e:
            raise
        else:
            response.encoding = 'utf-8'
            with open(path, 'wb') as f:
                f.write(response.content)
                del response

        return path 
Example #3
Source File: lib_tvshows.py    From plugin.video.openmeta with GNU General Public License v3.0 6 votes vote down vote up
def batch_add_tvshows_to_library(library_folder, show):
	id = show['id']
	showname = text.to_utf8(show['seriesname'])
	show_folder = os.path.join(library_folder, str(id) + '/')
	if not xbmcvfs.exists(show_folder):
		try:
			xbmcvfs.mkdir(show_folder)
		except:
			pass
	nfo_filepath = os.path.join(show_folder, 'tvshow.nfo')
	if not xbmcvfs.exists(nfo_filepath):
		nfo_file = xbmcvfs.File(nfo_filepath, 'w')
		content = 'https://thetvdb.com/?tab=series&id=%s' % str(id)
		nfo_file.write(content)
		nfo_file.close()
	clean_needed = True
	return clean_needed 
Example #4
Source File: speedtest.py    From plugin.program.indigo with GNU General Public License v3.0 6 votes vote down vote up
def make_dir(mypath, dirname):
    ''' Creates sub-directories if they are not found. '''
    import xbmcvfs

    if not xbmcvfs.exists(mypath):
        try:
            xbmcvfs.mkdirs(mypath)
        except:
            xbmcvfs.mkdir(mypath)

    subpath = os.path.join(mypath, dirname)

    if not xbmcvfs.exists(subpath):
        try:
            xbmcvfs.mkdirs(subpath)
        except:
            xbmcvfs.mkdir(subpath)

    return subpath


# ----------------------------------------------------------------------------------------------------------------- 
Example #5
Source File: mystreams.py    From program.plexus with GNU General Public License v2.0 6 votes vote down vote up
def my_streams_menu():
	if not os.path.exists(mystrm_folder): xbmcvfs.mkdir(mystrm_folder)
	files = os.listdir(mystrm_folder)
	if files:
		for fic in files:
			content = readfile(os.path.join(mystrm_folder,fic)).split('|')
			if content:
				if 'acestream://' in content[1] or '.acelive' in content[1] or '.torrent' in content[1]:
					addDir(content[0],content[1],1,content[2],1,False) 
				elif 'sop://' in content[1]:
					addDir(content[0],content[1],2,content[2],1,False) 
				else:
					pass
		xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_UNSORTED)
		xbmcplugin.addSortMethod(int(sys.argv[1]), xbmcplugin.SORT_METHOD_LABEL)
	addDir('[B][COLOR maroon]'+translate(30009)+'[/COLOR][/B]',MainURL,11,os.path.join(addonpath,art,'plus-menu.png'),1,False) 
Example #6
Source File: vfs.py    From plugin.git.browser with GNU General Public License v3.0 6 votes vote down vote up
def mkdir(path, recursive=False):
	if exists(path):
		if debug:
			xbmc.log('******** VFS mkdir notice: %s exists' % path)
		return False
	if recursive:
		try:
			return xbmcvfs.mkdirs(path)
		except Exception as e:
			xbmc.log('******** VFS error: %s' % e)
			return False
	else:
		try:
			return xbmcvfs.mkdir(path)
		except Exception as e:
			xbmc.log('******** VFS error: %s' % e)
			return False 
Example #7
Source File: downloader.py    From plugin.video.mediathekview with MIT License 5 votes vote down vote up
def _download_files(self, film, filmurl, pathname, filename, extension):
        # make sure the destination directory exists
        if not xbmcvfs.exists(pathname):
            xbmcvfs.mkdir(pathname)
        # prepare resulting filenames
        movname = pathname + filename + extension
        srtname = pathname + filename + u'.srt'
        ttmname = pathname + filename + u'.ttml'

        # download video
        progress = KodiProgressDialog()
        progress.create(self.plugin.language(30974), filename + extension)
        # pylint: disable=broad-except
        try:
            progress.update(0)
            mvutils.url_retrieve_vfs(
                filmurl, movname, progress.url_retrieve_hook)
            progress.close()
            self.notifier.show_notification(
                30960, self.plugin.language(30976).format(filmurl))
        except Exception as err:
            progress.close()
            self.plugin.error('Failure downloading {}: {}', filmurl, err)
            self.notifier.show_error(
                30952, self.plugin.language(30975).format(filmurl, err))
            return False

        # download subtitles
        if self.settings.downloadsrt and film.url_sub:
            self.download_subtitle(film, ttmname, srtname, filename)

        return True 
Example #8
Source File: NetflixCommon.py    From plugin.video.netflix with MIT License 5 votes vote down vote up
def __init__(self, plugin_handle, base_url):

        self.addon = Addon()
        self.data_path = xbmc.translatePath(self.addon.getAddonInfo('profile'))
        self.cookie_path = self.data_path + 'COOKIE'
        self.plugin = self.addon.getAddonInfo('name')
        self.verb_log = self.addon.getSetting('logging') == 'true'
        self.plugin_handle = plugin_handle
        self.base_url = base_url
        self.version = self.addon.getAddonInfo('version')

        xbmcvfs.mkdir(path=self.data_path) 
Example #9
Source File: utils.py    From xbmc-addons-chinese with GNU General Public License v2.0 5 votes vote down vote up
def data_dir():
    """"get user data directory of this addon. 
    according to http://wiki.xbmc.org/index.php?title=Add-on_Rules#Requirements_for_scripts_and_plugins
    """
    __datapath__ = xbmc.translatePath( __Addon.getAddonInfo('profile') ).decode('utf-8')
    if not xbmcvfs.exists(__datapath__):
        xbmcvfs.mkdir(__datapath__)
    return __datapath__ 
Example #10
Source File: lib_tvshows.py    From plugin.video.openmeta with GNU General Public License v3.0 5 votes vote down vote up
def library_tv_strm(show, folder, id, season, episode):
	enc_season = ('Season %s' % season).translate(None, '\/:*?"<>|').strip('.')
	folder = os.path.join(folder, enc_season)
	try:
		xbmcvfs.mkdir(folder)
	except:
		pass
	enc_name = '%s - S%02dE%02d.strm' % (text.clean_title(show['seriesname']), season, episode)
	stream = os.path.join(folder, enc_name)
	if not xbmcvfs.exists(stream):
		file = xbmcvfs.File(stream, 'w')
		content = plugin.url_for('tv_play', id=id, season=season, episode=episode)
		file.write(str(content))
		file.close() 
Example #11
Source File: lib_tvshows.py    From plugin.video.openmeta with GNU General Public License v3.0 5 votes vote down vote up
def setup_library(library_folder):
	if library_folder[-1] != '/':
		library_folder += '/'
	if not xbmcvfs.exists(library_folder):
		xbmcvfs.mkdir(library_folder)
		msg = 'Would you like to automatically set OpenMeta as a tv shows source?'
		if plugin.yesno('Library setup', msg):
			try:
				source_thumbnail = plugin.get_media_icon('tv')
				source_name = 'OpenMeta TV shows'
				source_content = "('%s','tvshows','metadata.tvdb.com','',0,0,'<settings version=\"2\"><setting id=\"absolutenumber\" default=\"true\">false</setting><setting id=\"alsoimdb\">true</setting><setting id=\"dvdorder\" default=\"true\">false</setting><setting id=\"fallback\">true</setting><setting id=\"fallbacklanguage\">es</setting><setting id=\"fanart\">true</setting><setting id=\"language\" default=\"true\">en</setting><setting id=\"RatingS\" default=\"true\">TheTVDB</setting><setting id=\"usefallbacklanguage1\">true</setting></settings>',0,0,NULL,NULL)" % library_folder
				tools.add_source(source_name, library_folder, source_content, source_thumbnail)
			except:
				pass
	return xbmc.translatePath(library_folder) 
Example #12
Source File: lib_tvshows.py    From plugin.video.openmeta with GNU General Public License v3.0 5 votes vote down vote up
def auto_tvshows_setup(library_folder):
	if library_folder[-1] != '/': library_folder += '/'
	try:
		xbmcvfs.mkdir(library_folder)
		source_thumbnail = plugin.get_media_icon('tv')
		source_name = 'OpenMeta TV shows'
		source_content = "('%s','tvshows','metadata.tvdb.com','',0,0,'<settings version=\"2\"><setting id=\"absolutenumber\" default=\"true\">false</setting><setting id=\"alsoimdb\">true</setting><setting id=\"dvdorder\" default=\"true\">false</setting><setting id=\"fallback\">true</setting><setting id=\"fallbacklanguage\">es</setting><setting id=\"fanart\">true</setting><setting id=\"language\" default=\"true\">en</setting><setting id=\"RatingS\" default=\"true\">TheTVDB</setting><setting id=\"usefallbacklanguage1\">true</setting></settings>',0,0,NULL,NULL)" % library_folder
		tools.add_source(source_name, library_folder, source_content, source_thumbnail)
		return True
	except:
		False 
Example #13
Source File: lib_movies.py    From plugin.video.openmeta with GNU General Public License v3.0 5 votes vote down vote up
def batch_add_movies_to_library(library_folder, id):
	if id == None:
		return
	changed = False
	movie_folder = os.path.join(library_folder, str(id) + '/')
	if not xbmcvfs.exists(movie_folder):
		try:
			xbmcvfs.mkdir(movie_folder)
		except:
			pass
	nfo_filepath = os.path.join(movie_folder, str(id) + '.nfo')
	if not xbmcvfs.exists(nfo_filepath):
		changed = True
		nfo_file = xbmcvfs.File(nfo_filepath, 'w')
		content = 'https://www.imdb.com/title/%s/' % str(id)
		nfo_file.write(content)
		nfo_file.close()
	strm_filepath = os.path.join(movie_folder, str(id) + '.strm')
	src = 'imdb'
	if not xbmcvfs.exists(strm_filepath):
		changed = True
		strm_file = xbmcvfs.File(strm_filepath, 'w')
		try:
			content = plugin.url_for('movies_play', src=src, id=id)
			strm_file.write(content)
			strm_file.close()
		except:
			pass
	return changed 
Example #14
Source File: lib_movies.py    From plugin.video.openmeta with GNU General Public License v3.0 5 votes vote down vote up
def setup_library(library_folder):
	if library_folder[-1] != '/':
		library_folder += '/'
	if not xbmcvfs.exists(library_folder):
		xbmcvfs.mkdir(library_folder)
		msg = 'Would you like to automatically set OpenMeta as a movies video source?'
		if plugin.yesno('Library setup', msg):
			source_thumbnail = plugin.get_media_icon('movies')
			source_name = 'OpenMeta Movies'
			source_content = "('%s','movies','metadata.themoviedb.org','',2147483647,1,'<settings version=\"2\"><setting id=\"certprefix\" default=\"true\">Rated </setting><setting id=\"fanart\">true</setting><setting id=\"imdbanyway\">true</setting><setting id=\"keeporiginaltitle\" default=\"true\">false</setting><setting id=\"language\" default=\"true\">en</setting><setting id=\"RatingS\" default=\"true\">TMDb</setting><setting id=\"tmdbcertcountry\" default=\"true\">us</setting><setting id=\"trailer\">true</setting></settings>',0,0,NULL,NULL)" % library_folder
			tools.add_source(source_name, library_folder, source_content, source_thumbnail)
	return xbmc.translatePath(library_folder) 
Example #15
Source File: lib_movies.py    From plugin.video.openmeta with GNU General Public License v3.0 5 votes vote down vote up
def auto_movie_setup(library_folder):
	if library_folder[-1] != '/':
		library_folder += '/'
	try:
		xbmcvfs.mkdir(library_folder)
		source_thumbnail = plugin.get_media_icon('movies')
		source_name = 'OpenMeta Movies'
		source_content = "('%s','movies','metadata.themoviedb.org','',2147483647,1,'<settings version=\"2\"><setting id=\"certprefix\" default=\"true\">Rated </setting><setting id=\"fanart\">true</setting><setting id=\"imdbanyway\">true</setting><setting id=\"keeporiginaltitle\" default=\"true\">false</setting><setting id=\"language\" default=\"true\">en</setting><setting id=\"RatingS\" default=\"true\">TMDb</setting><setting id=\"tmdbcertcountry\" default=\"true\">us</setting><setting id=\"trailer\">true</setting></settings>',0,0,NULL,NULL)" % library_folder
		tools.add_source(source_name, library_folder, source_content, source_thumbnail)
		return True
	except:
		False 
Example #16
Source File: utils.py    From plugin.video.bdyun with GNU General Public License v3.0 5 votes vote down vote up
def data_dir():
    """"get user data directory of this addon. 
    according to http://wiki.xbmc.org/index.php?title=Add-on_Rules#Requirements_for_scripts_and_plugins
    """
    __datapath__ = xbmc.translatePath( __Addon.getAddonInfo('profile') ).decode('utf-8')
    if not xbmcvfs.exists(__datapath__):
        xbmcvfs.mkdir(__datapath__)
    return __datapath__ 
Example #17
Source File: Utils.py    From script.toolbox with GNU General Public License v2.0 5 votes vote down vote up
def save_to_file(content, filename, path=""):
    if path == "":
        path = get_browse_dialog()
        if not path:
            return ""
        text_file_path = "%s%s.txt" % (path, filename)
    else:
        if not xbmcvfs.exists(path):
            xbmcvfs.mkdir(path)
        text_file_path = os.path.join(path, filename + ".txt")
    log("save to textfile: " + text_file_path)
    text_file = xbmcvfs.File(text_file_path, "w")
    simplejson.dump(content, text_file)
    text_file.close()
    return True 
Example #18
Source File: kodiutils.py    From plugin.video.vrt.nu with GNU General Public License v3.0 5 votes vote down vote up
def mkdir(path):
    """Create a directory (using xbmcvfs)"""
    from xbmcvfs import mkdir as vfsmkdir
    log(3, "Create directory '{path}'.", path=path)
    return vfsmkdir(path) 
Example #19
Source File: Library.py    From plugin.video.netflix with MIT License 5 votes vote down vote up
def setup_local_netflix_library(self, source):
        """Sets up the basic directories

        Parameters
        ----------
        source : :obj:`dict` of :obj:`str`
            Dicitionary with directories to be created
        """
        for label in source:
            exists = xbmcvfs.exists(
                path=self.nx_common.check_folder_path(source[label]))
            if not exists:
                xbmcvfs.mkdir(source[label]) 
Example #20
Source File: kodiutils.py    From script.module.inputstreamhelper with MIT License 5 votes vote down vote up
def mkdir(path):
    """Create a directory (using xbmcvfs)"""
    from xbmcvfs import mkdir as vfsmkdir
    log(2, "Create directory '{path}'.", path=path)
    return vfsmkdir(from_unicode(path)) 
Example #21
Source File: cloudservice.py    From ownCloud-for-KODI with GNU General Public License v2.0 5 votes vote down vote up
def traverse(self, path, cacheType, folderID, savePublic, level):
        import os
        import xbmcvfs

        xbmcvfs.mkdir(path)

        folders = self.getFolderList(folderID)
        files = self.getMediaList(folderID,cacheType)

        if files:
            for media in files:
                filename = xbmc.translatePath(os.path.join(path, media.title+'.strm'))
                strmFile = open(filename, "w")

                strmFile.write(self.PLUGIN_URL+'?mode=streamURL&url=' + self.FILE_URL+ media.id +'\n')
                strmFile.close()

        if folders and level == 1:
            count = 1
            progress = xbmcgui.DialogProgress()
            progress.create(self.addon.getLocalizedString(30000),self.addon.getLocalizedString(30036),'\n','\n')

            for folder in folders:
                max = len(folders)
                progress.update(count/max*100,self.addon.getLocalizedString(30036),folder.title,'\n')
                self.traverse( path+'/'+folder.title + '/',cacheType,folder.id,savePublic,0)
                count = count + 1

        if folders and level == 0:
            for folder in folders:
                self.traverse( path+'/'+folder.title + '/',cacheType,folder.id,savePublic,0) 
Example #22
Source File: utils.py    From plugin.video.emby with GNU General Public License v3.0 5 votes vote down vote up
def unzip_recursive(path, dirs, dest):

    for directory in dirs:

        dirs_dir = os.path.join(path, directory.decode('utf-8'))
        dest_dir = os.path.join(dest, directory.decode('utf-8'))
        xbmcvfs.mkdir(dest_dir)

        dirs2, files = xbmcvfs.listdir(dirs_dir)

        if dirs2:
            unzip_recursive(dirs_dir, dirs2, dest_dir)

        for file in files:
            unzip_file(os.path.join(dirs_dir, file.decode('utf-8')), os.path.join(dest_dir, file.decode('utf-8'))) 
Example #23
Source File: utils.py    From plugin.video.emby with GNU General Public License v3.0 5 votes vote down vote up
def copy_recursive(path, dirs, dest):

    for directory in dirs:

        dirs_dir = os.path.join(path, directory.decode('utf-8'))
        dest_dir = os.path.join(dest, directory.decode('utf-8'))
        xbmcvfs.mkdir(dest_dir)

        dirs2, files = xbmcvfs.listdir(dirs_dir)

        if dirs2:
            copy_recursive(dirs_dir, dirs2, dest_dir)

        for file in files:
            copy_file(os.path.join(dirs_dir, file.decode('utf-8')), os.path.join(dest_dir, file.decode('utf-8'))) 
Example #24
Source File: views.py    From plugin.video.emby with GNU General Public License v3.0 5 votes vote down vote up
def verify_kodi_defaults():

    ''' Make sure we have the kodi default folder in place.
    '''
    node_path = xbmc.translatePath("special://profile/library/video").decode('utf-8')

    if not xbmcvfs.exists(node_path):
        try:
            shutil.copytree(
                src=xbmc.translatePath("special://xbmc/system/library/video").decode('utf-8'),
                dst=xbmc.translatePath("special://profile/library/video").decode('utf-8'))
        except Exception as error:
            xbmcvfs.mkdir(node_path)

    for index, node in enumerate(['movies', 'tvshows', 'musicvideos']):
        file = os.path.join(node_path, node, "index.xml")

        if xbmcvfs.exists(file):

            try:
                xml = etree.parse(file).getroot()
            except Exception as error:
                LOG.error(error) 

                continue

            xml.set('order', str(17 + index))
            indent(xml)
            write_xml(etree.tostring(xml, 'UTF-8'), file)

    playlist_path = xbmc.translatePath("special://profile/playlists/video").decode('utf-8')

    if not xbmcvfs.exists(playlist_path):
        xbmcvfs.mkdirs(playlist_path) 
Example #25
Source File: client.py    From plugin.video.emby with GNU General Public License v3.0 5 votes vote down vote up
def get_device_id(reset=False):

    ''' Return the device_id if already loaded.
        It will load from emby_guid file. If it's a fresh
        setup, it will generate a new GUID to uniquely
        identify the setup for all users.

        window prop: emby_deviceId
    '''
    client_id = window('emby_deviceId')

    if client_id:
        return client_id

    directory = xbmc.translatePath('special://profile/addon_data/plugin.video.emby/').decode('utf-8')

    if not xbmcvfs.exists(directory):
        xbmcvfs.mkdir(directory)

    emby_guid = os.path.join(directory, "emby_guid")
    file_guid = xbmcvfs.File(emby_guid)
    client_id = file_guid.read()

    if not client_id or reset:
        LOG.info("Generating a new GUID.")

        client_id = str("%012X" % create_id())
        file_guid = xbmcvfs.File(emby_guid, 'w')
        file_guid.write(client_id)

    file_guid.close()

    LOG.info("DeviceId loaded: %s", client_id)
    window('emby_deviceId', value=client_id)

    return client_id 
Example #26
Source File: cache.py    From bugatsinho.github.io with GNU General Public License v3.0 5 votes vote down vote up
def timeout(function, *args, **table):
    try:
        response = None

        f = repr(function)
        f = re.sub('.+\smethod\s|.+function\s|\sat\s.+|\sof\s.+', '', f)

        a = hashlib.md5()
        for i in args: a.update(str(i))
        a = str(a.hexdigest())
    except:
        pass

    try:
        table = table['table']
    except:
        table = 'rel_list'

    try:
        xbmcvfs.mkdir(dataPath)
        dbcon = database.connect(os.path.join(dataPath, 'cache.db'))
        dbcur = dbcon.cursor()
        dbcur.execute("SELECT * FROM %s WHERE func = '%s' AND args = '%s'" % (table, f, a))
        match = dbcur.fetchone()
        return int(match[3])
    except:
        return 
Example #27
Source File: cache.py    From bugatsinho.github.io with GNU General Public License v3.0 5 votes vote down vote up
def timeout(function, *args, **table):
    try:
        response = None

        f = repr(function)
        f = re.sub('.+\smethod\s|.+function\s|\sat\s.+|\sof\s.+', '', f)

        a = hashlib.md5()
        for i in args: a.update(str(i))
        a = str(a.hexdigest())
    except:
        pass

    try:
        table = table['table']
    except:
        table = 'rel_list'

    try:
        xbmcvfs.mkdir(dataPath)
        dbcon = database.connect(os.path.join(dataPath, 'cache.db'))
        dbcur = dbcon.cursor()
        dbcur.execute("SELECT * FROM %s WHERE func = '%s' AND args = '%s'" % (table, f, a))
        match = dbcur.fetchone()
        return int(match[3])
    except:
        return 
Example #28
Source File: mystreams.py    From program.plexus with GNU General Public License v2.0 5 votes vote down vote up
def my_streams_menu():
	if not os.path.exists(mystrm_folder): xbmcvfs.mkdir(mystrm_folder)
	files = os.listdir(mystrm_folder)
	if files:
		for fic in files:
			content = readfile(os.path.join(mystrm_folder,fic)).split('|')
			if content:
				if 'acestream://' in content[1] or '.acelive' in content[1] or '.torrent' in content[1]:
					addDir(content[0],content[1],1,content[2],1,False) 
				elif 'sop://' in content[1]:
					addDir(content[0],content[1],2,content[2],1,False) 
				else:
					pass
	addDir('[B][COLOR maroon]'+translate(30009)+'[/COLOR][/B]',MainURL,11,os.path.join(addonpath,art,'plus-menu.png'),1,False) 
Example #29
Source File: subreddit_lists.py    From plugin.video.sparkle with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self):
        # Initialize the subreddits db file if doesn't exist
        if not os.path.exists(_subreddits_file):
            xbmcvfs.mkdir(_dataPath)
            self.conn = self.initialize_db()
        else:
            self.conn = database.connect(_subreddits_file) 
Example #30
Source File: common.py    From service.vpn.manager with GNU General Public License v2.0 5 votes vote down vote up
def checkDirectory(vpn_provider):
    # Check that the directory for the VPN provider exists
    dir_path = getAddonPath(True, getVPNLocation(vpn_provider))
    if xbmcvfs.exists(dir_path): return True
    infoTrace("common.py", "Creating VPN provider directory " + dir_path)
    try:
        xbmcvfs.mkdir(dir_path)
    except Exception as e:
        errorTrace("common.py", "Couldn't create directory " + dir_path)
        errorTrace("common.py", str(e))
        return False
    return True