diff --git a/README.md b/README.md index 6d70e0a..0d808d7 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,8 @@ video_object.download(downloader=threaded, quality=Quality.BEST, path="your_outp # SEE DOCUMENTATION FOR MORE ``` +> [!NOTE] +> XVideos API can also be used from the command line. Do: xvideos_api -h to see the options # Changelog See [Changelog](https://github.com/EchterAlsFake/xvideos_api/blob/master/README/Changelog.md) for more details. diff --git a/setup.py b/setup.py index 5e2091b..a8d2933 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ "requests", "bs4", "lxml", "ffmpeg-progress-yield", "eaf_base_api" ], entry_points={ - 'console_scripts': [ + 'console_scripts': ['xvideos_api=xvideos_api.xvideos_api:main' # If you want to create any executable scripts ], }, diff --git a/xvideos_api/xvideos_api.py b/xvideos_api/xvideos_api.py index 551d6bc..d75f3ad 100644 --- a/xvideos_api/xvideos_api.py +++ b/xvideos_api/xvideos_api.py @@ -18,6 +18,7 @@ import json import html import logging +import argparse from bs4 import BeautifulSoup from functools import cached_property @@ -294,3 +295,35 @@ def search(cls, query, sorting_Sort: Sort = Sort.Sort_relevance, sorting_Date: S for id in urls: yield Video(id) + + +def main(): + parser = argparse.ArgumentParser(description="API Command Line Interface") + parser.add_argument("--download", type=str, help="URL to download from") + parser.add_argument("--quality", type=str, help="The video quality (best,half,worst)") + parser.add_argument("--file", type=str, help="(Optional) Specify a file with URLs (separated with new lines)") + parser.add_argument("--downloader", type=str, help="The downloader for the segments (threaded,ffmpeg,default)") + parser.add_argument("--output", type=str, help="The output path (with filename)") + args = parser.parse_args() + + if args.download: + client = Client() + video = client.get_video(args.download) + video.download(downloader=args.downloader, quality=args.quality, path=args.output) + + if args.file: + videos = [] + client = Client() + + with open(args.file, "r") as file: + content = file.read().splitlines() + + for url in content: + videos.append(client.get_video(url)) + + for video in videos: + video.download(quality=args.quality, downloader=args.downloader, path=args.output) + + +if __name__ == "__main__": + main()