forked from delta4d/douban-album-dl
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 031c4ba
Showing
12 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
build | ||
dist | ||
.egg-info | ||
__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include LICENSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
douban album downloader | ||
======================= | ||
|
||
A simple python script to download douban albums. | ||
|
||
|
||
installation | ||
------------ | ||
|
||
:: | ||
|
||
$ pip install douban-album-dl | ||
|
||
|
||
usage | ||
----- | ||
|
||
:: | ||
|
||
$ douban-album-dl album_id [location] | ||
|
||
``album_id`` is the last number of the douban album url. | ||
i.e. "https://www.douban.com/photos/album/**<ALBUM_ID>**" | ||
|
||
``location`` is the folder where images saved, defaults to ``./album``. | ||
|
||
license | ||
------- | ||
|
||
MIT | ||
|
||
|
||
contribute | ||
---------- | ||
|
||
Feel free to file an issue, or make a pr. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env python | ||
|
||
from douban.album import Album | ||
import requests | ||
import sys | ||
import os | ||
|
||
def mayday(): | ||
h = """douban-album-dl album_id [location=./album]""" | ||
|
||
print(h) | ||
|
||
def mkdir(path): | ||
if not os.path.exists(path): | ||
os.makedirs(path) | ||
|
||
def get_album(album, path): | ||
idx = 0 | ||
mkdir(path) | ||
os.chdir(path) | ||
for photo_url in album.photos(): | ||
name = os.path.basename(photo_url) | ||
print("{}: saving {}".format(idx, name)) | ||
r = requests.get(photo_url, stream=True) | ||
with open(name, "wb") as f: | ||
f.write(r.content) | ||
idx += 1 | ||
print() | ||
print("saving album to {}, total {} images".format(path, idx)) | ||
|
||
|
||
if __name__ == "__main__": | ||
if len(sys.argv) == 1: | ||
mayday() | ||
else: | ||
album = Album(sys.argv[1]) | ||
path = "./album" if len(sys.argv) == 2 else sys.argv[2] | ||
get_album(album, path) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from bs4 import BeautifulSoup | ||
import requests | ||
|
||
class Album: | ||
BASE_URL = "https://www.douban.com/photos/album/" | ||
|
||
def __init__(self, album_id): | ||
self.url = Album.BASE_URL + album_id + "/?start=" | ||
|
||
def photos(self): | ||
start = 0 | ||
while True: | ||
next_photos = self.__photos(start) | ||
step = len(next_photos) | ||
if 0 == step: | ||
break | ||
for photo in next_photos: | ||
yield photo.img["src"].replace("photo/lthumb", "photo/large") | ||
start += step | ||
|
||
def __photos(self, start): | ||
url = self.url + str(start) | ||
r = requests.get(url) | ||
soup = BeautifulSoup(r.text, "html.parser") | ||
return soup.find_all("div", class_="photo_wrap") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Metadata-Version: 1.0 | ||
Name: douban-album-downloader | ||
Version: 0.0.1 | ||
Summary: douban album downloader | ||
Home-page: https://github.com/delta4d/douban-album-dl | ||
Author: delta | ||
Author-email: UNKNOWN | ||
License: MIT | ||
Description: douban album downloader | ||
Keywords: douban dl | ||
Platform: UNKNOWN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
MANIFEST.in | ||
README.rst | ||
setup.cfg | ||
setup.py | ||
bin/douban-album-dl | ||
douban/__init__.py | ||
douban/album.py | ||
douban_album_downloader.egg-info/PKG-INFO | ||
douban_album_downloader.egg-info/SOURCES.txt | ||
douban_album_downloader.egg-info/dependency_links.txt | ||
douban_album_downloader.egg-info/top_level.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
douban |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[bdist_wheel] | ||
universal = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
"""Douban Album Downloader""" | ||
|
||
|
||
from setuptools import setup, find_packages | ||
|
||
setup( | ||
name = "douban album downloader", | ||
version = "0.0.1", | ||
description = "douban album downloader", | ||
long_description = "douban album downloader", | ||
url = "https://github.com/delta4d/douban-album-dl", | ||
author = "delta", | ||
email = "delta4d@gmail.com", | ||
license = "MIT", | ||
scripts = ["bin/douban-album-dl"], | ||
keywords = "douban dl", | ||
packages = find_packages(exclude = ["tests"]) | ||
) |