Skip to content
This repository was archived by the owner on Apr 17, 2023. It is now read-only.

Commit 748bc55

Browse files
committed
Add cli support
1 parent 0c5b614 commit 748bc55

File tree

2 files changed

+46
-5
lines changed

2 files changed

+46
-5
lines changed

twitter_video_tools/__init__.py

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,45 @@
11
# pylint: disable=useless-import-alias
22

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+
78
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+
]

twitter_video_tools/__main__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import twitter_video_tools
2+
3+
if __name__ == '__main__':
4+
twitter_video_tools.main()

0 commit comments

Comments
 (0)