Skip to content

Open-source download manager & offline media toolbox for YouTube, music, social media, learning platforms & 1,800+ sites. Built with Tauri 2.0, Rust & Svelte.

936 B
Raw Blame
use std::sync::Arc;

use crate::platforms::traits::PlatformDownloader;

pub struct PlatformRegistry {
    platforms: Vec<Arc<dyn PlatformDownloader>>,
}

impl PlatformRegistry {
    pub fn new() -> Self {
        Self {
            platforms: Vec::new(),
        }
    }

    pub fn register(&mut self, platform: Arc<dyn PlatformDownloader>) {
        self.platforms.push(platform);
    }

    pub fn find_platform(&self, url: &str) -> Option<Arc<dyn PlatformDownloader>> {
        self.platforms.iter().find(|p| p.can_handle(url)).cloned()
    }

    /// Downloader pelo nome (`"direct_file"`, `"generic"`…), para quando a
    /// escolha vem de uma sondagem e não de `can_handle`.
    pub fn find_by_name(&self, name: &str) -> Option<Arc<dyn PlatformDownloader>> {
        self.platforms.iter().find(|p| p.name() == name).cloned()
    }
}

impl Default for PlatformRegistry {
    fn default() -> Self {
        Self::new()
    }
}