Skip to content

Commit

Permalink
update 1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hwfan committed Aug 20, 2021
1 parent 02b57aa commit 4b03d4c
Show file tree
Hide file tree
Showing 10 changed files with 98 additions and 35 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,5 @@ dmypy.json

# Pyre type checker
.pyre/

pack.sh
10 changes: 6 additions & 4 deletions DriveDownloader/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
# E-mail: [email protected] #
# Homepage: https://github.com/hwfan #
#############################################
from DriveDownloader.netdrives.googledrive import GoogleDriveSession
from DriveDownloader.netdrives.onedrive import OneDriveSession
from DriveDownloader.netdrives import *
import argparse
import os
import sys
Expand All @@ -18,8 +17,7 @@ def parse_args():
return args

def simple_cli():

sys.stdout.write('============ Drive Downloader V1.2 ============\n')
sys.stdout.write('============ Drive Downloader ============\n')

if len(sys.argv) > 1:
# non-interactive mode
Expand All @@ -45,6 +43,10 @@ def simple_cli():
download_session = OneDriveSession(final_proxy)
elif 'drive.google.com' in url:
download_session = GoogleDriveSession(final_proxy)
elif 'sharepoint' in url:
download_session = SharePointSession(final_proxy)
elif 'dropbox' in url:
download_session = DropBoxSession(final_proxy)
else:
raise NotImplementedError("The drive type is not supported!")

Expand Down
4 changes: 4 additions & 0 deletions DriveDownloader/netdrives/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .googledrive import GoogleDriveSession
from .onedrive import OneDriveSession
from .sharepoint import SharePointSession
from .dropbox import DropBoxSession
4 changes: 1 addition & 3 deletions DriveDownloader/netdrives/basedrive.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,17 @@
import re
from tqdm import tqdm
from DriveDownloader.utils.misc import *
from fake_useragent import UserAgent

class DriveSession:
def __init__(self, proxy=None, chunk_size=32768):
self.session = requests.Session()
self.ua = UserAgent(verify_ssl=False)
if proxy is None:
self.proxies = None
else:
self.proxies = { "http": proxy, "https": proxy, }
self.params = dict()
self.chunk_size = chunk_size
self.headers = { 'Accept-Encoding': '', 'User-Agent': self.ua.random, }
self.headers = { 'Accept-Encoding': '', }

def generate_url(self, url):
raise NotImplementedError
Expand Down
27 changes: 27 additions & 0 deletions DriveDownloader/netdrives/dropbox.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#############################################
# Author: Hongwei Fan #
# E-mail: [email protected] #
# Homepage: https://github.com/hwfan #
#############################################
import urllib.parse as urlparse
from DriveDownloader.netdrives.basedrive import DriveSession

class DropBoxSession(DriveSession):
def __init__(self, proxy, chunk_size=32768):
DriveSession.__init__(self, proxy, chunk_size)

def generate_url(self, url):
'''
Solution provided by:
https://www.qian.blue/archives/OneDrive-straight.html
'''
parsed_url = urlparse.urlparse(url)
netloc = parsed_url.netloc.replace('www', 'dl-web')
query = ''
parsed_url = parsed_url._replace(netloc=netloc, query=query)
resultUrl = urlparse.urlunparse(parsed_url)
return resultUrl

def connect(self, url, custom_filename=''):
onedrive_url = self.generate_url(url)
DriveSession.connect(self, onedrive_url, download=True, custom_filename=custom_filename)
4 changes: 4 additions & 0 deletions DriveDownloader/netdrives/googledrive.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ def __init__(self, proxy, chunk_size=32768):
DriveSession.__init__(self, proxy, chunk_size)

def generate_url(self, url):
'''
Solution provided by:
https://stackoverflow.com/questions/25010369/wget-curl-large-file-from-google-drive
'''
parsed_url = urlparse.urlparse(url)
parsed_qs = urlparse.parse_qs(parsed_url.query)
if 'id' in parsed_qs:
Expand Down
3 changes: 2 additions & 1 deletion DriveDownloader/netdrives/onedrive.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
# E-mail: [email protected] #
# Homepage: https://github.com/hwfan #
#############################################
from DriveDownloader.netdrives.basedrive import DriveSession
import base64
from DriveDownloader.netdrives.basedrive import DriveSession

class OneDriveSession(DriveSession):
def __init__(self, proxy, chunk_size=32768):
DriveSession.__init__(self, proxy, chunk_size)
Expand Down
28 changes: 28 additions & 0 deletions DriveDownloader/netdrives/sharepoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#############################################
# Author: Hongwei Fan #
# E-mail: [email protected] #
# Homepage: https://github.com/hwfan #
#############################################
import urllib.parse as urlparse
from DriveDownloader.netdrives.basedrive import DriveSession

class SharePointSession(DriveSession):
def __init__(self, proxy, chunk_size=32768):
DriveSession.__init__(self, proxy, chunk_size)

def generate_url(self, url):
'''
Solution provided by:
https://www.qian.blue/archives/OneDrive-straight.html
'''
parsed_url = urlparse.urlparse(url)
path = parsed_url.path
netloc = parsed_url.netloc
splitted_path = path.split('/')
personal_attr, domain, sharelink = splitted_path[3:6]
resultUrl = f"https://{netloc}/{personal_attr}/{domain}/_layouts/52/download.aspx?share={sharelink}"
return resultUrl

def connect(self, url, custom_filename=''):
onedrive_url = self.generate_url(url)
DriveSession.connect(self, onedrive_url, download=True, custom_filename=custom_filename)
47 changes: 22 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@

DriveDownloader is a Python tool for downloading files on online drives. With DriveDownloader, one can download the resources from netdrive with only one command line.

DriveDownloader now supports **OneDrive** and **GoogleDrive**.
DriveDownloader now supports:
- OneDrive
- OneDrive for Business
- GoogleDrive
- Dropbox

**[News] Update version 1.2.1: Repaired OneDrive supporting bug.**
**[News] Update version 1.3.0: Supported Sharepoint, Dropbox and MEGA. Removed the deprecated fake-useragent.**

**[News] Update version 1.2: New interface, better project structure and documents.**
**[News] Update version 1.2.1: Repaired OneDrive supporting bug.**

## Requirements

- Python 3
- argparse
- requests
- tqdm
- fake-useragent
- pysocks
- Use `pip install -r requirements.txt` to install the packages.
- Proxy server if necessary. **We don't provide proxy service for DriveDownloader.**
Expand All @@ -33,6 +36,15 @@ DriveDownloader now supports **OneDrive** and **GoogleDrive**.

## Usage

### Non-interactive Mode

```
ddl URL --filename FILENAME --proxy PROXY
```

**Warning for OneDrive user:**

Since Linux shell can parse "!" from the url, single quotes(') should be added before and after the url when using non-interactive mode.
### Interactive Mode

1. Simply input "ddl" in the shell and press enter.
Expand All @@ -41,7 +53,7 @@ DriveDownloader now supports **OneDrive** and **GoogleDrive**.
```
2. The shell will return an interface for inputting the user info.
```
============ Drive Downloader V1.2 ============
============ Drive Downloader ============
URL: (input your url here)
Filename: (input your filename here)
Proxy: (input your proxy here)
Expand All @@ -53,24 +65,9 @@ DriveDownloader now supports **OneDrive** and **GoogleDrive**.
Download finished.
```

### Non-interactive Mode

For the non-interactive mode, please input the user info as arguments after "ddl".
- Since Linux shell can parse "!" from the url,
- **single quotes(') should be added before and after the url**
- when using non-interactive mode.

```
ddl 'URL' --filename FILENAME --proxy PROXY
```

### Options

- `URL`: target url to download from.
- OneDrive Example: <https://1drv.ms/t/s!ArUVoRxpBphY5U-axxe-xf3fidKh?e=kPexEF>
- GoogleDrive Example:
- <https://drive.google.com/file/d/1XQRdK8ewbpOlQn7CvB99aT1FLi6cUKt_/view?usp=sharing>
- <https://drive.google.com/open?id=1XQRdK8ewbpOlQn7CvB99aT1FLi6cUKt_>
- `--filename FILENAME`: (optional) output filename. Example: 'hello.txt'
- `--proxy PROXY`: (optional) the proxy address through which to download the file. Example: `--proxy http://example.com:80`

Expand All @@ -84,15 +81,15 @@ We extract the size of file from the "Content-Length" of HTTP response. If this

Try "socks5h" as the protocol prefix instead. It will transmit the url to proxy server for parsing.

**fake_useragent.errors.FakeUserAgentError: Maximum amount of retries reached**
<!-- **fake_useragent.errors.FakeUserAgentError: Maximum amount of retries reached**
This message may occur when DriveDownloader is first used. Try again and if this also occurs, please report in the issue.
This message may occur when DriveDownloader is first used. Try again and if this also occurs, please report in the issue. -->

## TODOS

- [x] General downloader API - one class for downloading, and several inheritance classes to load the configurations.
- [x] Command-line UI - apostrophes will not be needed in the newest version.
- [ ] Window based UI - PyQt, X Window, ...
- [ ] Support more netdrives - OneDrive for Business, Dropbox, MEGA, ...
- [ ] Multi-process downloading.
- [x] Support more netdrives - OneDrive for Business, Dropbox, ...
- [ ] Downloading files from a list.
- [ ] Multi-process downloading.
- [ ] Window based UI - PyQt, X Window, ...
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages
setup(
name = "DriveDownloader",
version = "1.2.1-post1",
version = "1.3.0",
keywords = ("drivedownloader", "drive", "netdrive", "download"),
description = "A Python netdrive downloader.",
long_description = "A Python netdrive downloader.",
Expand All @@ -14,7 +14,7 @@
packages = find_packages(),
include_package_data = True,
platforms = "any",
install_requires = ['argparse', 'requests', 'tqdm', 'fake-useragent', 'pysocks'],
install_requires = ['argparse', 'requests', 'tqdm', 'pysocks'],

scripts = [],
entry_points = {
Expand Down

0 comments on commit 4b03d4c

Please sign in to comment.