Commit 613b99cd authored by Andy Stewart's avatar Andy Stewart
Browse files

Remove aria2p dependeny: use json library instead aria2p.

parent daab627a
Loading
Loading
Loading
Loading
+3 −4
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ EAF is an extensible framework, one can develop any Qt5 application and integrat
1. Make sure to have ```python3``` installed, and use ```pip3``` to install all EAF dependencies (see below list for details)

```Bash
sudo pip3 install dbus-python python-xlib pyqt5 pyqtwebengine pymupdf grip qrcode feedparser aria2p
sudo pip3 install dbus-python python-xlib pyqt5 pyqtwebengine pymupdf grip qrcode feedparser
```

    If you use Arch Linux, we recommend you install dependencies with below command:
@@ -55,7 +55,7 @@ sudo pip3 install dbus-python python-xlib pyqt5 pyqtwebengine pymupdf grip qrcod
```Bash
sudo pacman -S python-pyqt5 python-pyqt5-sip python-pyqtwebengine python-xlib python-qrcode python-feedparser
python-dbus
yay -S python-pymupdf python-grip aria2p
yay -S python-pymupdf python-grip
```

    Because Arch's QtWebEngine build with proprietary codec library that can play video file with browser.
@@ -115,7 +115,6 @@ Packages listed as **Core** are mandatory for EAF to work, whereas other package
| grip          | pip3          | Markdown Previewer                                                                 | Markdown rendering server                 |
| qrcode        | pip3          | File Sender, File Receiver, Airshare                                               | Render QR code pointing to local files    |
| feedparser    | pip3          | RSS Reader                                                                         | Parse RSS feeds                           |
| aria2p        | pip3          | Browser                                                                            | Send download requests to Aria2 daemon    |
| aria2         | pacman (Arch) | Browser                                                                            | Download files from the web               |
| wetty         | yarn          | Terminal                                                                           | Communicate between browser and local TTY |
| libreoffice   | pacman        | Doc Viewer                                                                         | Convert doc file to pdf |
@@ -195,7 +194,7 @@ If you got "undefined symbol" error after start EAF, and you use Arch Linux, yes
You need use pip install all dependences after you upgrade your Arch system, then undefine symbol error will fix.

```Bash
sudo pip3 install dbus-python python-xlib pyqt5 pyqtwebengine pymupdf grip qrcode feedparser aria2p --force-reinstall
sudo pip3 install dbus-python python-xlib pyqt5 pyqtwebengine pymupdf grip qrcode feedparser --force-reinstall
```

### What is Github Personal Access Tokens?
+6 −10
Original line number Diff line number Diff line
@@ -448,19 +448,15 @@ class BrowserBuffer(Buffer):

            self.message_to_emacs.emit("Save image: " + image_path)
        else:
            from shutil import which

            if which("aria2p") is not None:

            self.try_start_aria2_daemon()

                download_data = download_item.url().toString()
                with open(os.devnull, "w") as null_file:
                    subprocess.Popen(["aria2p", "add", download_data], stdout=null_file)
            from core.pyaria2 import Jsonrpc

                self.message_to_emacs.emit("Start download: " + download_data)
            else:
                self.message_to_emacs.emit("Please install aria2p first.")
            download_url = download_item.url().toString()
            jsonrpc = Jsonrpc('localhost', 6800)
            resp = jsonrpc.addUris(download_url)

            self.message_to_emacs.emit("Start download: " + download_url)

    def destroy_buffer(self):
        # Record close page.

core/pyaria2.py

0 → 100644
+53 −0
Original line number Diff line number Diff line

#!/usr/bin/env python
# coding=utf-8

import json
import requests

class Jsonrpc(object):

    MUTI_METHOD = 'system.multicall'
    ADDURI_METHOD = 'aria2.addUri'

    def __init__(self, host, port, token=None):
        self._idCount = 0
        self.host = host
        self.port = port
        self.serverUrl = "http://{host}:{port}/jsonrpc".format(**locals())

    def _genParams(self, method , uris=None, options=None, cid=None):
        p = {
            'jsonrpc': '2.0',
            'id': self._idCount,
            'method': method,
            'test': 'test',
            'params': []
        }
        if uris:
            p['params'].append(uris)
        if options:
            p['params'].append(options)
        return p

    def _post(self, action, params, onSuccess, onFail=None):
        if onFail is None:
            onFail = Jsonrpc._defaultErrorHandle
        paramsObject = self._genParams(action, *params)
        resp = requests.post(self.serverUrl, data=json.dumps(paramsObject))
        result = resp.json()
        if "error" in result:
            return onFail(result["error"]["code"], result["error"]["message"])
        else:
            return onSuccess(resp)

    def addUris(self, uri, options=None):
        def success(response):
            return response.text
        return self._post(Jsonrpc.ADDURI_METHOD, [[uri,], options], success)


    @staticmethod
    def _defaultErrorHandle(code, message):
        print ("ERROR: {},{}".format(code, message))
        return None