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
wujiawei
committed
Aug 3, 2017
1 parent
8916093
commit 6385c0f
Showing
8 changed files
with
105 additions
and
47 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
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,58 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
import argparse | ||
import re | ||
|
||
from douban.album import Album | ||
from douban.celebrity import Celebrity | ||
from douban.douban_album_dl import get_album | ||
from douban.douban_celebrity_dl import get_celebrity | ||
|
||
|
||
def get_args(): | ||
""" | ||
argparse 选项的默认语法是基于 Unix 约定, `-` 来表示命令行开关 | ||
:return: | ||
""" | ||
parser = argparse.ArgumentParser(prog='Douban downloader', | ||
description=""" | ||
A tiny tool to download douban resources | ||
""") | ||
parser.add_argument("url", help="start url of album or any other pages") | ||
parser.add_argument('path', default='./douban', nargs='?', help='the path to store all resources') # 可选 | ||
# parser.add_argument('-a', '--album', help='album id', action='store') | ||
# parser.add_argument('-c', '--celebrity', help='celebrity id', action='store') | ||
return parser.parse_args() | ||
|
||
|
||
def parse_url(url, path): | ||
""" | ||
https://www.douban.com/photos/album/<album_id> | ||
https://movie.douban.com/celebrity/<celebrity_id> | ||
:param url: | ||
:return: | ||
""" | ||
match = re.match(r'https://www.douban.com/photos/album/(\d+)', url) | ||
if match: | ||
album_id = match.group(1) | ||
album = Album(album_id) | ||
get_album(album, path) | ||
return | ||
match = re.match(r'https://movie.douban.com/celebrity/(\d+)', url) | ||
if match: | ||
celebrity_id = match.group(1) | ||
celebrity = Celebrity(celebrity_id) | ||
get_celebrity(celebrity, path) | ||
return | ||
print "Not support this url yet" | ||
|
||
|
||
def main(): | ||
"""Main entry point""" | ||
args = get_args() | ||
if args.url is not None: | ||
parse_url(args.url, args.path) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
from bs4 import BeautifulSoup | ||
import requests | ||
|
||
|
||
class Album: | ||
BASE_URL = "https://www.douban.com/photos/album/" | ||
|
||
|
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
File renamed without changes.
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 |
---|---|---|
@@ -1,22 +1,28 @@ | ||
"""Douban Album Downloader""" | ||
|
||
|
||
from setuptools import setup, find_packages | ||
|
||
requirements = [ | ||
"bs4", | ||
"requests" | ||
] | ||
|
||
setup( | ||
name = "douban album dl", | ||
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"]), | ||
install_requires = [ | ||
"bs4", | ||
"requests" | ||
] | ||
name="douban_dl", | ||
version="0.0.1", | ||
description="douban downloader, include album, celebrity", | ||
long_description="douban album downloader", | ||
url="https://github.com/einverne/douban-dl", | ||
author="einverne", | ||
email="einverne@gmail.com", | ||
license="MIT", | ||
# scripts=["bin/douban-album-dl"], | ||
# not use scripts while use entry_points instead https://packaging.python.org/tutorials/distributing-packages/#scripts | ||
entry_points={ | ||
'console_scripts': [ | ||
'douban_dl = douban.__main__:main', | ||
]}, | ||
keywords="douban dl", | ||
packages=find_packages(exclude=["tests"]), | ||
install_requires=requirements, | ||
) |
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 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- |
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,8 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
import os | ||
|
||
|
||
def mkdir(path): | ||
if not os.path.exists(path): | ||
os.makedirs(path) |