|
1 | 1 | # pylint: disable=useless-import-alias
|
2 | 2 |
|
3 |
| -from .monsnode_parser import MonsnodeParser as MonsnodeParser |
4 |
| -from .platform_video_downloader import \ |
5 |
| - PlatformVideoDownloader as PlatformVideoDownloader |
6 |
| -from .twitter_crawler import TwitterCrawler as TwitterCrawler |
| 3 | +from typing import Optional |
| 4 | + |
| 5 | +import typer |
| 6 | +from rich import print as rich_print |
| 7 | + |
7 | 8 | from .twitter_video_tools import TwitterVideoTools as TwitterVideoTools
|
8 |
| -from .video_downloader import VideoDownloader as VideoDownloader |
| 9 | +from .utils import URLValidator |
| 10 | + |
| 11 | + |
| 12 | +def _cli_main( |
| 13 | + link: str = typer.Argument(..., help='Video tweet link or target user\'s likes or media.'), |
| 14 | + username: Optional[str] = typer.Option(None, help='Your twitter credentials username.'), |
| 15 | + password: Optional[str] = typer.Option(None, help='Your twitter credentials password.'), |
| 16 | + until_link: Optional[str] = typer.Option( |
| 17 | + None, |
| 18 | + help='Keeps finding videos until this link is found. None for no limit. Only for user\'s likes or media.', |
| 19 | + ), |
| 20 | +) -> None: |
| 21 | + url_validator = URLValidator(link) |
| 22 | + |
| 23 | + if not url_validator.is_valid_link(): |
| 24 | + rich_print(f'\'[underline]{link}[/underline]\' [bold red]is an invalid link.[/bold red]') |
| 25 | + return |
| 26 | + twitter_video_tools = TwitterVideoTools(username, password) |
| 27 | + |
| 28 | + if url_validator.is_valid_twitter_media_link(): |
| 29 | + target_username = link.split('/')[3] |
| 30 | + twitter_video_tools.download_from_user(target_username, until_link) |
| 31 | + elif url_validator.is_valid_twitter_liked_link(): |
| 32 | + target_username = link.split('/')[3] |
| 33 | + twitter_video_tools.download_from_liked_tweets(target_username, until_link) |
| 34 | + else: |
| 35 | + twitter_video_tools.download([link]) |
| 36 | + |
| 37 | + |
| 38 | +def main() -> None: |
| 39 | + typer.run(_cli_main) |
| 40 | + |
| 41 | + |
| 42 | +__all__ = [ |
| 43 | + 'main', |
| 44 | + 'TwitterVideoTools', |
| 45 | +] |
0 commit comments