def browse(self, entry, dir=myDownloadsDir): self.state = 0 #success self.dir = '' URL = entry.URL if (URL[:4] != 'http') and (URL[:3] != 'ftp'): self.state = -1 #URL does not point to internet file. return ext, size = self.read_file_info(entry) if self.state != 0: return #For the local file name we use the playlist item 'name' field. #But this string may contain invalid characters. Therefore #we strip these invalid characters. We also limit the file #name length to 42 which is the XBMC XBOX limit. localfile = re.sub( '[^\w\s-]', '', entry.name ) # remove characters which are not a letter, digit, white-space, underscore, or dash localfile = re.sub( '\s+', ' ', localfile ) # convert all instances of multiple spaces to single spaces localfile = localfile[:(42 - len(ext))] # limit to 42 characters. localfile = localfile + ext size_MB = float(size) / (1024 * 1024) heading = "Download File: (Size = %.1f MB)" % size_MB browsewnd = CDialogBrowse("CBrowseskin.xml", os.getcwd()) browsewnd.SetFile(dir, localfile, 3, heading) browsewnd.doModal() if browsewnd.state != 0: self.state = -2 #cancel download return self.localfile = browsewnd.dir + browsewnd.filename self.dir = browsewnd.dir #Check if the file already exists if os.path.exists(self.localfile): dialog = xbmcgui.Dialog() if dialog.yesno( "Message", "The destination file already exists, continue?") == False: self.state = -2 #cancel download
def browse(self, entry, dir=myDownloadsDir): self.state = 0 # success self.dir = "" URL = entry.URL if (URL[:4] != "http") and (URL[:3] != "ftp"): self.state = -1 # URL does not point to internet file. return ext, size = self.read_file_info(entry) if self.state != 0: return # For the local file name we use the playlist item 'name' field. # But this string may contain invalid characters. Therefore # we strip these invalid characters. We also limit the file # name length to 42 which is the XBMC XBOX limit. localfile = re.sub( "[^\w\s-]", "", entry.name ) # remove characters which are not a letter, digit, white-space, underscore, or dash localfile = re.sub("\s+", " ", localfile) # convert all instances of multiple spaces to single spaces localfile = localfile[: (42 - len(ext))] # limit to 42 characters. localfile = localfile + ext size_MB = float(size) / (1024 * 1024) heading = "Download File: (Size = %.1f MB)" % size_MB browsewnd = CDialogBrowse("CBrowseskin.xml", os.getcwd()) browsewnd.SetFile(dir, localfile, 3, heading) browsewnd.doModal() if browsewnd.state != 0: self.state = -2 # cancel download return self.localfile = browsewnd.dir + browsewnd.filename self.dir = browsewnd.dir # Check if the file already exists if os.path.exists(self.localfile): dialog = xbmcgui.Dialog() if dialog.yesno("Message", "The destination file already exists, continue?") == False: self.state = -2 # cancel download
def browse(self, entry, dir=myDownloadsDir): self.state = 0 #success self.dir = '' self.processed = False URL = entry.URL if (URL[:4] != 'http') and (URL[:3] != 'ftp'): self.state = -1 #URL does not point to internet file. return if re.search('^http://(\w+\.)?(icefilms|mega(upload|video))\.', URL): size_check_skip = True else: size_check_skip = False if size_check_skip: print("Mega URL; skipping size check") size = 0 urlopener = CURLLoader() result = urlopener.geturl_processor(entry) URL = entry.URL loc_url = URL self.processed = entry.processed self.loc_url = URL url_stripped = re.sub('\?.*$', '', loc_url) # strip GET-method args url_stripped = re.sub('\|.*$', '', url_stripped) # strip header info if any # find extension match = re.search('(\.\w+)$', url_stripped) if match is None: #ext = "" ext = getFileExtension(loc_url) if ext != '': ext = '.' + ext else: ext = match.group(1) else: ext, size = self.read_file_info(entry) url_stripped = re.sub('\?.*$', '', entry.URL) # strip GET-method args url_stripped = re.sub('\&.*$', '', entry.URL) # strip odd GET-method args url_stripped = re.sub('\|.*$', '', url_stripped) # strip header info if any if self.state != 0: return # For the local file name we use the playlist item 'name' field. # But this string may contain invalid characters. Therefore # we strip these invalid characters. We also limit the file # name length to 42 which is the XBMC XBOX limit. if re.search('^Source #', entry.name): localfile = url_stripped[url_stripped.rindex("/") + 1:] else: localfile = re.sub( '[^\w\s-]', '', entry.name ) # remove characters which are not a letter, digit, white-space, underscore, or dash localfile = re.sub( '\s+', ' ', localfile ) # convert all instances of multiple spaces to single spaces localfile = localfile[:(42 - len(ext))] # limit to 42 characters. localfile = localfile + ext if size_check_skip: heading = "Download File" else: size_string, raw_size = self.file_size(size, '') heading = "Download File: (Size = %s)" % size_string if (entry.type == 'playlist') and (localfile.lower().endswith('.plx') == False): localfile += '.plx' #browsewnd = CDialogBrowse("CBrowseskin.xml", os.getcwd()) curdir = addon.getAddonInfo('path') browsewnd = CDialogBrowse("CBrowseskin2.xml", curdir) browsewnd.SetFile(dir, localfile, 3, heading) browsewnd.doModal() if browsewnd.state != 0: self.state = -2 #cancel download return self.localfile = browsewnd.dir + browsewnd.filename self.dir = browsewnd.dir #Check if the file already exists if os.path.exists(self.localfile): dialog = xbmcgui.Dialog() if dialog.yesno( "Message", "The destination file already exists, continue?") == False: self.state = -2 #cancel download
def browse(self, entry, dir=myDownloadsDir): self.state = 0 #success self.dir = '' self.processed=False URL=entry.URL if (URL[:4] != 'http') and (URL[:3] != 'ftp'): self.state = -1 #URL does not point to internet file. return if re.search('^http://(\w+\.)?(icefilms|mega(upload|video))\.', URL): size_check_skip=True else: size_check_skip=False if size_check_skip: print("Mega URL; skipping size check") size=0 urlopener = CURLLoader() result = urlopener.geturl_processor(entry) URL=entry.URL loc_url=URL self.processed=entry.processed self.loc_url=URL url_stripped = re.sub('\?.*$', '', loc_url) # strip GET-method args url_stripped = re.sub('\|.*$', '', url_stripped) # strip header info if any # find extension match = re.search('(\.\w+)$',url_stripped) if match is None: #ext = "" ext = getFileExtension(loc_url) if ext != '': ext = '.' + ext else: ext = match.group(1) else: ext, size = self.read_file_info(entry) url_stripped = re.sub('\?.*$', '', entry.URL) # strip GET-method args url_stripped = re.sub('\&.*$', '', entry.URL) # strip odd GET-method args url_stripped = re.sub('\|.*$', '', url_stripped) # strip header info if any if self.state != 0: return # For the local file name we use the playlist item 'name' field. # But this string may contain invalid characters. Therefore # we strip these invalid characters. We also limit the file # name length to 42 which is the XBMC XBOX limit. if re.search('^Source #', entry.name): localfile=url_stripped[url_stripped.rindex("/")+1:] else: localfile = re.sub('[^\w\s-]', '', entry.name) # remove characters which are not a letter, digit, white-space, underscore, or dash localfile = re.sub('\s+', ' ', localfile) # convert all instances of multiple spaces to single spaces localfile = localfile[:(42-len(ext))] # limit to 42 characters. localfile = localfile + ext if size_check_skip: heading="Download File" else: size_string, raw_size = self.file_size(size,'') heading = "Download File: (Size = %s)" % size_string if (entry.type=='playlist') and (localfile.lower().endswith('.plx')==False): localfile+='.plx' #browsewnd = CDialogBrowse("CBrowseskin.xml", os.getcwd()) curdir = addon.getAddonInfo('path') browsewnd = CDialogBrowse("CBrowseskin2.xml", curdir) browsewnd.SetFile(dir, localfile, 3, heading) browsewnd.doModal() if browsewnd.state != 0: self.state = -2 #cancel download return self.localfile = browsewnd.dir + browsewnd.filename self.dir = browsewnd.dir #Check if the file already exists if os.path.exists(self.localfile): dialog = xbmcgui.Dialog() if dialog.yesno("Message", "The destination file already exists, continue?") == False: self.state = -2 #cancel download
def browse(self, entry, dir=myDownloadsDir): self.state = 0 #success self.dir = '' URL=entry.URL if URL[:4] != 'http': self.state = -1 #URL does not point to internet file. return urlopener = CURLLoader() result = urlopener.urlopen(URL) if result != 0: self.state = -1 #URL does not point to internet file. return loc_url = urlopener.loc_url #Now we try to open the URL. If it does not exist an error is #returned. # try: # oldtimeout=socket.getdefaulttimeout() # socket.setdefaulttimeout(url_open_timeout) # values = { 'User-Agent' : 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'} # req = urllib2.Request(loc_url, None, values) # f = urllib2.urlopen(req) # loc_url=f.geturl() # socket.setdefaulttimeout(oldtimeout) # except IOError: # socket.setdefaulttimeout(oldtimeout) # self.state = -1 #failed to open URL # return #special handing for some URL's pos = URL.find('http://youtube.com/v') #find last 'http' in the URL if pos != -1: ext='.mp4' else: pos = URL.find("flyupload.com") if pos != -1: ext='.avi' else: #strip the file extension pos = loc_url.rfind('.') #find last '.' in the string if pos != -1: ext = loc_url[pos:] #the file extension else: ext = "" #For the local file name we use the playlist item 'name' field. #But this string may contain invalid characters. Therefore #we strip these invalid characters. We also limit the file #name length to 42 which is the XBMC limit. localfile = entry.name.replace('<',"") localfile = localfile.replace('>',"") localfile = localfile.replace('=',"") localfile = localfile.replace('?',"") localfile = localfile.replace(':',"") localfile = localfile.replace(';',"") localfile = localfile.replace('"',"") localfile = localfile.replace('*',"") localfile = localfile.replace('+',"") localfile = localfile.replace(',',"") localfile = localfile.replace('/',"") localfile = localfile.replace('|',"") localfile = localfile[:(42-len(ext))] #limit to 42 characters. localfile = localfile + ext browsewnd = CDialogBrowse() browsewnd.SetFile(dir, localfile, 3) browsewnd.doModal() if browsewnd.state != 0: self.state = -2 #cancel download return self.localfile = browsewnd.dir + browsewnd.filename self.dir = browsewnd.dir #Check if the file already exists if os.path.exists(self.localfile): dialog = xbmcgui.Dialog() if dialog.yesno("Message", "The destination file already exists, continue?") == False: self.state = -2 #cancel download