Пример #1
0
def route_download_public(url,ofolder,fname,xcimode="Untrimmed",zmode="Compressed",file=None):
	if (fname.endswith('.xcz') or fname.endswith('.nsz')) and zmode=="Uncompressed":	
		decompress(url,ofolder,file=file)		
	if fname.endswith('.xci') and xcimode=="Trimmed":
		Public.download(url,ofolder,trimm=True,file=file)	
	elif fname.endswith('.xci') and xcimode=="Supertrimmed":		
		supertrimm(url,ofolder,file=file)
	else:
		Public.download(url,ofolder,trimm=False,file=file)			
Пример #2
0
def delete_from_drive(filepath=None, url=None, lkID=None, TD=None):
    try:
        if filepath == None and url == None and lkID == None:
            return False
        if TD == None:
            remote = location(route=filepath)
        else:
            remote = location(route=filepath, TD_Name=TD)
        if lkID != None:
            file_id = lkID
        elif url != None:
            file_id, is_download_link = Public.parse_url(url)
        elif filepath != None:
            file_id = remote.ID

        file = remote.drive_service.files().get(fileId=file_id,
                                                fields='parents').execute()
        # print(file.get('parents'))
        previous_parents = ",".join(file.get('parents'))
        file = remote.drive_service.files().update(
            fileId=file_id,
            removeParents=previous_parents,
            fields='name,id,parents').execute()
        print("{} was removed from drive".format(file['name']))
    except IOError as e:
        print(e, file=sys.stderr)
Пример #3
0
def add_to_drive(url=None, ID=None, filepath=None, makecopy=False, TD=None):
    # print(url);print(ID);print(filepath);print(makecopy);print(TD);
    try:
        if ID == None and url == None:
            return False
        if filepath == None:
            return False
        if ID != None:
            file_id = ID
        else:
            file_id, is_download_link = Public.parse_url(url)
        if TD == None:
            remote = location(route=filepath)
        else:
            remote = location(route=filepath, TD_Name=TD)
        # remote=location(route=filepath)
        drive = remote.drivename
        FolderID = remote.ID
        if makecopy != True:
            file = remote.drive_service.files().update(
                fileId=file_id, addParents=FolderID,
                fields='id,parents,name').execute()
            name = file.get('name')
        else:
            result = remote.drive_service.files().get(
                fileId=file_id, fields="name,mimeType").execute()
            name = result['name']
            newfile = {'name': name, 'parents': [FolderID]}

            file = remote.drive_service.files().copy(
                fileId=file_id, body=newfile, fields='id, parents').execute()
        print("{} was added to drive".format(name))
    except IOError as e:
        print(e, file=sys.stderr)
    return name
Пример #4
0
def get_cnmt_data(path=None,TD=None,filter=None,target=None,file=None):
	if path==None and file==None:
		return False
	if file != None:
		remote=file
		type='file'
		remote.rewind()
	elif path.startswith('http'):
		url=path
		remote=Public.location(url);readable=remote.readable
		if not readable:
			return False			
		type='file'
	else:		
		if path=='pick':
			account=Private.token_picker()
			TD=Private.TD_picker(account)
			return
		test=path.split(".+")
		if TD=='pick':
			TD=Private.TD_picker(path)		
		if len(test)>1 or path.endswith('/') or path.endswith('\\'):
			type="folder"
		else:	
			ID,name,type,size,md5,remote=Private.get_Data(path,TD=TD,Print=False)
	if type!='file':
		# print('Path is a folder')
		Private.folderpicker(path,TD=TD,filter=filter,mode='get_cnmt_data')
		return
	else:
		files_list=get_files_from_head(remote,remote.name)
		# print(files_list)
		for i in range(len(files_list)):
			if (files_list[i][0]).endswith('.cnmt.nca'):
				nca_name=files_list[i][0]
				off1=files_list[i][1]
				off2=files_list[i][2]
				sz=files_list[i][3]
				if target==None:
					break
				# print(nca_name)
				# print(target)
				if str(nca_name).lower()==str(target).lower():
					break
		remote.seek(off1,off2)	
		buf=int(sz)
		try:
			nca=Nca()
			nca.open(MemoryFile(remote.read(buf)))
			nca.rewind()
			cnmt=io.BytesIO(nca.return_cnmt())
			titleid,titleversion,base_ID,keygeneration,rightsId,RSV,RGV,ctype,metasdkversion,exesdkversion,hasHtmlManual,Installedsize,DeltaSize,ncadata=cnmt_data(cnmt,nca,nca_name)
			d={}
			d['titleid']=titleid;d['version']=titleversion;d['baseid']=base_ID;d['keygeneration']=keygeneration;d['rightsId']=rightsId;
			d['rsv']=RSV;d['rgv']=RGV;d['ctype']=ctype;d['metasdkversion']=metasdkversion;d['exesdkversion']=exesdkversion;
			d['hasHtmlManual']=hasHtmlManual;d['Installedsize']=Installedsize;d['DeltaSize']=DeltaSize;d['ncadata']=ncadata;
			# print(d)
			return d,files_list,remote
		except IOError as e:
			print(e, file=sys.stderr)
Пример #5
0
def showicon_remote(filename):
	filename=html.unescape(filename)
	global globalpath; global globalremote
	if globalpath!=filename:
		if not filename.startswith('http'):
			globalpath=filename
			lib,TD,libpath=get_library_from_path(remote_lib_file,filename)
			ID,name,type,size,md5,remote=DrivePrivate.get_Data(filename,TD=TD,Print=False)
			globalremote=remote
		else:
			globalpath=filename
			remote=DrivePublic.location(filename);readable=remote.readable
			globalremote=remote
			if not readable:
				eel.setImage("")
				return
	try:				
		a=DriveHtmlInfo.icon_info(file=globalremote)		
		# a=DriveHtmlInfo.icon_info(path=filename,TD=TD)
		encoded = b64encode(a).decode("ascii")
		data="data:image/png;base64, " + encoded	
		eel.setImage(data)	
		return
	except:
		iconurl=nutdb.get_icon(remote.id)
		if iconurl!=False:
			eel.setImage(iconurl)
			return
		else:
			eel.setImage("")	
			return
Пример #6
0
def supertrimm(path,ofolder,TD=None,filter=None,file=None):
	buf=64*1024;buffer=buf
	if path.startswith('http'):
		url=path
		if file==None:
			remote=Public.location(url);readable=remote.readable
		else:
			remote=file;readable=remote.readable
		if not readable:
			return False
		type='file'
	else:
		if path=='pick':
			account=Private.token_picker()
			TD=Private.TD_picker(account)
			return
		test=path.split(".+")
		if TD=='pick':
			TD=Private.TD_picker(path)
		if len(test)>1 or path.endswith('/') or path.endswith('\\'):
			type="folder"
		else:
			ID,name,type,size,md5,remote=Private.get_Data(path,TD=TD,Print=False)
	if type!='file':
		# print('Path is a folder')
		Private.folderpicker(path,TD=TD,filter=filter,mode='supertrimm')
		return
	else:
		if remote.name.endswith(".xci"):
			supertrimm_xci(remote,ofolder)
		elif remote.name.endswith(".xcz"):
			from Drive.Decompress import decompress
			decompress(path,ofolder,TD)
Пример #7
0
def get_parents(path, ID=None, url=None):
    file_id = ID
    remote = location(route=path)
    if ID != None:
        file = remote.drive_service.files().get(fileId=file_id,
                                                fields='parents').execute()
        return file.get('parents')
    elif url != None:
        file_id, is_download_link = Public.parse_url(url)
        file = remote.drive_service.files().get(fileId=file_id,
                                                fields='parents').execute()
        return file.get('parents')
    else:
        return False
def addtodrive(filename,truecopy=True):
	if os.path.exists(cache_lib_file):
		lib,TD,libpath=get_cache_lib()
		if lib!=None:
			file_id, is_download_link=DrivePublic.parse_url(filename)		
			if is_download_link:
				remote=DrivePrivate.location(route=libpath,TD_Name=TD)		
				result=remote.drive_service.files().get(fileId=file_id, fields="name,mimeType").execute()		
				name=result['name']	
				testpath=('{}/{}').format(libpath,name)
				remote=DrivePrivate.location(route=testpath,TD_Name=TD)	
				if remote.name==None:			
					name=DrivePrivate.add_to_drive(url=filename,filepath=libpath,makecopy=truecopy,TD=TD)
					filename=('{}/{}').format(libpath,name)
					ID,name,type,size,md5,remote=DrivePrivate.get_Data(filename,TD=TD,Print=False)
				else:
					filename=testpath
				globalremote=remote
		return filename	
Пример #9
0
def interface_menu(path,TD,hide_f_op=False):
	xcipr=False;nxzpr=False;xcimode="Untrimmed";zmode="Compressed"
	if isinstance(path, list):
		if not isinstance(path[0], list):	
			for file in path:
				if file.endswith('.xci'):
					xcipr=True
				elif file.endswith('.xcz') or file.endswith('.nsz'):
					nxzpr=True	
				if xcipr==True and nxzpr==True:
					break
			if xcipr==True:
				xcimode=interface_xci_mode()
			if nxzpr==True:	
				zmode=interface_compressedf_mode()
			ofolder=ask_download_folder()	
			clear_Screen()
			About()						
			counter=len(path)	
			for file in path:	
				route_download(file,TD,ofolder,xcimode=xcimode,zmode=zmode)	
				counter-=1
				if counter>0:
					print("Still {} files to download".format(str(counter)))	
			input('\nPress any key to continue...')					
			return False	
		else:
			counter=0;files=list()
			for i in path:
				counter+=len(i[0])
				files+=i[0]
			for file in files:
				if file.endswith('.xci'):
					xcipr=True
				elif file.endswith('.xcz') or file.endswith('.nsz'):
					nxzpr=True	
				if xcipr==True and nxzpr==True:
					break
			if xcipr==True:
				xcimode=interface_xci_mode()
			if nxzpr==True:	
				zmode=interface_compressedf_mode()
			ofolder=ask_download_folder()	
			clear_Screen()
			About()			
			for k in path:
				TD=k[1];files=k[0]
				for file in files:	
					route_download(file,TD,ofolder,xcimode=xcimode,zmode=zmode)	
					counter-=1
					if counter>0:
						print("Still {} files to download".format(str(counter)))	
			input('\nPress any key to continue...')					
			return False				
	elif path.startswith('http'):
		file=Public.return_remote(path)		
		if file.name.endswith('.xci'):
			xcipr=True
		elif file.name.endswith('.xcz') or file.name.endswith('.nsz'):
			nxzpr=True
		elif file.name==None:
			print("File overpassed quota or is unreadable")
			input('\nPress any key to continue...')	
			clear_Screen()
			About()		
		if xcipr==True:
			xcimode=interface_xci_mode()
		if nxzpr==True:	
			zmode=interface_compressedf_mode()
		ofolder=ask_download_folder()		
		route_download_public(path,ofolder,file.name,xcimode=xcimode,zmode=zmode,file=file)	
		input('\nPress any key to continue...')					
		return False
	elif path !=None:
		if path.endswith('.xci'):
			xcipr=True
		elif path.endswith('.xcz') or path.endswith('.nsz'):
			nxzpr=True	
		if xcipr==True:
			xcimode=interface_xci_mode()
		if nxzpr==True:	
			zmode=interface_compressedf_mode()
		ofolder=ask_download_folder()	
		route_download(path,TD,ofolder,xcimode=xcimode,zmode=zmode)	
		input('\nPress any key to continue...')					
		return False	
	else:
		return False