Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
delta4d committed May 19, 2017
0 parents commit 031c4ba
Show file tree
Hide file tree
Showing 12 changed files with 148 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
build
dist
.egg-info
__pycache__
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include LICENSE
36 changes: 36 additions & 0 deletions README.rst
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.
38 changes: 38 additions & 0 deletions bin/douban-album-dl
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 added douban/__init__.py
Empty file.
25 changes: 25 additions & 0 deletions douban/album.py
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")
11 changes: 11 additions & 0 deletions douban_album_downloader.egg-info/PKG-INFO
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
11 changes: 11 additions & 0 deletions douban_album_downloader.egg-info/SOURCES.txt
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
1 change: 1 addition & 0 deletions douban_album_downloader.egg-info/dependency_links.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions douban_album_downloader.egg-info/top_level.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
douban
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[bdist_wheel]
universal = 1
18 changes: 18 additions & 0 deletions setup.py
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"])
)

0 comments on commit 031c4ba

Please sign in to comment.