Exemple #1
0
def get_dlink(tokens,fid,path,num):
	global counter
	settings.DRY = False
	logger.debug("file path: %s "%path)
	bdstoken,sign1,sign3,timestamp = tokens
	
	header = {
	'Host':PAN_HOST,
	'Referer':DISK_HOME,
	}
	data = {
		'sign':base64.b64encode(utils.tosign(sign3,sign1)).decode('utf-8'),
		'timestamp':timestamp,
		'fidlist':'[%s]'%fid,
		'type':'dlink',
		'bdstoken':bdstoken,
		'channel':'chunlei',
		'clienttype':0,
		'web':1,
		'app_id':'250528',
		}
	url = 'http://pan.baidu.com/api/download?' + urllib.parse.urlencode(data)
	
	xml = fetch(url,{},fid+"_json",header,os.path.dirname(path))
	list_json = json.loads(xml.decode("utf-8"))
	
	if list_json['errno'] == 112 or list_json['errno'] == 113 :
		
		if counter < 2:
			counter +=1
			tokens = auth.index()
			return get_dlink(tokens,fid,path,num)
		else:
			return (None,fid,num)
		
	elif list_json['errno'] == -1:
		#remove_invalid_file(path)
		
		return (None,fid,num)
	elif list_json['errno'] == 0:
		
		settings.DRY = True
	
		return (list_json['dlink'][0]['dlink'],fid,num)
	else:
		logger.info ("Unknow Error, return none.")
		return (None,fid,num)
Exemple #2
0
def get_dlink(tokens, fid, path, num):
    global counter
    settings.DRY = False
    logger.debug("file path: %s " % path)
    bdstoken, sign1, sign3, timestamp = tokens

    header = {
        'Host': PAN_HOST,
        'Referer': DISK_HOME,
    }
    data = {
        'sign': base64.b64encode(utils.tosign(sign3, sign1)).decode('utf-8'),
        'timestamp': timestamp,
        'fidlist': '[%s]' % fid,
        'type': 'dlink',
        'bdstoken': bdstoken,
        'channel': 'chunlei',
        'clienttype': 0,
        'web': 1,
        'app_id': '250528',
    }
    url = 'http://pan.baidu.com/api/download?' + urllib.parse.urlencode(data)

    xml = fetch(url, {}, fid + "_json", header, os.path.dirname(path))
    list_json = json.loads(xml.decode("utf-8"))

    if list_json['errno'] == 112 or list_json['errno'] == 113:

        if counter < 2:
            counter += 1
            tokens = auth.index()
            return get_dlink(tokens, fid, path, num)
        else:
            return (None, fid, num)

    elif list_json['errno'] == -1:
        #remove_invalid_file(path)

        return (None, fid, num)
    elif list_json['errno'] == 0:

        settings.DRY = True

        return (list_json['dlink'][0]['dlink'], fid, num)
    else:
        logger.info("Unknow Error, return none.")
        return (None, fid, num)
Exemple #3
0
	def __init__(self):
		Gtk.Window.__init__(self, title="Cloud Disk")

		self.set_border_width(10)
		self.maximize()
		#Setting up the self.grid in which the elements are to be positionned
		self.grid = Gtk.Grid()
		self.grid.set_column_homogeneous(True)
		self.grid.set_row_homogeneous(True)
		self.add(self.grid)
		#box = Gtk.Box(spacing=6)
		#self.add(box)
		self.tokens = auth.index()

		self.bdstoken,self.sign1,self.sign3,self.timestamp = self.tokens
	
		#self.connect('activate', self.on_login_dialog_close)
		#self.connect("delete-event", Gtk.main_quit)
		if not self.bdstoken:
			dialog = LoginDialog(self)	
			#dialog.connect("close",self.on_login_dialog_close)
			response = dialog.run()
	
			dialog.destroy()
			if response == Gtk.ResponseType.DELETE_EVENT:
				print(response)
				print("quit")
				#self.close()
		
				self.destroy()
				return
			elif response == 11:
				print("login")
			else:
				return 
		self.down_list = []

		self.current_path = "/"
		self.current_selection = None
		##							   num,pix,filename,size,path,isdir,fsid,cate,spath,speed,progress,status
		#                              0   1   2        3     4    5     6    7    8     9     10       11
		self.liststore = Gtk.ListStore(int,GdkPixbuf.Pixbuf,str, str, str,int,str,int,str,str,int,str)
		self.current_list = []
		#self.loading_spin = Gtk.Spinner()
		#self.loading_spin.props.valign = Gtk.Align.CENTER
		#box.pack_start(self.loading_spin, False, False, 0)
		#self.grid.add(self.loading_spin)
		
		self.init_view(self.current_path)
		#self.spinn.hide()
		#list_json = cloudapi.list_path(self.current_path,500,settings.DRY,self.bdstoken)
		#logger.debug("list json: %s"%str(len(list_json))
		#file_list = cloudapi.get_list(list_json)
		#logger.debug("file_list: %s"%str(file_list))


		#self.populate_view(file_list)
		
		self.stop_gif = False


		#creating the treeview, making it use the filter as a model, and adding the columns
		self.treeview = Gtk.TreeView(model=self.liststore)
		for i, column_title in enumerate(["Num","Thumb","File", "Size", "Path"]):
			if column_title != "Thumb":
				renderer = Gtk.CellRendererText()
				column = Gtk.TreeViewColumn(column_title, renderer, text=i)
			else:
				renderer_pixbuf = Gtk.CellRendererPixbuf()
				
				column = Gtk.TreeViewColumn(column_title, renderer_pixbuf,pixbuf=i)
			
			#if not column_title == 'isdir' and not column_title == 'fsid' and not column_title == 'cate'  :
			self.treeview.append_column(column)

		self.treeview.props.activate_on_single_click = False
		self.treeview.connect("row-activated",self.on_row_double_click)


		self.selection = self.treeview.get_selection()
		self.selection.connect("changed", self.on_tree_selection_changed)
		self.selection.set_mode(Gtk.SelectionMode.MULTIPLE)
		#select = selection.get_selected_rows() 

		#creating buttons to filter by programming language, and setting up their events
		self.buttons = list()
		for act in ["Up level", "Refresh View", "Batch Add Task", "Remove File", "Download","CleanUp","Search"]:
			button = Gtk.Button(act)
			self.buttons.append(button)
			funcname = "on_%s_button_clicked"%act.lower().replace(" ","_")
			print(funcname)
			func = getattr(self, funcname)
			button.connect("clicked", func)


		#setting up the layout, putting the treeview in a scrollwindow, and the buttons in a row
		self.scrollable_treelist = Gtk.ScrolledWindow()
		self.scrollable_treelist.set_vexpand(True)
		#self.grid.attach(self.loading_spin, 0, 0, 10, 20)
		#self.grid.attach_next_to(self.scrollable_treelist,self.loading_spin, Gtk.PositionType.BOTTOM, 10, 23)
		self.grid.attach(self.scrollable_treelist, 0, 0, 8, 20)
		#box.pack_start(self.scrollable_treelist, True, True, 0)
		self.grid.attach_next_to(self.buttons[0], self.scrollable_treelist, Gtk.PositionType.BOTTOM, 1, 1)
		for i, button in enumerate(self.buttons[1:]):
			self.grid.attach_next_to(button, self.buttons[i], Gtk.PositionType.RIGHT, 1, 1)
			#self.add_action_widget(self.buttons[i],i+1)
			#box.pack_start(self.buttons[i], False, False, 0)
		self.scrollable_treelist.add(self.treeview)

		#box.show_all()
		self.grid.show_all()
Exemple #4
0
    def __init__(self):
        Gtk.Window.__init__(self, title="Cloud Disk")

        self.set_border_width(10)
        self.maximize()
        #Setting up the self.grid in which the elements are to be positionned
        self.grid = Gtk.Grid()
        self.grid.set_column_homogeneous(True)
        self.grid.set_row_homogeneous(True)
        self.add(self.grid)
        #box = Gtk.Box(spacing=6)
        #self.add(box)
        self.tokens = auth.index()

        self.bdstoken, self.sign1, self.sign3, self.timestamp = self.tokens

        #self.connect('activate', self.on_login_dialog_close)
        #self.connect("delete-event", Gtk.main_quit)
        if not self.bdstoken:
            dialog = LoginDialog(self)
            #dialog.connect("close",self.on_login_dialog_close)
            response = dialog.run()

            dialog.destroy()
            if response == Gtk.ResponseType.DELETE_EVENT:
                print(response)
                print("quit")
                #self.close()

                self.destroy()
                return
            elif response == 11:
                print("login")
            else:
                return
        self.down_list = []

        self.current_path = "/"
        self.current_selection = None
        ##							   num,pix,filename,size,path,isdir,fsid,cate,spath,speed,progress,status
        #                              0   1   2        3     4    5     6    7    8     9     10       11
        self.liststore = Gtk.ListStore(int, GdkPixbuf.Pixbuf, str, str, str,
                                       int, str, int, str, str, int, str)
        self.current_list = []
        #self.loading_spin = Gtk.Spinner()
        #self.loading_spin.props.valign = Gtk.Align.CENTER
        #box.pack_start(self.loading_spin, False, False, 0)
        #self.grid.add(self.loading_spin)

        self.init_view(self.current_path)
        #self.spinn.hide()
        #list_json = cloudapi.list_path(self.current_path,500,settings.DRY,self.bdstoken)
        #logger.debug("list json: %s"%str(len(list_json))
        #file_list = cloudapi.get_list(list_json)
        #logger.debug("file_list: %s"%str(file_list))

        #self.populate_view(file_list)

        self.stop_gif = False

        #creating the treeview, making it use the filter as a model, and adding the columns
        self.treeview = Gtk.TreeView(model=self.liststore)
        for i, column_title in enumerate(
            ["Num", "Thumb", "File", "Size", "Path"]):
            if column_title != "Thumb":
                renderer = Gtk.CellRendererText()
                column = Gtk.TreeViewColumn(column_title, renderer, text=i)
            else:
                renderer_pixbuf = Gtk.CellRendererPixbuf()

                column = Gtk.TreeViewColumn(column_title,
                                            renderer_pixbuf,
                                            pixbuf=i)

            #if not column_title == 'isdir' and not column_title == 'fsid' and not column_title == 'cate'  :
            self.treeview.append_column(column)

        self.treeview.props.activate_on_single_click = False
        self.treeview.connect("row-activated", self.on_row_double_click)

        self.selection = self.treeview.get_selection()
        self.selection.connect("changed", self.on_tree_selection_changed)
        self.selection.set_mode(Gtk.SelectionMode.MULTIPLE)
        #select = selection.get_selected_rows()

        #creating buttons to filter by programming language, and setting up their events
        self.buttons = list()
        for act in [
                "Up level", "Refresh View", "Batch Add Task", "Remove File",
                "Download", "CleanUp", "Search"
        ]:
            button = Gtk.Button(act)
            self.buttons.append(button)
            funcname = "on_%s_button_clicked" % act.lower().replace(" ", "_")
            print(funcname)
            func = getattr(self, funcname)
            button.connect("clicked", func)

        #setting up the layout, putting the treeview in a scrollwindow, and the buttons in a row
        self.scrollable_treelist = Gtk.ScrolledWindow()
        self.scrollable_treelist.set_vexpand(True)
        #self.grid.attach(self.loading_spin, 0, 0, 10, 20)
        #self.grid.attach_next_to(self.scrollable_treelist,self.loading_spin, Gtk.PositionType.BOTTOM, 10, 23)
        self.grid.attach(self.scrollable_treelist, 0, 0, 8, 20)
        #box.pack_start(self.scrollable_treelist, True, True, 0)
        self.grid.attach_next_to(self.buttons[0], self.scrollable_treelist,
                                 Gtk.PositionType.BOTTOM, 1, 1)
        for i, button in enumerate(self.buttons[1:]):
            self.grid.attach_next_to(button, self.buttons[i],
                                     Gtk.PositionType.RIGHT, 1, 1)
            #self.add_action_widget(self.buttons[i],i+1)
            #box.pack_start(self.buttons[i], False, False, 0)
        self.scrollable_treelist.add(self.treeview)

        #box.show_all()
        self.grid.show_all()