Skip to content

Commit

Permalink
✨ more cli options and catch crawl errors
Browse files Browse the repository at this point in the history
  • Loading branch information
lonsty committed Mar 18, 2021
1 parent 9e8aec8 commit 38b7867
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 97 deletions.
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ CLI to download videos from https://xvideos.com

</div>

<div align="center"><a href="README_CN.md">中文文档</a></div>
<div align="center"><a href="https://github.com/lonsty/xvideos-dl/blob/master/README_CN.md">中文文档</a></div>

## Features

Expand All @@ -28,6 +28,13 @@ CLI to download videos from https://xvideos.com

## Usage

⚠️**Requires:**

- `Python`: >= 3.7
- `Cookie`: When you run it for the first time, you will be prompted to enter the cookie, log in https://xvideos.com with your account, copy and paste a long string of cookies, then enjoy it.

Cookie is stored in *~/.xvideos/cookie* (or *C:\Users\<USER>\cookie*).

- Install xvideos-dl

```bash
Expand All @@ -48,6 +55,17 @@ xvideos-dl https://www.xvideos.com/video37177493/asian_webcam_2_camsex4u.life ht

## Release History

### 1.1.1

New Feature:

- Add parameters to control the start and end of the video in the download list.

Others:

- When running the same command repeatedly, quickly skip the downloaded video.
- Catch exceptions: 404 not found, forbidden downloading...

### 1.1.0

New Features:
Expand All @@ -61,7 +79,7 @@ New Features:

New Features:

- Download videos from playlist.
- Download videos from favorites.
- Show download speed.

### 1.0.0
Expand Down
13 changes: 12 additions & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ xvideos-dl https://www.xvideos.com/video37177493/asian_webcam_2_camsex4u.life ht

## Release History

### 1.1.1

New Feature:

- Add parameters to control the start and end of the video in the download list.

Others:

- When running the same command repeatedly, quickly skip the downloaded video.
- Catch exceptions: 404 not found, forbidden downloading...

### 1.1.0

New Features:
Expand All @@ -65,7 +76,7 @@ New Features:

New Features:

- Download all videos in playlists.
- Download videos from favorites.
- Show download speed.

### 1.0.0
Expand Down
98 changes: 55 additions & 43 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ typer = {extras = ["all"], version = "^0.3.2"}
rich = "^9.8.2"
beautifulsoup4 = "^4.9.0"
cursor = "^1.3.4"
integv = "^1.3.0"
requests = "^2.25.0"

[tool.poetry.dev-dependencies]
Expand Down
61 changes: 32 additions & 29 deletions xvideos_dl/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ def main(
"--destination",
help="Destination to save the downloaded videos.",
),
max: int = typer.Option(None, "-n", "--maximum", help="Maximum videos to download."),
reversed: bool = typer.Option(False, "-r", "--reversed", help="Download videos in reverse order."),
start: int = typer.Option(1, "-s", "--start", show_default=False, help="Download from the 1st (default) video."),
number: int = typer.Option(None, "-n", "--number", help="Quit after downloading number of videos."),
reverse: bool = typer.Option(False, "-r", "--reverse", help="Download videos in reverse order."),
low: bool = typer.Option(False, "-l", "--low-definition", help="Download low definition videos."),
overwrite: bool = typer.Option(False, "-o", "--overwrite", help="Overwrite the exist video files."),
reset_cookie: bool = typer.Option(False, "--reset-cookie", help="Use a new cookie for this time."),
version: bool = typer.Option(
None,
"-v",
Expand All @@ -57,35 +59,36 @@ def main(
):
"""CLI to download videos from https://xvideos.com"""
videos_to_download = []
for url in urls:
if "/profiles/" in url:
videos = []
videos = get_videos_from_user_page(url, "0", c.USER_UPLOAD_API, videos)
videos_to_download.extend(videos)
elif "/channels/" in url:
videos = []
videos = get_videos_from_user_page(url, "0", c.CHANNEL_API, videos)
videos_to_download.extend(videos)
elif "/favorite/" in url:
pid = parse_playlist_id(url)
videos = get_videos_by_playlist_id(pid)
videos_to_download.extend(videos)
else:
video = get_videos_from_play_page(url)
videos_to_download.append(video)
try:
for url in urls:
if "/profiles/" in url:
videos = []
videos = get_videos_from_user_page(url, "0", c.USER_UPLOAD_API, videos)
videos_to_download.extend(videos)
elif "/channels/" in url:
videos = []
videos = get_videos_from_user_page(url, "0", c.CHANNEL_API, videos)
videos_to_download.extend(videos)
elif "/favorite/" in url:
pid = parse_playlist_id(url)
videos = get_videos_by_playlist_id(pid, reset_cookie)
videos_to_download.extend(videos)
else:
video = get_videos_from_play_page(url)
videos_to_download.append(video)

if reversed:
videos_to_download = videos_to_download[::-1]
if max:
videos_to_download = videos_to_download[:max]
if reverse:
videos_to_download = videos_to_download[::-1]
videos_to_download = videos_to_download[start - 1 :]
if number:
videos_to_download = videos_to_download[:number]

total = len(videos_to_download)
for idx, video in enumerate(videos_to_download):
try:
total = len(videos_to_download)
for idx, video in enumerate(videos_to_download):
with HiddenCursor():
process = Process(idx + 1, total)
console.print(f"Downloading: [cyan]{process.status()}[/]")
download(video, dest, low, overwrite)
except Exception as e:
console.print(f"[red]{e}[/]")
sys.exit(1)
download(video, dest, low, overwrite, reset_cookie)
except Exception as e:
console.print(f"[red]{e}[/]")
sys.exit(1)

0 comments on commit 38b7867

Please sign in to comment.