diff --git a/README.md b/README.md index ef98703..221c043 100644 --- a/README.md +++ b/README.md @@ -8,17 +8,24 @@ Funny tools for downloading movies, tv serials and BLEACH comics - Automatically download latest comics BLEACH from __BLEACH__ __Baidu__ __Tieba__. - Comics will be saved in __BLEACH/[Name]__ in current directory. - No comics will be downloaded twice according to existence of __BLEACH/[Name]__. + - Automatically download TV serials from 人人影视 with given ID. + +## Requirement + +__Python 3__ ## Usage - Command line ``` -pip install funny_tool +pip3 install funny_tool ``` ``` -usage: ft [-h] [-b] [-d] [-p PAGE] +usage: ft [-h] [-b] [-d] [-p PAGE] [-t TV] [-l] + +funny_tool: Download movies, tv serials and comics! optional arguments: -h, --help show this help message and exit @@ -26,7 +33,9 @@ optional arguments: -d, --dytt Download latest movies from dytt. -p PAGE, --page PAGE pages to retrieve when downloading movies from dytt, should be used with -d. - -s, --shield Download Marvels.Agents.of.S.H.I.E.L.D. + -t TV, --tv TV Download TV serials by giving ID, use flag -l to check + IDs. + -l, --list TV serials list. ``` - Python lib @@ -36,8 +45,9 @@ import funny_tool funny_tool.bleach() funny_tool.dytt() -funny_tool.dytt(2) -funny_tool.shield() +funny_tool.dytt(2) # retrieve 2 pages +funny_tool.tv(30675) # Shield +funny_tool.tvlist() ``` ## TODO diff --git a/funny_tool/__init__.py b/funny_tool/__init__.py index 906efd3..f188aa8 100644 --- a/funny_tool/__init__.py +++ b/funny_tool/__init__.py @@ -1,6 +1,7 @@ from .bleach import BLEACH from .dytt import DYTT -from .shield import SHIELD +from .tvserials import TVSerials +from .utils.TVList import get_list def bleach(): b = BLEACH() @@ -10,6 +11,10 @@ def dytt(page = 1): d = DYTT() d.get_Latest_URLs(page) -def shield(): - s = SHIELD() - s.get_serials() +# id: String +def tv(id): + s = TVSerials() + s.get_serials(id) + +def tvlist(): + return get_list() diff --git a/funny_tool/funny_tool.py b/funny_tool/funny_tool.py index 4da4c61..9e789f8 100644 --- a/funny_tool/funny_tool.py +++ b/funny_tool/funny_tool.py @@ -1,7 +1,7 @@ from .bleach import BLEACH from .dytt import DYTT -from .shield import SHIELD -import argparse +from .tvserials import TVSerials +import os, argparse def all(): parser = argparse.ArgumentParser(description = 'funny_tool: Download movies, tv serials and comics!') @@ -9,9 +9,11 @@ def all(): parser.add_argument('-d', '--dytt', action='store_true', help='Download latest movies from dytt.') parser.add_argument('-p', '--page', action='store', type=int, default=1, help='pages to retrieve when downloading movies from dytt, should be used with -d.') - parser.add_argument('-s', '--shield', action='store_true', help='Download Marvels.Agents.of.S.H.I.E.L.D.') + parser.add_argument('-t', '--tv', action='store', type=str, help='Download TV serials by giving ID, use flag -l to check IDs.') + parser.add_argument('-l', '--list', action='store_true', help='TV serials list.') given_args = parser.parse_args() + print(''' ,----, ,/ .`| @@ -34,14 +36,19 @@ def all(): if given_args.bleach: b = BLEACH() b.get_Latest_URLs() - + if given_args.dytt: t = DYTT() t.get_Latest_URLs(given_args.page) - - if given_args.shield: - s = SHIELD() - s.get_serials() - - if given_args.bleach == False and given_args.dytt == False and given_args.shield == False: + + if given_args.tv: + s = TVSerials() + s.get_serials(given_args.tv) + + if given_args.list: + from .utils.TVList import get_list + tvlist = get_list() + for key in tvlist.keys(): print(key + ' ' + tvlist[key]) + + if not given_args.bleach and not given_args.dytt and not given_args.tv and not given_args.list: parser.print_help() diff --git a/funny_tool/shield.py b/funny_tool/tvserials.py similarity index 80% rename from funny_tool/shield.py rename to funny_tool/tvserials.py index c53fd97..14d1381 100644 --- a/funny_tool/shield.py +++ b/funny_tool/tvserials.py @@ -1,16 +1,15 @@ from bs4 import BeautifulSoup from tqdm import tqdm from .utils.rrys_login import RRYS_Login -import os, time +from .utils.TVList import get_list +import os, time, re -class SHIELD(object): +class TVSerials(object): def __init__(self): self.prefix = 'http://www.zimuzu.tv/' self.type = 'HR-HDTV' - self.logfile = 'SHIELD.txt' self.link = ['迅雷'] # '电驴','网盘','城通' - self.path = os.getcwd() + '/' + self.logfile ''' Calculate shows to download @@ -24,15 +23,24 @@ def calculate(self, list, last = 'S00E00'): return latest_index - last_index ''' - Extract 'S.H.I.E.L.D.' TOTD: should replace with regex. + Extract S??E?? ''' def extract_string(self, string): - return string[string.find("S.H.I.E.L.D.") + 12: string.find("S.H.I.E.L.D.") + 18] + return re.search('(S\d{2}E\d{2})\.', string).groups()[0] ''' Get info from tv play list ''' - def get_serials(self, sersials_id = '30675'): + def get_serials(self, sersials_id): + tvlist = get_list() + if sersials_id not in tvlist.keys(): + print('No TV serials for such a id.') + return + + self.logfile = tvlist[sersials_id] + '.txt' + self.path = os.getcwd() + '/' + self.logfile + print('TV : Starting to download ' + tvlist[sersials_id]) + # Get last num log = open(self.path, 'a+') log.seek(0) @@ -74,4 +82,4 @@ def get_serials(self, sersials_id = '30675'): log.close() # Close bar progress_bar.close() - print('SHIELD: Download finished! ' + str(count) + ' tv serials downloaded. Check SHIELD.txt.') + print('TV : Download finished! ' + str(count) + ' tv serials downloaded. Check ' + self.logfile) diff --git a/funny_tool/utils/TVList.py b/funny_tool/utils/TVList.py new file mode 100644 index 0000000..1777eff --- /dev/null +++ b/funny_tool/utils/TVList.py @@ -0,0 +1,5 @@ +def get_list(): + return { + '30675': 'S.H.I.E.L.D', + '31801': 'Silicon Valley' + } diff --git a/setup.py b/setup.py index d2ed87d..84bf4e2 100644 --- a/setup.py +++ b/setup.py @@ -9,10 +9,15 @@ except ImportError: from distutils.core import setup +README = '' +with open('README.md', mode='r', encoding='utf-8') as rdm: + README = rdm.read() + setup( name='funny_tool', - version='0.2.3', + version='0.2.5', description='The funny tools to download movies and comics', + long_description=README, author='CCharlieLi', author_email='ccharlieli@live.com', url='https://github.com/CCharlieLi/funny_tool', @@ -30,7 +35,6 @@ 'Environment :: Console', 'Intended Audience :: End Users/Desktop', 'License :: OSI Approved :: MIT License', - 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Operating System :: MacOS :: MacOS X', 'Operating System :: Microsoft :: Windows', diff --git a/usage.png b/usage.png index be47b7c..18cccd7 100644 Binary files a/usage.png and b/usage.png differ