lavalink_rs/python/model/
track.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
use crate::model::track::*;

use pyo3::prelude::*;
use pythonize::{depythonize, pythonize};

#[pymodule]
pub fn track(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
    m.add_class::<TrackLoadType>()?;
    //m.add_class::<TrackLoadData>()?;
    m.add_class::<Track>()?;
    m.add_class::<TrackData>()?;
    m.add_class::<TrackInfo>()?;
    m.add_class::<PlaylistData>()?;
    m.add_class::<PlaylistInfo>()?;
    m.add_class::<TrackError>()?;

    Ok(())
}

#[pyclass(get_all, set_all)]
pub(crate) struct Track {
    pub(crate) load_type: TrackLoadType,
    pub(crate) data: Option<PyObject>,
}

#[apply(crate::python::with_getter_setter)]
#[pymethods]
impl TrackData {
    getter_setter!((encoded, String), (info, TrackInfo),);

    #[getter(plugin_info)]
    fn get_plugin_info(&self, py: Python<'_>) -> PyObject {
        pythonize(py, &self.plugin_info).unwrap()
    }

    #[setter(plugin_info)]
    fn set_plugin_info(&mut self, py: Python<'_>, input: PyObject) {
        self.plugin_info = depythonize(input.as_ref(py)).unwrap()
    }

    #[getter(user_data)]
    fn get_user_data(&self, py: Python<'_>) -> PyObject {
        pythonize(py, &self.user_data).unwrap()
    }

    #[setter(user_data)]
    fn set_user_data(&mut self, py: Python<'_>, input: PyObject) {
        self.user_data = depythonize(input.as_ref(py)).unwrap()
    }
}

#[apply(crate::python::with_getter_setter)]
#[pymethods]
impl PlaylistData {
    getter_setter!((info, PlaylistInfo), (tracks, Vec<TrackData>),);

    #[getter(plugin_info)]
    fn get_plugin_info(&self, py: Python<'_>) -> PyObject {
        pythonize(py, &self.plugin_info).unwrap()
    }

    #[setter(plugin_info)]
    fn set_plugin_info(&mut self, py: Python<'_>, input: PyObject) {
        self.plugin_info = depythonize(input.as_ref(py)).unwrap()
    }
}