19
19
use Alltube \Stream \ConvertedPlaylistArchiveStream ;
20
20
use Alltube \Stream \PlaylistArchiveStream ;
21
21
use Alltube \Stream \YoutubeStream ;
22
+ use Graby \HttpClient \Plugin \ServerSideRequestForgeryProtection \Exception \InvalidURLException ;
22
23
use Slim \Http \Request ;
23
24
use Slim \Http \Response ;
24
25
use Slim \Http \StatusCode ;
@@ -37,56 +38,53 @@ class DownloadController extends BaseController
37
38
*
38
39
* @return Response HTTP response
39
40
* @throws AlltubeLibraryException
41
+ * @throws InvalidURLException
40
42
*/
41
43
public function download (Request $ request , Response $ response ): Response
42
44
{
43
- $ url = $ request -> getQueryParam ( ' url ' );
45
+ $ url = $ this -> getVideoPageUrl ( $ request );
44
46
45
- if (isset ($ url )) {
46
- $ this ->video = $ this ->downloader ->getVideo ($ url , $ this ->getFormat ($ request ), $ this ->getPassword ($ request ));
47
+ $ this ->video = $ this ->downloader ->getVideo ($ url , $ this ->getFormat ($ request ), $ this ->getPassword ($ request ));
47
48
48
- try {
49
- if ($ this ->config ->convert && $ request ->getQueryParam ('audio ' )) {
50
- // Audio convert.
51
- return $ this ->getAudioResponse ($ request , $ response );
52
- } elseif ($ this ->config ->convertAdvanced && !is_null ($ request ->getQueryParam ('customConvert ' ))) {
53
- // Advance convert.
54
- return $ this ->getConvertedResponse ($ request , $ response );
55
- }
49
+ try {
50
+ if ($ this ->config ->convert && $ request ->getQueryParam ('audio ' )) {
51
+ // Audio convert.
52
+ return $ this ->getAudioResponse ($ request , $ response );
53
+ } elseif ($ this ->config ->convertAdvanced && !is_null ($ request ->getQueryParam ('customConvert ' ))) {
54
+ // Advance convert.
55
+ return $ this ->getConvertedResponse ($ request , $ response );
56
+ }
56
57
57
- // Regular download.
58
- return $ this ->getDownloadResponse ($ request , $ response );
59
- } catch (PasswordException $ e ) {
60
- $ frontController = new FrontController ($ this ->container );
58
+ // Regular download.
59
+ return $ this ->getDownloadResponse ($ request , $ response );
60
+ } catch (PasswordException $ e ) {
61
+ $ frontController = new FrontController ($ this ->container );
61
62
62
- return $ frontController ->password ($ request , $ response );
63
- } catch (WrongPasswordException $ e ) {
64
- return $ this ->displayError ($ request , $ response , $ this ->localeManager ->t ('Wrong password ' ));
65
- } catch (PlaylistConversionException $ e ) {
63
+ return $ frontController ->password ($ request , $ response );
64
+ } catch (WrongPasswordException $ e ) {
65
+ return $ this ->displayError ($ request , $ response , $ this ->localeManager ->t ('Wrong password ' ));
66
+ } catch (PlaylistConversionException $ e ) {
67
+ return $ this ->displayError (
68
+ $ request ,
69
+ $ response ,
70
+ $ this ->localeManager ->t ('Conversion of playlists is not supported. ' )
71
+ );
72
+ } catch (InvalidProtocolConversionException $ e ) {
73
+ if (in_array ($ this ->video ->protocol , ['m3u8 ' , 'm3u8_native ' ])) {
66
74
return $ this ->displayError (
67
75
$ request ,
68
76
$ response ,
69
- $ this ->localeManager ->t ('Conversion of playlists is not supported. ' )
77
+ $ this ->localeManager ->t ('Conversion of M3U8 files is not supported. ' )
70
78
);
71
- } catch (InvalidProtocolConversionException $ e ) {
72
- if (in_array ($ this ->video ->protocol , ['m3u8 ' , 'm3u8_native ' ])) {
73
- return $ this ->displayError (
74
- $ request ,
75
- $ response ,
76
- $ this ->localeManager ->t ('Conversion of M3U8 files is not supported. ' )
77
- );
78
- } elseif ($ this ->video ->protocol == 'http_dash_segments ' ) {
79
- return $ this ->displayError (
80
- $ request ,
81
- $ response ,
82
- $ this ->localeManager ->t ('Conversion of DASH segments is not supported. ' )
83
- );
84
- } else {
85
- throw $ e ;
86
- }
79
+ } elseif ($ this ->video ->protocol == 'http_dash_segments ' ) {
80
+ return $ this ->displayError (
81
+ $ request ,
82
+ $ response ,
83
+ $ this ->localeManager ->t ('Conversion of DASH segments is not supported. ' )
84
+ );
85
+ } else {
86
+ throw $ e ;
87
87
}
88
- } else {
89
- return $ response ->withRedirect ($ this ->router ->pathFor ('index ' ));
90
88
}
91
89
}
92
90
0 commit comments