Skip to content

Commit

Permalink
refactor for Python packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
soimort committed Aug 31, 2012
1 parent e71972d commit 70cb82b
Show file tree
Hide file tree
Showing 22 changed files with 181 additions and 59 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
_*
/build/
/dist/

_*/
*.py[cod]

*.download
*.3gp
*.flv
*.mp4
*.webm
2 changes: 2 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Changelog
=========
File renamed without changes.
21 changes: 21 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
@@ -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 changes: 5 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include *.txt
include Makefile
include README.md
include you-get
include you-get.json
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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 changes: 2 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
You-Get
=======
5 changes: 5 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[build]
force=0

[global]
verbose=0
30 changes: 30 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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']
)
6 changes: 3 additions & 3 deletions you-get
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

from get import *
from you_get import *

if __name__ == '__main__':
main('you-get', any_download, any_download_playlist)
if __name__ == "__main__":
script_main('you-get', any_download, any_download_playlist)
50 changes: 35 additions & 15 deletions you-get.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,39 @@
{
"name": "you-get",
"version": "0.0.1",
"date": "2012-08-20",
"author": "Mort Yao <mort.yao@gmail.com>",
"file_list": [
"LICENSE",
"README.md",
"common.py",
"get.py",
"get_tudou.py",
"get_yinyuetai.py",
"get_youku.py",
"get_youtube.py",
"merge_flv.py",
"merge_mp4.py",
"you-get",
"you-get.json"
]

"author": "Mort Yao",
"author_email": "mort.yao@gmail.com",
"url": "http://www.soimort.org/you-get/",
"download_url": "https://github.com/soimort/you-get/zipball/master",
"license": "MIT",

"description": "A YouTube/Youku video downloader written in Python 3.",
"keywords": "video download youtube youku",

"packages": [
"you_get",
"you_get.downloader",
"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 changes: 7 additions & 0 deletions you_get/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

from .processor import *
from .downloader import *
from .main import *
from .common import script_main

__version__ = common.proj_info['version']
7 changes: 3 additions & 4 deletions common.py → you_get/common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3

import getopt
import json
Expand Down Expand Up @@ -295,12 +294,12 @@ def download_urls(urls, title, ext, total_size, output_dir = '.', refer = None,
if not merge:
return
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'))
for flv in flvs:
os.remove(flv)
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'))
for flv in flvs:
os.remove(flv)
Expand Down Expand Up @@ -360,7 +359,7 @@ def set_http_proxy(proxy):
opener = request.build_opener(proxy_support)
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']
help = 'Usage: [python3] %s [OPTION]... [URL]...\n' % script_name
help += '''\nStartup options:
Expand Down
5 changes: 5 additions & 0 deletions you_get/downloader/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

from .tudou import *
from .yinyuetai import *
from .youku import *
from .youtube import *
6 changes: 3 additions & 3 deletions get_tudou.py → you_get/downloader/tudou.py
Original file line number Diff line number Diff line change
@@ -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']

from common import *
from ..common import *

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')
Expand Down Expand Up @@ -73,4 +73,4 @@ def tudou_download_playlist(url, output_dir = '.', merge = True, info_only = Fal
download_playlist = tudou_download_playlist

if __name__ == '__main__':
main('tudou', tudou_download, tudou_download_playlist)
script_main('tudou.py', tudou_download, tudou_download_playlist)
6 changes: 3 additions & 3 deletions get_yinyuetai.py → you_get/downloader/yinyuetai.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env python3
#!/usr/bin/env python

__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):
assert title
Expand Down Expand Up @@ -33,4 +33,4 @@ def yinyuetai_download(url, output_dir = '.', merge = True, info_only = False):
download_playlist = playlist_not_supported('yinyuetai')

if __name__ == '__main__':
main('get_yinyuetai.py', yinyuetai_download)
script_main('yinyuetai.py', yinyuetai_download)
6 changes: 3 additions & 3 deletions get_youku.py → you_get/downloader/youku.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python3
#!/usr/bin/env python
# -*- coding: utf-8 -*-

__all__ = ['youku_download', 'youku_download_playlist', 'youku_download_by_id']

from common import *
from ..common import *

import json
from random import randint
Expand Down Expand Up @@ -198,4 +198,4 @@ def youku_download_playlist(url, output_dir = '.', merge = True, info_only = Fal
download_playlist = youku_download_playlist

if __name__ == '__main__':
main('get_youku.py', youku_download, youku_download_playlist)
script_main('youku.py', youku_download, youku_download_playlist)
6 changes: 3 additions & 3 deletions get_youtube.py → you_get/downloader/youtube.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env python3
#!/usr/bin/env python

__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):
try:
Expand Down Expand Up @@ -33,4 +33,4 @@ def youtube_download(url, output_dir = '.', merge = True, info_only = False):
download_playlist = playlist_not_supported('youtube')

if __name__ == '__main__':
main('get_youtube.py', youtube_download)
script_main('youtube.py', youtube_download)
43 changes: 21 additions & 22 deletions get.py → you_get/main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#!/usr/bin/env python3
#!/usr/bin/env python

from common import *
import get_tudou
import get_yinyuetai
import get_youku
import get_youtube
__all__ = ['any_download', 'any_download_playlist']

from .downloader import *
from .common import *

def url_to_module(url):
site = r1(r'http://([^/]+)/', url)
Expand All @@ -17,22 +16,22 @@ def url_to_module(url):

k = r1(r'([^.]+)', domain)
downloads = {
'youtube': get_youtube,
'youku': get_youku,
'yinyuetai': get_yinyuetai,
'tudou': get_tudou,
'youtube': youtube,
'youku': youku,
'yinyuetai': yinyuetai,
'tudou': tudou,
#TODO:
# 'acfun': get_acfun,
# 'bilibili': get_bilibili,
# 'kankanews': get_bilibili,
# 'iask': get_iask,
# 'sina': get_iask,
# 'ku6': get_ku6,
# 'pptv': get_pptv,
# 'iqiyi': get_iqiyi,
# 'sohu': get_sohu,
# '56': get_w56,
# 'cntv': get_cntv,
# 'acfun': acfun,
# 'bilibili': bilibili,
# 'kankanews': bilibili,
# 'iask': iask,
# 'sina': iask,
# 'ku6': ku6,
# 'pptv': pptv,
# 'iqiyi': iqiyi,
# 'sohu': sohu,
# '56': w56,
# 'cntv': cntv,
}
if k in downloads:
return downloads[k]
Expand All @@ -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)

if __name__ == '__main__':
main('get.py', any_download, any_download_playlist)
script_main('main.py', any_download, any_download_playlist)
5 changes: 5 additions & 0 deletions you_get/processor/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

__all__ = ['concat_flvs', 'concat_mp4s']

from .merge_flv import concat_flvs
from .merge_mp4 import concat_mp4s
2 changes: 1 addition & 1 deletion merge_flv.py → you_get/processor/merge_flv.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/env python

import struct
from io import BytesIO
Expand Down
2 changes: 1 addition & 1 deletion merge_mp4.py → you_get/processor/merge_mp4.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!/usr/bin/env python

# reference: c041828_ISO_IEC_14496-12_2005(E).pdf

Expand Down

0 comments on commit 70cb82b

Please sign in to comment.