|
| 1 | +import argparse |
| 2 | +import os |
| 3 | +from pathlib import Path |
| 4 | +from typing import List, Callable |
| 5 | +from .arguments import Arguments |
| 6 | + |
| 7 | +from .. exceptions import InvalidVideoIdException, NoContentsException |
| 8 | +from .. processors.tsv_archiver import TSVArchiver |
| 9 | +from .. processors.html_archiver import HTMLArchiver |
| 10 | +from .. tool.extract.extractor import Extractor |
| 11 | +from .. tool.videoinfo import VideoInfo |
| 12 | +from .. import __version__ |
| 13 | + |
| 14 | +''' |
| 15 | +Most of CLI modules refer to |
| 16 | +Petter Kraabøl's Twitch-Chat-Downloader |
| 17 | +https://github.com/PetterKraabol/Twitch-Chat-Downloader |
| 18 | +(MIT License) |
| 19 | +
|
| 20 | +''' |
| 21 | +def main(): |
| 22 | + # Arguments |
| 23 | + parser = argparse.ArgumentParser(description=f'pytchat v{__version__}') |
| 24 | + parser.add_argument('-v', f'--{Arguments.Name.VIDEO}', type=str, |
| 25 | + help='Video IDs separated by commas without space') |
| 26 | + parser.add_argument('-o', f'--{Arguments.Name.OUTPUT}', type=str, |
| 27 | + help='Output directory (end with "/")', default='./') |
| 28 | + parser.add_argument(f'--{Arguments.Name.VERSION}', action='store_true', |
| 29 | + help='Settings version') |
| 30 | + Arguments(parser.parse_args().__dict__) |
| 31 | + if Arguments().print_version: |
| 32 | + print(f'pytchat v{__version__}') |
| 33 | + return |
| 34 | + |
| 35 | + # Extractor |
| 36 | + if Arguments().video_ids: |
| 37 | + for video_id in Arguments().video_ids: |
| 38 | + try: |
| 39 | + info = VideoInfo(video_id) |
| 40 | + print(f"Extracting...\n" |
| 41 | + f" video_id: {video_id}\n" |
| 42 | + f" channel: {info.get_channel_name()}\n" |
| 43 | + f" title: {info.get_title()}") |
| 44 | + Extractor(video_id, |
| 45 | + processor = HTMLArchiver(Arguments().output+video_id+'.html') |
| 46 | + ).extract() |
| 47 | + print("Extraction end.\n") |
| 48 | + except (InvalidVideoIdException, NoContentsException) as e: |
| 49 | + print(e) |
| 50 | + return |
| 51 | + parser.print_help() |
0 commit comments