@@ -14,6 +14,35 @@ type metadataType = {
1414 activeMode : string
1515} ;
1616
17+ /**
18+ * Get the subtitle file buffer given an array of files
19+ */
20+ export function selectSubtitleFile (
21+ files : Array < { name : string } > = [ ] ,
22+ activeMode : string ,
23+ metadata : { season : number , episode : number }
24+ ) : { name: string } | boolean {
25+ return (
26+ files . find ( file => {
27+ const formatIsSupported = file . name . includes ( '.srt' ) ;
28+
29+ switch ( activeMode ) {
30+ // Check if the current file is the exact episode we're looking for
31+ case 'season_complete' : {
32+ const { season, episode } = metadata ;
33+ return (
34+ formatIsSupported && isExactEpisode ( file . name , season , episode )
35+ ) ;
36+ }
37+
38+ // Check if the current file is greater than the previous file
39+ default :
40+ return formatIsSupported ;
41+ }
42+ } ) || false
43+ ) ;
44+ }
45+
1746export default class Torrent {
1847 inProgress : boolean = false ;
1948
@@ -60,8 +89,8 @@ export default class Torrent {
6089
6190 this . engine . add ( magnetURI , { path : cacheLocation } , torrent => {
6291 const server = torrent . createServer ( ) ;
63- server . listen ( port ) ;
64- this . server = server ;
92+ this . server = server . listen ( port ) ;
93+ // this.server = server;
6594
6695 const { file, torrentIndex } = torrent . files . reduce (
6796 ( previous , current , index ) => {
@@ -146,15 +175,15 @@ export default class Torrent {
146175
147176 destroy ( ) {
148177 if ( this . inProgress ) {
149- console . log ( 'Destroyed Torrent...' ) ;
150-
151- if ( this . server && typeof this . server . close === 'function' ) {
178+ if ( this . server && this . server . close ) {
179+ console . log ( 'Closing the torrent server...' ) ;
152180 this . server . close ( ) ;
153181 this . server = { } ;
154182 }
155183
156184 this . clearIntervals ( ) ;
157185
186+ console . log ( 'Destroying the torrent engine...' ) ;
158187 this . engine . destroy ( ) ;
159188 this . engine = undefined ;
160189
@@ -190,32 +219,3 @@ export function formatSpeeds(
190219 ratio
191220 } ;
192221}
193-
194- /**
195- * Get the subtitle file buffer given an array of files
196- */
197- export function selectSubtitleFile (
198- files : Array < { name : string } > = [ ] ,
199- activeMode : string ,
200- metadata : { season : number , episode : number }
201- ) : { name: string } | boolean {
202- return (
203- files . find ( file => {
204- const formatIsSupported = file . name . includes ( '.srt' ) ;
205-
206- switch ( activeMode ) {
207- // Check if the current file is the exact episode we're looking for
208- case 'season_complete' : {
209- const { season, episode } = metadata ;
210- return (
211- formatIsSupported && isExactEpisode ( file . name , season , episode )
212- ) ;
213- }
214-
215- // Check if the current file is greater than the previous file
216- default :
217- return formatIsSupported ;
218- }
219- } ) || false
220- ) ;
221- }
0 commit comments