feat(apm): add Aira Package Manager with rotating spinner & youtube module v1.4.6
This commit is contained in:
1 parent
960a8fc91f
commit
cea8982b0f
4 files changed
+280
-3
No files matched your search
@@ -34,6 +34,7 @@ import "<module_name>";
|
|||||||
| 14 | [`sqlite`](./sqlite.md) | Database | Lightweight embedded SQL relational database | `open()`, `query()`, `execute()`, `close()` |
|
| 14 | [`sqlite`](./sqlite.md) | Database | Lightweight embedded SQL relational database | `open()`, `query()`, `execute()`, `close()` |
|
||||||
| 15 | [`net`](./net.md) | Networking | Host pings, TCP port checks, and IP discovery | `ping()`, `port_open()`, `local_ip()`, `fetch()` |
|
| 15 | [`net`](./net.md) | Networking | Host pings, TCP port checks, and IP discovery | `ping()`, `port_open()`, `local_ip()`, `fetch()` |
|
||||||
| 16 | [`thread`](./thread.md) | Concurrency | Thread spawning, worker pools, and parallel execution | `spawn()`, `join()`, `pool()`, `sleep()` |
|
| 16 | [`thread`](./thread.md) | Concurrency | Thread spawning, worker pools, and parallel execution | `spawn()`, `join()`, `pool()`, `sleep()` |
|
||||||
|
| 17 | [`youtube`](./youtube.md) / `yt` | Media & Video | YouTube video/audio download engine via APM with progressive stream resolution | `get()`, `stream()`, `download()`, `title`, `duration` |
|
||||||
|
|
||||||
---
|
---
|
||||||
*Maintained by the AiraLang Core Engineering Team. Created by Adam Eehan.*
|
*Maintained by the AiraLang Core Engineering Team. Created by Adam Eehan.*
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
# 🎬 AiraLang `youtube` Module
|
||||||
|
> **YouTube Video and Audio Downloader Engine (via APM)**
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
```bash
|
||||||
|
aira install youtube
|
||||||
|
# or
|
||||||
|
airalang install youtube
|
||||||
|
```
|
||||||
|
|
||||||
|
## Import
|
||||||
|
```aira
|
||||||
|
import "youtube";
|
||||||
|
// or alias:
|
||||||
|
import "yt";
|
||||||
|
```
|
||||||
|
|
||||||
|
## Methods & Properties
|
||||||
|
- `youtube.get(url)`: Fetches video metadata and returns a `video` object.
|
||||||
|
- `video.title`: Video title string.
|
||||||
|
- `video.duration`: Duration in seconds.
|
||||||
|
- `video.author`: Channel / uploader name.
|
||||||
|
- `video.views`: Video view count.
|
||||||
|
- `video.stream(format)`: Returns a `stream` object (format can be `"mp4"` or `"mp3"`).
|
||||||
|
- `stream.download([save_path])`: Downloads the stream to specified file or default title.
|
||||||
|
- `os.save(filename)`: Configures and creates the destination file path.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
```aira
|
||||||
|
import "youtube";
|
||||||
|
import "os";
|
||||||
|
|
||||||
|
let url = input("Enter Your URL Here : ");
|
||||||
|
|
||||||
|
let video = youtube.get(url);
|
||||||
|
say "Video Title : " + video.title;
|
||||||
|
|
||||||
|
let stream = video.stream("mp4");
|
||||||
|
|
||||||
|
let save = os.save("video.mp4");
|
||||||
|
|
||||||
|
say "Starting Download...";
|
||||||
|
stream.download(save);
|
||||||
|
|
||||||
|
say "Download Finished Successfully!";
|
||||||
|
```
|
||||||
+103
-1
@@ -1,5 +1,8 @@
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
import time
|
||||||
|
import json
|
||||||
|
import threading
|
||||||
|
|
||||||
# Cross-platform UTF-8 Console and ANSI Color configuration
|
# Cross-platform UTF-8 Console and ANSI Color configuration
|
||||||
if sys.platform == "win32":
|
if sys.platform == "win32":
|
||||||
@@ -23,7 +26,7 @@ from lexer import Lexer
|
|||||||
from parser import Parser
|
from parser import Parser
|
||||||
from evaluator import Evaluator
|
from evaluator import Evaluator
|
||||||
|
|
||||||
VERSION = "1.4.5 (Aira Self-Healing AI Compiler Edition)"
|
VERSION = "1.4.6 (Aira Package Manager & YouTube Edition)"
|
||||||
AUTHOR = "Adam Eehan (Aira Group of Technology)"
|
AUTHOR = "Adam Eehan (Aira Group of Technology)"
|
||||||
|
|
||||||
ASCII_BANNER = f"""\033[1;36m
|
ASCII_BANNER = f"""\033[1;36m
|
||||||
@@ -291,6 +294,96 @@ def revoke_ai_api_key():
|
|||||||
|
|
||||||
prompt_developer_for_ai_key()
|
prompt_developer_for_ai_key()
|
||||||
|
|
||||||
|
class AiraSpinner:
|
||||||
|
def __init__(self, message="Processing..."):
|
||||||
|
self.message = message
|
||||||
|
self.stop_running = False
|
||||||
|
self.thread = None
|
||||||
|
self.frames = ["⢿", "⣻", "⣽", "⣾", "⣷", "⣯", "⣟", "⡿"]
|
||||||
|
|
||||||
|
def _spin(self):
|
||||||
|
i = 0
|
||||||
|
while not self.stop_running:
|
||||||
|
f = self.frames[i % len(self.frames)]
|
||||||
|
sys.stdout.write(f"\r\033[1;36m {f}\033[0m {self.message}")
|
||||||
|
sys.stdout.flush()
|
||||||
|
time.sleep(0.08)
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
def __enter__(self):
|
||||||
|
self.stop_running = False
|
||||||
|
self.thread = threading.Thread(target=self._spin, daemon=True)
|
||||||
|
self.thread.start()
|
||||||
|
return self
|
||||||
|
|
||||||
|
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||||
|
self.stop_running = True
|
||||||
|
if self.thread:
|
||||||
|
self.thread.join(timeout=0.3)
|
||||||
|
sys.stdout.write("\r\033[K")
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
def install_package(pkg_name):
|
||||||
|
pkg_name = pkg_name.lower().strip()
|
||||||
|
print(f"\033[1;36m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\033[0m")
|
||||||
|
print(f"\033[1;35m📦 [Aira Package Manager (APM v1.0)]\033[0m")
|
||||||
|
print(f"\033[1;36m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\033[0m")
|
||||||
|
|
||||||
|
with AiraSpinner(f"Resolving package '{pkg_name}' from Aira Package Registry..."):
|
||||||
|
time.sleep(0.8)
|
||||||
|
print(f" \033[1;32m[✓]\033[0m Package \033[1;33m{pkg_name}\033[0m resolved successfully.")
|
||||||
|
|
||||||
|
if pkg_name in ("youtube", "yt"):
|
||||||
|
with AiraSpinner("Verifying engine dependencies (yt-dlp)..."):
|
||||||
|
import subprocess
|
||||||
|
try:
|
||||||
|
import yt_dlp
|
||||||
|
engine_ready = True
|
||||||
|
except ImportError:
|
||||||
|
engine_ready = False
|
||||||
|
time.sleep(0.4)
|
||||||
|
|
||||||
|
if engine_ready:
|
||||||
|
print(" \033[1;32m[✓]\033[0m Backend engine yt-dlp is ready.")
|
||||||
|
else:
|
||||||
|
with AiraSpinner("Installing yt-dlp backend engine via pip..."):
|
||||||
|
subprocess.check_call([sys.executable, "-m", "pip", "install", "yt-dlp"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||||
|
print(" \033[1;32m[✓]\033[0m Backend engine installed successfully.")
|
||||||
|
|
||||||
|
with AiraSpinner("Configuring package registry and setting up permissions..."):
|
||||||
|
config_dir = os.path.expanduser("~/.config/airalang")
|
||||||
|
os.makedirs(config_dir, exist_ok=True)
|
||||||
|
packages_file = os.path.join(config_dir, "installed_packages.json")
|
||||||
|
packages = {}
|
||||||
|
if os.path.exists(packages_file):
|
||||||
|
try:
|
||||||
|
with open(packages_file, "r", encoding="utf-8") as f:
|
||||||
|
packages = json.load(f)
|
||||||
|
except Exception:
|
||||||
|
packages = {}
|
||||||
|
packages["youtube"] = {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"installed_at": time.time(),
|
||||||
|
"description": "YouTube video and audio download engine for AiraLang"
|
||||||
|
}
|
||||||
|
packages["yt"] = packages["youtube"]
|
||||||
|
with open(packages_file, "w", encoding="utf-8") as f:
|
||||||
|
json.dump(packages, f, indent=2)
|
||||||
|
time.sleep(0.5)
|
||||||
|
|
||||||
|
print(f" \033[1;32m[✓]\033[0m Module '{pkg_name}' registered in APM.")
|
||||||
|
print(f"\n\033[1;32m✨ Successfully installed '{pkg_name}' v1.0.0!\033[0m")
|
||||||
|
print(f"\033[1;36m💡 Usage in your .aira scripts:\033[0m")
|
||||||
|
print(f" import \"youtube\";")
|
||||||
|
print(f" let video = youtube.get(url);")
|
||||||
|
print(f" let stream = video.stream(\"mp4\");")
|
||||||
|
print(f" let save = os.save(\"video.mp4\");")
|
||||||
|
print(f" stream.download(save);")
|
||||||
|
print(f"\033[1;36m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\033[0m")
|
||||||
|
else:
|
||||||
|
print(f" \033[1;31m[✗]\033[0m Package '{pkg_name}' not found in Aira Package Registry.")
|
||||||
|
print(f"Available packages: youtube (yt)")
|
||||||
|
|
||||||
def print_help():
|
def print_help():
|
||||||
print(f"""\033[1;36mAiraLang v{VERSION}\033[0m
|
print(f"""\033[1;36mAiraLang v{VERSION}\033[0m
|
||||||
Creator: {AUTHOR}
|
Creator: {AUTHOR}
|
||||||
@@ -299,6 +392,8 @@ Creator: {AUTHOR}
|
|||||||
airalang Start interactive REPL
|
airalang Start interactive REPL
|
||||||
airalang <script.aira> Execute an AiraLang script
|
airalang <script.aira> Execute an AiraLang script
|
||||||
airalang run <script.aira> Execute an AiraLang script
|
airalang run <script.aira> Execute an AiraLang script
|
||||||
|
airalang install <package> Install a module via Aira Package Manager (APM)
|
||||||
|
aira install <package> Install a module via Aira Package Manager (APM)
|
||||||
airalang build <file.aira> [-o out] Compile script to standalone executable
|
airalang build <file.aira> [-o out] Compile script to standalone executable
|
||||||
airalang new <project_name> Create a new AiraLang project scaffold
|
airalang new <project_name> Create a new AiraLang project scaffold
|
||||||
airalang --ai api revoke Revoke active API key and configure a fresh one
|
airalang --ai api revoke Revoke active API key and configure a fresh one
|
||||||
@@ -328,6 +423,13 @@ def main():
|
|||||||
print(f"AiraLang v{VERSION} | Creator: {AUTHOR}")
|
print(f"AiraLang v{VERSION} | Creator: {AUTHOR}")
|
||||||
elif arg1 in ("-h", "--help"):
|
elif arg1 in ("-h", "--help"):
|
||||||
print_help()
|
print_help()
|
||||||
|
elif arg1 in ("install", "i", "add"):
|
||||||
|
if len(sys.argv) > 2:
|
||||||
|
install_package(sys.argv[2])
|
||||||
|
sys.exit(0)
|
||||||
|
else:
|
||||||
|
print("\033[1;31m[!] Error: Specify package name: airalang install <package_name>\033[0m")
|
||||||
|
sys.exit(1)
|
||||||
elif arg1 in ("--ai-setup", "--setup-ai"):
|
elif arg1 in ("--ai-setup", "--setup-ai"):
|
||||||
from stdlib_modules import prompt_developer_for_ai_key
|
from stdlib_modules import prompt_developer_for_ai_key
|
||||||
prompt_developer_for_ai_key()
|
prompt_developer_for_ai_key()
|
||||||
|
|||||||
+130
-2
@@ -170,13 +170,21 @@ def create_file_module():
|
|||||||
return os.path.getsize(path)
|
return os.path.getsize(path)
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
|
def save_path(filepath):
|
||||||
|
path_str = str(filepath).strip()
|
||||||
|
dir_name = os.path.dirname(path_str)
|
||||||
|
if dir_name:
|
||||||
|
os.makedirs(dir_name, exist_ok=True)
|
||||||
|
return path_str
|
||||||
|
|
||||||
return AiraModule("file", {
|
return AiraModule("file", {
|
||||||
"read": read_file,
|
"read": read_file,
|
||||||
"write": write_file,
|
"write": write_file,
|
||||||
"append": append_file,
|
"append": append_file,
|
||||||
"exists": exists,
|
"exists": exists,
|
||||||
"delete": delete,
|
"delete": delete,
|
||||||
"size": size
|
"size": size,
|
||||||
|
"save": save_path
|
||||||
})
|
})
|
||||||
|
|
||||||
def create_os_module():
|
def create_os_module():
|
||||||
@@ -199,6 +207,13 @@ def create_os_module():
|
|||||||
os.makedirs(path, exist_ok=True)
|
os.makedirs(path, exist_ok=True)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def save_path(filepath):
|
||||||
|
path_str = str(filepath).strip()
|
||||||
|
dir_name = os.path.dirname(path_str)
|
||||||
|
if dir_name:
|
||||||
|
os.makedirs(dir_name, exist_ok=True)
|
||||||
|
return path_str
|
||||||
|
|
||||||
def get_args():
|
def get_args():
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
raw = sys.argv[1:]
|
raw = sys.argv[1:]
|
||||||
@@ -222,6 +237,7 @@ def create_os_module():
|
|||||||
"getcwd": cwd,
|
"getcwd": cwd,
|
||||||
"listdir": listdir,
|
"listdir": listdir,
|
||||||
"mkdir": mkdir,
|
"mkdir": mkdir,
|
||||||
|
"save": save_path,
|
||||||
"args": get_args,
|
"args": get_args,
|
||||||
"argv": get_args,
|
"argv": get_args,
|
||||||
"exit": exit_app,
|
"exit": exit_app,
|
||||||
@@ -1671,6 +1687,116 @@ def create_system_module():
|
|||||||
"cpu": get_cpu
|
"cpu": get_cpu
|
||||||
})
|
})
|
||||||
|
|
||||||
|
def is_package_installed(pkg_name):
|
||||||
|
config_dir = os.path.expanduser("~/.config/airalang")
|
||||||
|
packages_file = os.path.join(config_dir, "installed_packages.json")
|
||||||
|
if os.path.exists(packages_file):
|
||||||
|
try:
|
||||||
|
with open(packages_file, "r", encoding="utf-8") as f:
|
||||||
|
pkgs = json.load(f)
|
||||||
|
return pkg_name.lower() in pkgs
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
return False
|
||||||
|
|
||||||
|
def create_youtube_module():
|
||||||
|
if not is_package_installed("youtube") and not is_package_installed("yt"):
|
||||||
|
raise ImportError(
|
||||||
|
"\033[1;31m[AiraLang Package Error]:\033[0m Module 'youtube' is not installed!\n"
|
||||||
|
"\033[1;36m💡 Run:\033[0m aira install youtube"
|
||||||
|
)
|
||||||
|
try:
|
||||||
|
import yt_dlp
|
||||||
|
except ImportError:
|
||||||
|
raise ImportError(
|
||||||
|
"\033[1;31m[AiraLang Package Error]:\033[0m Backend engine 'yt-dlp' is missing.\n"
|
||||||
|
"\033[1;36m💡 Run:\033[0m aira install youtube"
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_video(url):
|
||||||
|
url_str = str(url).strip()
|
||||||
|
ydl_opts = {
|
||||||
|
'quiet': True,
|
||||||
|
'no_warnings': True,
|
||||||
|
'extract_flat': True,
|
||||||
|
'skip_download': True,
|
||||||
|
'extractor_args': {'youtube': {'player_client': ['android', 'ios', 'web']}}
|
||||||
|
}
|
||||||
|
try:
|
||||||
|
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
||||||
|
info = ydl.extract_info(url_str, download=False)
|
||||||
|
except Exception as e:
|
||||||
|
raise RuntimeError(f"Aira YouTube Error: Failed to fetch video info: {e}")
|
||||||
|
|
||||||
|
title = info.get("title", "YouTube Video")
|
||||||
|
duration = info.get("duration", 0)
|
||||||
|
author = info.get("uploader", info.get("channel", "Unknown Channel"))
|
||||||
|
views = info.get("view_count", 0)
|
||||||
|
|
||||||
|
def get_stream(fmt="mp4"):
|
||||||
|
fmt_str = str(fmt).lower().strip()
|
||||||
|
|
||||||
|
def download(save_path=None):
|
||||||
|
if save_path:
|
||||||
|
outtmpl = str(save_path).strip()
|
||||||
|
else:
|
||||||
|
outtmpl = f"{title}.%(ext)s"
|
||||||
|
|
||||||
|
parent_dir = os.path.dirname(outtmpl)
|
||||||
|
if parent_dir:
|
||||||
|
os.makedirs(parent_dir, exist_ok=True)
|
||||||
|
|
||||||
|
if fmt_str in ("mp3", "audio", "m4a"):
|
||||||
|
ydl_dl_opts = {
|
||||||
|
'format': 'bestaudio/best/140/251',
|
||||||
|
'outtmpl': outtmpl,
|
||||||
|
'quiet': False,
|
||||||
|
'no_warnings': True,
|
||||||
|
'extractor_args': {'youtube': {'player_client': ['android', 'ios', 'web']}}
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
ydl_dl_opts = {
|
||||||
|
'format': 'best[ext=mp4]/18/22/b/best',
|
||||||
|
'outtmpl': outtmpl,
|
||||||
|
'quiet': False,
|
||||||
|
'no_warnings': True,
|
||||||
|
'extractor_args': {'youtube': {'player_client': ['android', 'ios', 'web']}}
|
||||||
|
}
|
||||||
|
|
||||||
|
try:
|
||||||
|
with yt_dlp.YoutubeDL(ydl_dl_opts) as dl:
|
||||||
|
dl.download([url_str])
|
||||||
|
return outtmpl
|
||||||
|
except Exception as e:
|
||||||
|
raise RuntimeError(f"Aira YouTube Download Error: {e}")
|
||||||
|
|
||||||
|
return AiraModule("youtube_stream", {
|
||||||
|
"download": download,
|
||||||
|
"format": fmt_str
|
||||||
|
})
|
||||||
|
|
||||||
|
return AiraModule("youtube_video", {
|
||||||
|
"title": title,
|
||||||
|
"duration": duration,
|
||||||
|
"author": author,
|
||||||
|
"uploader": author,
|
||||||
|
"views": views,
|
||||||
|
"url": url_str,
|
||||||
|
"stream": get_stream
|
||||||
|
})
|
||||||
|
|
||||||
|
def quick_download(url, save_path=None, fmt="mp4"):
|
||||||
|
video = get_video(url)
|
||||||
|
st = video.get("stream")(fmt)
|
||||||
|
return st.get("download")(save_path)
|
||||||
|
|
||||||
|
return AiraModule("youtube", {
|
||||||
|
"get": get_video,
|
||||||
|
"video": get_video,
|
||||||
|
"url": get_video,
|
||||||
|
"download": quick_download
|
||||||
|
})
|
||||||
|
|
||||||
BUILTIN_MODULES = {
|
BUILTIN_MODULES = {
|
||||||
"file": create_file_module,
|
"file": create_file_module,
|
||||||
"os": create_os_module,
|
"os": create_os_module,
|
||||||
@@ -1689,6 +1815,8 @@ BUILTIN_MODULES = {
|
|||||||
"android": create_android_module,
|
"android": create_android_module,
|
||||||
"droidsec": create_android_module,
|
"droidsec": create_android_module,
|
||||||
"system": create_system_module,
|
"system": create_system_module,
|
||||||
"hardware": create_system_module
|
"hardware": create_system_module,
|
||||||
|
"youtube": create_youtube_module,
|
||||||
|
"yt": create_youtube_module
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference in new issue
Block a user