refactor for Python packaging

This commit is contained in:
Mort Yao 2012-08-31 17:20:38 +02:00
parent e71972d4a1
commit 70cb82b703
22 changed files with 181 additions and 59 deletions

6
.gitignore vendored
View File

@ -1,7 +1,11 @@
_* /build/
/dist/
_*/
*.py[cod] *.py[cod]
*.download *.download
*.3gp
*.flv *.flv
*.mp4 *.mp4
*.webm *.webm

2
CHANGELOG.txt Normal file
View File

@ -0,0 +1,2 @@
Changelog
=========

21
MANIFEST Normal file
View File

@ -0,0 +1,21 @@
# file GENERATED by distutils, do NOT edit
CHANGELOG.txt
LICENSE.txt
Makefile
README.md
README.txt
setup.cfg
setup.py
you-get
you-get.json
you_get/__init__.py
you_get/common.py
you_get/main.py
you_get/downloader/__init__.py
you_get/downloader/tudou.py
you_get/downloader/yinyuetai.py
you_get/downloader/youku.py
you_get/downloader/youtube.py
you_get/processor/__init__.py
you_get/processor/merge_flv.py
you_get/processor/merge_mp4.py

5
MANIFEST.in Normal file
View File

@ -0,0 +1,5 @@
include *.txt
include Makefile
include README.md
include you-get
include you-get.json

18
Makefile Normal file
View File

@ -0,0 +1,18 @@
default: install sdist bdist
clean:
rm -fr build/ dist/
build:
python3 setup.py build
install: build
sudo python3 setup.py install
sdist:
python3 setup.py sdist
bdist:
python3 setup.py bdist
.PHONY: default clean build install sdist bdist

2
README.txt Normal file
View File

@ -0,0 +1,2 @@
You-Get
=======

5
setup.cfg Normal file
View File

@ -0,0 +1,5 @@
[build]
force=0
[global]
verbose=0

30
setup.py Executable file
View File

@ -0,0 +1,30 @@
#!/usr/bin/env python3
PROJ_METADATA = 'you-get.json'
import os, json
here = os.path.abspath(os.path.dirname(__file__))
proj_info = json.loads(open(os.path.join(here, PROJ_METADATA)).read())
README = open(os.path.join(here, 'README.txt')).read()
CHANGELOG = open(os.path.join(here, 'CHANGELOG.txt')).read()
from distutils.core import setup
setup(
name = proj_info['name'],
version = proj_info['version'],
author = proj_info['author'],
author_email = proj_info['author_email'],
url = proj_info['url'],
download_url = proj_info['download_url'],
license = proj_info['license'],
description = proj_info['description'],
keywords = proj_info['keywords'],
long_description = README + '\n\n' + CHANGELOG,
packages = proj_info['packages'],
classifiers = proj_info['classifiers']
)

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from get import * from you_get import *
if __name__ == '__main__': if __name__ == "__main__":
main('you-get', any_download, any_download_playlist) script_main('you-get', any_download, any_download_playlist)

View File

@ -1,19 +1,39 @@
{ {
"name": "you-get",
"version": "0.0.1", "version": "0.0.1",
"date": "2012-08-20", "date": "2012-08-20",
"author": "Mort Yao <mort.yao@gmail.com>",
"file_list": [ "author": "Mort Yao",
"LICENSE", "author_email": "mort.yao@gmail.com",
"README.md", "url": "http://www.soimort.org/you-get/",
"common.py", "download_url": "https://github.com/soimort/you-get/zipball/master",
"get.py", "license": "MIT",
"get_tudou.py",
"get_yinyuetai.py", "description": "A YouTube/Youku video downloader written in Python 3.",
"get_youku.py", "keywords": "video download youtube youku",
"get_youtube.py",
"merge_flv.py", "packages": [
"merge_mp4.py", "you_get",
"you-get", "you_get.downloader",
"you-get.json" "you_get.processor"
],
"classifiers": [
"Development Status :: 1 - Planning",
"Environment :: Console",
"Environment :: Web Environment",
"Intended Audience :: End Users/Desktop",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.2",
"Topic :: Internet",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Multimedia",
"Topic :: Multimedia :: Video",
"Topic :: Utilities"
] ]
} }

7
you_get/__init__.py Normal file
View File

@ -0,0 +1,7 @@
from .processor import *
from .downloader import *
from .main import *
from .common import script_main
__version__ = common.proj_info['version']

View File

@ -1,4 +1,3 @@
#!/usr/bin/env python3
import getopt import getopt
import json import json
@ -295,12 +294,12 @@ def download_urls(urls, title, ext, total_size, output_dir = '.', refer = None,
if not merge: if not merge:
return return
if ext == 'flv': if ext == 'flv':
from merge_flv import concat_flvs from .processor.merge_flv import concat_flvs
concat_flvs(flvs, os.path.join(output_dir, title + '.flv')) concat_flvs(flvs, os.path.join(output_dir, title + '.flv'))
for flv in flvs: for flv in flvs:
os.remove(flv) os.remove(flv)
elif ext == 'mp4': elif ext == 'mp4':
from merge_mp4 import concat_mp4s from .processor.merge_mp4 import concat_mp4s
concat_mp4s(flvs, os.path.join(output_dir, title + '.mp4')) concat_mp4s(flvs, os.path.join(output_dir, title + '.mp4'))
for flv in flvs: for flv in flvs:
os.remove(flv) os.remove(flv)
@ -360,7 +359,7 @@ def set_http_proxy(proxy):
opener = request.build_opener(proxy_support) opener = request.build_opener(proxy_support)
request.install_opener(opener) request.install_opener(opener)
def main(script_name, download, download_playlist = None): def script_main(script_name, download, download_playlist = None):
version = 'You-Get %s, a video downloader.' % proj_info['version'] version = 'You-Get %s, a video downloader.' % proj_info['version']
help = 'Usage: [python3] %s [OPTION]... [URL]...\n' % script_name help = 'Usage: [python3] %s [OPTION]... [URL]...\n' % script_name
help += '''\nStartup options: help += '''\nStartup options:

View File

@ -0,0 +1,5 @@
from .tudou import *
from .yinyuetai import *
from .youku import *
from .youtube import *

View File

@ -1,8 +1,8 @@
#!/usr/bin/env python3 #!/usr/bin/env python
__all__ = ['tudou_download', 'tudou_download_playlist', 'tudou_download_by_id', 'tudou_download_by_iid'] __all__ = ['tudou_download', 'tudou_download_playlist', 'tudou_download_by_id', 'tudou_download_by_iid']
from common import * from ..common import *
def tudou_download_by_iid(iid, title, output_dir = '.', merge = True, info_only = False): def tudou_download_by_iid(iid, title, output_dir = '.', merge = True, info_only = False):
xml = get_html('http://v2.tudou.com/v?it=' + iid + '&st=1,2,3,4,99') xml = get_html('http://v2.tudou.com/v?it=' + iid + '&st=1,2,3,4,99')
@ -73,4 +73,4 @@ download = tudou_download
download_playlist = tudou_download_playlist download_playlist = tudou_download_playlist
if __name__ == '__main__': if __name__ == '__main__':
main('tudou', tudou_download, tudou_download_playlist) script_main('tudou.py', tudou_download, tudou_download_playlist)

View File

@ -1,8 +1,8 @@
#!/usr/bin/env python3 #!/usr/bin/env python
__all__ = ['yinyuetai_download', 'yinyuetai_download_by_id'] __all__ = ['yinyuetai_download', 'yinyuetai_download_by_id']
from common import * from ..common import *
def yinyuetai_download_by_id(id, title = None, output_dir = '.', merge = True, info_only = False): def yinyuetai_download_by_id(id, title = None, output_dir = '.', merge = True, info_only = False):
assert title assert title
@ -33,4 +33,4 @@ download = yinyuetai_download
download_playlist = playlist_not_supported('yinyuetai') download_playlist = playlist_not_supported('yinyuetai')
if __name__ == '__main__': if __name__ == '__main__':
main('get_yinyuetai.py', yinyuetai_download) script_main('yinyuetai.py', yinyuetai_download)

View File

@ -1,9 +1,9 @@
#!/usr/bin/env python3 #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
__all__ = ['youku_download', 'youku_download_playlist', 'youku_download_by_id'] __all__ = ['youku_download', 'youku_download_playlist', 'youku_download_by_id']
from common import * from ..common import *
import json import json
from random import randint from random import randint
@ -198,4 +198,4 @@ download = youku_download
download_playlist = youku_download_playlist download_playlist = youku_download_playlist
if __name__ == '__main__': if __name__ == '__main__':
main('get_youku.py', youku_download, youku_download_playlist) script_main('youku.py', youku_download, youku_download_playlist)

View File

@ -1,8 +1,8 @@
#!/usr/bin/env python3 #!/usr/bin/env python
__all__ = ['youtube_download', 'youtube_download_by_id'] __all__ = ['youtube_download', 'youtube_download_by_id']
from common import * from ..common import *
def youtube_download_by_id(id, title = None, output_dir = '.', merge = True, info_only = False): def youtube_download_by_id(id, title = None, output_dir = '.', merge = True, info_only = False):
try: try:
@ -33,4 +33,4 @@ download = youtube_download
download_playlist = playlist_not_supported('youtube') download_playlist = playlist_not_supported('youtube')
if __name__ == '__main__': if __name__ == '__main__':
main('get_youtube.py', youtube_download) script_main('youtube.py', youtube_download)

View File

@ -1,10 +1,9 @@
#!/usr/bin/env python3 #!/usr/bin/env python
from common import * __all__ = ['any_download', 'any_download_playlist']
import get_tudou
import get_yinyuetai from .downloader import *
import get_youku from .common import *
import get_youtube
def url_to_module(url): def url_to_module(url):
site = r1(r'http://([^/]+)/', url) site = r1(r'http://([^/]+)/', url)
@ -17,22 +16,22 @@ def url_to_module(url):
k = r1(r'([^.]+)', domain) k = r1(r'([^.]+)', domain)
downloads = { downloads = {
'youtube': get_youtube, 'youtube': youtube,
'youku': get_youku, 'youku': youku,
'yinyuetai': get_yinyuetai, 'yinyuetai': yinyuetai,
'tudou': get_tudou, 'tudou': tudou,
#TODO: #TODO:
# 'acfun': get_acfun, # 'acfun': acfun,
# 'bilibili': get_bilibili, # 'bilibili': bilibili,
# 'kankanews': get_bilibili, # 'kankanews': bilibili,
# 'iask': get_iask, # 'iask': iask,
# 'sina': get_iask, # 'sina': iask,
# 'ku6': get_ku6, # 'ku6': ku6,
# 'pptv': get_pptv, # 'pptv': pptv,
# 'iqiyi': get_iqiyi, # 'iqiyi': iqiyi,
# 'sohu': get_sohu, # 'sohu': sohu,
# '56': get_w56, # '56': w56,
# 'cntv': get_cntv, # 'cntv': cntv,
} }
if k in downloads: if k in downloads:
return downloads[k] return downloads[k]
@ -48,4 +47,4 @@ def any_download_playlist(url, output_dir = '.', merge = True, info_only = False
m.download_playlist(url, output_dir = output_dir, merge = merge, info_only = info_only) m.download_playlist(url, output_dir = output_dir, merge = merge, info_only = info_only)
if __name__ == '__main__': if __name__ == '__main__':
main('get.py', any_download, any_download_playlist) script_main('main.py', any_download, any_download_playlist)

View File

@ -0,0 +1,5 @@
__all__ = ['concat_flvs', 'concat_mp4s']
from .merge_flv import concat_flvs
from .merge_mp4 import concat_mp4s

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python3 #!/usr/bin/env python
import struct import struct
from io import BytesIO from io import BytesIO

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python3 #!/usr/bin/env python
# reference: c041828_ISO_IEC_14496-12_2005(E).pdf # reference: c041828_ISO_IEC_14496-12_2005(E).pdf