lavalink_rs/python/model/
search.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
use crate::error::LavalinkError;
use crate::model::search::*;

use pyo3::prelude::*;

#[pymodule]
pub fn search(_py: Python<'_>, m: &Bound<'_, PyModule>) -> PyResult<()> {
    m.add_class::<SearchEngines>()?;
    m.add_class::<SpotifyRecommendedParameters>()?;
    m.add_class::<FloweryTTSParameters>()?;

    Ok(())
}

#[pymethods]
impl SpotifyRecommendedParameters {
    #[new]
    fn new_py() -> SpotifyRecommendedParameters {
        SpotifyRecommendedParameters::default()
    }
}

#[pymethods]
impl FloweryTTSParameters {
    #[new]
    fn new_py() -> FloweryTTSParameters {
        FloweryTTSParameters::default()
    }
}

#[pyclass]
pub(crate) struct SearchEngines;

#[pymethods]
impl SearchEngines {
    #[staticmethod]
    fn youtube(query: String) -> String {
        crate::model::search::SearchEngines::YouTube
            .to_query(&query)
            .unwrap()
    }
    #[staticmethod]
    fn youtube_music(query: String) -> String {
        crate::model::search::SearchEngines::YouTubeMusic
            .to_query(&query)
            .unwrap()
    }
    #[staticmethod]
    fn soundcloud(query: String) -> String {
        crate::model::search::SearchEngines::SoundCloud
            .to_query(&query)
            .unwrap()
    }
    #[staticmethod]
    fn spotify(query: String) -> String {
        crate::model::search::SearchEngines::Spotify
            .to_query(&query)
            .unwrap()
    }
    #[staticmethod]
    fn spotify_recommended(
        query: String,
        parameters: SpotifyRecommendedParameters,
    ) -> Result<String, LavalinkError> {
        crate::model::search::SearchEngines::SpotifyRecommended(parameters).to_query(&query)
    }
    #[staticmethod]
    fn apple_music(query: String) -> String {
        crate::model::search::SearchEngines::AppleMusic
            .to_query(&query)
            .unwrap()
    }
    #[staticmethod]
    fn deezer(query: String) -> String {
        crate::model::search::SearchEngines::Deezer
            .to_query(&query)
            .unwrap()
    }
    #[staticmethod]
    fn deezer_isrc(query: String) -> String {
        crate::model::search::SearchEngines::DeezerISRC
            .to_query(&query)
            .unwrap()
    }
    #[staticmethod]
    fn yandex_music(query: String) -> String {
        crate::model::search::SearchEngines::YandexMusic
            .to_query(&query)
            .unwrap()
    }
    #[staticmethod]
    fn flowery_tts(
        query: String,
        parameters: FloweryTTSParameters,
    ) -> Result<String, LavalinkError> {
        crate::model::search::SearchEngines::FloweryTTS(parameters).to_query(&query)
    }
}