1- use librespot;
21use cpython:: { PyResult , Python , PythonObject } ;
3- use pyfuture:: PyFuture ;
42use futures;
3+ use librespot;
4+ use pyfuture:: PyFuture ;
5+ use tokio_core:: reactor:: Remote ;
56use SpotifyId ;
67
78py_class ! ( pub class Track |py| {
89 data session : librespot:: session:: Session ;
10+ data handle : Remote ;
911 data track : librespot:: metadata:: Track ;
1012
1113 def id( & self ) -> PyResult <SpotifyId > {
@@ -18,20 +20,23 @@ py_class!(pub class Track |py| {
1820
1921 def album( & self ) -> PyResult <PyFuture > {
2022 let session = self . session( py) . clone( ) ;
23+ let handle = self . handle( py) . clone( ) ;
2124 let album = self . track( py) . album;
2225
23- Album :: get( py, session, album)
26+ Album :: get( py, session, handle , album)
2427 }
2528
2629 def artists( & self ) -> PyResult <PyFuture > {
2730 let session = self . session( py) . clone( ) ;
31+ let handle = self . handle( py) . clone( ) ;
2832 let artists = self . track( py) . artists. clone( ) ;
29- Artist :: get_all( py, session, artists)
33+ Artist :: get_all( py, session, handle , artists)
3034 }
3135} ) ;
3236
3337py_class ! ( pub class Album |py| {
3438 data session : librespot:: session:: Session ;
39+ data handle : Remote ;
3540 data album : librespot:: metadata:: Album ;
3641
3742 def id( & self ) -> PyResult <SpotifyId > {
@@ -44,19 +49,22 @@ py_class!(pub class Album |py| {
4449
4550 def artists( & self ) -> PyResult <PyFuture > {
4651 let session = self . session( py) . clone( ) ;
52+ let handle = self . handle( py) . clone( ) ;
4753 let artists = self . album( py) . artists. clone( ) ;
48- Artist :: get_all( py, session, artists)
54+ Artist :: get_all( py, session, handle , artists)
4955 }
5056
5157 def tracks( & self ) -> PyResult <PyFuture > {
5258 let session = self . session( py) . clone( ) ;
59+ let handle = self . handle( py) . clone( ) ;
5360 let artists = self . album( py) . tracks. clone( ) ;
54- Track :: get_all( py, session, artists)
61+ Track :: get_all( py, session, handle , artists)
5562 }
5663} ) ;
5764
5865py_class ! ( pub class Artist |py| {
5966 data _session : librespot:: session:: Session ;
67+ data _handle : Remote ;
6068 data artist : librespot:: metadata:: Artist ;
6169
6270 def id( & self ) -> PyResult <SpotifyId > {
@@ -70,6 +78,7 @@ py_class!(pub class Artist |py| {
7078
7179fn get < T , F , O > ( py : Python ,
7280 session : librespot:: session:: Session ,
81+ handle : Remote ,
7382 id : librespot:: util:: SpotifyId ,
7483 create_instance : F ) -> PyResult < PyFuture >
7584 where
@@ -78,13 +87,14 @@ fn get<T, F, O>(py: Python,
7887 O : PythonObject
7988{
8089 let future = session. metadata ( ) . get :: < T > ( id) ;
81- PyFuture :: new ( py, future, |py, result| {
82- create_instance ( py, session, result. unwrap ( ) )
90+ PyFuture :: new ( py, handle . clone ( ) , future, |py, result| {
91+ create_instance ( py, session, handle , result. unwrap ( ) )
8392 } )
8493}
8594
8695fn get_all < T , F , O , I > ( py : Python ,
8796 session : librespot:: session:: Session ,
97+ handle : Remote ,
8898 ids : I ,
8999 create_instance : F ) -> PyResult < PyFuture >
90100 where
@@ -101,10 +111,10 @@ fn get_all<T, F, O, I>(py: Python,
101111
102112 let future = futures:: future:: join_all ( futures) ;
103113
104- PyFuture :: new ( py, future, move |py, result| {
114+ PyFuture :: new ( py, handle . clone ( ) , future, move |py, result| {
105115 let objects = result. unwrap ( ) ;
106116 let objects = objects. into_iter ( ) . map ( |artist| {
107- create_instance ( py, session. clone ( ) , artist)
117+ create_instance ( py, session. clone ( ) , handle . clone ( ) , artist)
108118 } ) . collect :: < PyResult < Vec < _ > > > ( ) ?;
109119
110120 Ok ( objects)
@@ -114,53 +124,59 @@ fn get_all<T, F, O, I>(py: Python,
114124impl Track {
115125 pub fn get ( py : Python ,
116126 session : librespot:: session:: Session ,
127+ handle : Remote ,
117128 id : librespot:: util:: SpotifyId ) -> PyResult < PyFuture >
118129 {
119130 get ( py, session, id, Track :: create_instance)
120131 }
121132
122133 pub fn get_all < I > ( py : Python ,
123134 session : librespot:: session:: Session ,
135+ handle : Remote ,
124136 ids : I ) -> PyResult < PyFuture >
125137 where I : IntoIterator < Item = librespot:: util:: SpotifyId > ,
126138 I :: IntoIter : ' static
127139 {
128- get_all ( py, session, ids, Track :: create_instance)
140+ get_all ( py, session, handle , ids, Track :: create_instance)
129141 }
130142}
131143
132144impl Album {
133145 pub fn get ( py : Python ,
134146 session : librespot:: session:: Session ,
147+ handle : Remote ,
135148 id : librespot:: util:: SpotifyId ) -> PyResult < PyFuture >
136149 {
137150 get ( py, session, id, Album :: create_instance)
138151 }
139152
140153 pub fn get_all < I > ( py : Python ,
141154 session : librespot:: session:: Session ,
155+ handle : Remote ,
142156 ids : I ) -> PyResult < PyFuture >
143157 where I : IntoIterator < Item = librespot:: util:: SpotifyId > ,
144158 I :: IntoIter : ' static
145159 {
146- get_all ( py, session, ids, Album :: create_instance)
160+ get_all ( py, session, handle , ids, Album :: create_instance)
147161 }
148162}
149163
150164impl Artist {
151165 pub fn get ( py : Python ,
152166 session : librespot:: session:: Session ,
167+ handle : Remote ,
153168 id : librespot:: util:: SpotifyId ) -> PyResult < PyFuture >
154169 {
155- get ( py, session, id, Artist :: create_instance)
170+ get ( py, session, handle , id, Artist :: create_instance)
156171 }
157172
158173 pub fn get_all < I > ( py : Python ,
159174 session : librespot:: session:: Session ,
175+ handle : Remote ,
160176 ids : I ) -> PyResult < PyFuture >
161177 where I : IntoIterator < Item = librespot:: util:: SpotifyId > ,
162178 I :: IntoIter : ' static
163179 {
164- get_all ( py, session, ids, Artist :: create_instance)
180+ get_all ( py, session, handle , ids, Artist :: create_instance)
165181 }
166182}
0 commit comments