From d00c1dc91c7ccc014c39ef2a087cfea13e0e4d87 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Thu, 14 Apr 2016 12:42:13 +0200 Subject: [PATCH 1/5] Use PSR-7 streams for conversion --- composer.json | 3 +- composer.lock | 95 ++++++++++++++++++++++++++++++++- controllers/FrontController.php | 47 ++++++---------- 3 files changed, 112 insertions(+), 33 deletions(-) diff --git a/composer.json b/composer.json index 0b578a3..18a6a5e 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,8 @@ "ptachoire/process-builder-chain": "~1.2.0", "ffmpeg/ffmpeg": "dev-release", "rudloff/smarty-plugin-noscheme": "~0.1.0", - "rudloff/rtmpdump-bin": "~2.3" + "rudloff/rtmpdump-bin": "~2.3", + "rudloff/psr7-process-stream": "~0.1.0" }, "require-dev": { "symfony/var-dumper": "~3.0.0" diff --git a/composer.lock b/composer.lock index 5022148..d6a574e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "a0c23015c2a2bbb700ae566a04ca8679", - "content-hash": "42d3272dbfe226c0ef3da4e135e2dae3", + "hash": "0fef6027910cac993af5690ffd131b1c", + "content-hash": "ae728e70b08dd126d55576800f334529", "packages": [ { "name": "container-interop/container-interop", @@ -48,6 +48,64 @@ ], "type": "library" }, + { + "name": "guzzlehttp/psr7", + "version": "1.3.0", + "source": { + "type": "git", + "url": "https://github.com/guzzle/psr7.git", + "reference": "31382fef2889136415751badebbd1cb022a4ed72" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/31382fef2889136415751badebbd1cb022a4ed72", + "reference": "31382fef2889136415751badebbd1cb022a4ed72", + "shasum": "" + }, + "require": { + "php": ">=5.4.0", + "psr/http-message": "~1.0" + }, + "provide": { + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Psr7\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "PSR-7 message implementation", + "keywords": [ + "http", + "message", + "stream", + "uri" + ], + "time": "2016-04-13 19:56:01" + }, { "name": "jeremykendall/php-domain-parser", "version": "3.0.0", @@ -408,6 +466,39 @@ }, "type": "library" }, + { + "name": "rudloff/psr7-process-stream", + "version": "0.1.0", + "source": { + "type": "git", + "url": "https://github.com/Rudloff/psr7-process-stream.git", + "reference": "055ecbdadee9b43904aed75d5a548c277cac10a8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Rudloff/psr7-process-stream/zipball/055ecbdadee9b43904aed75d5a548c277cac10a8", + "reference": "055ecbdadee9b43904aed75d5a548c277cac10a8", + "shasum": "" + }, + "require": { + "guzzlehttp/psr7": "~1.3.0" + }, + "require-dev": { + "symfony/var-dumper": "~3.0.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "ProcessStream\\": "classes/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-3.0" + ], + "description": "PSR-7 stream implementation that can be used to manage processes", + "time": "2016-04-14 10:36:10" + }, { "name": "rudloff/rtmpdump-bin", "version": "2.3", diff --git a/controllers/FrontController.php b/controllers/FrontController.php index 03f2f01..ab3b5aa 100644 --- a/controllers/FrontController.php +++ b/controllers/FrontController.php @@ -16,6 +16,7 @@ use Alltube\VideoDownload; use Alltube\Config; use Symfony\Component\Process\ProcessBuilder; use Chain\Chain; +use ProcessStream\PopenStream; /** * Main controller @@ -136,6 +137,21 @@ class FrontController 'user_agent', $video->http_headers->{'User-Agent'} ); + + $response = $response->withHeader( + 'Content-Disposition', + 'attachment; filename="'. + html_entity_decode( + pathinfo( + $video->_filename, + PATHINFO_FILENAME + ).'.mp3', + ENT_COMPAT, + 'ISO-8859-1' + ).'"' + ); + $response = $response->withHeader('Content-Type', 'audio/mpeg'); + if (parse_url($video->url, PHP_URL_SCHEME) == 'rtmp') { $builder = new ProcessBuilder( array( @@ -164,21 +180,6 @@ class FrontController } $chain = new Chain($builder->getProcess()); $chain->add('|', $avconvProc); - ob_end_flush(); - header( - 'Content-Disposition: attachment; filename="'. - html_entity_decode( - pathinfo( - $video->_filename, - PATHINFO_FILENAME - ).'.mp3', - ENT_COMPAT, - 'ISO-8859-1' - ).'"' - ); - header("Content-Type: audio/mpeg"); - passthru($chain->getProcess()->getCommandLine()); - exit; } else { $chain = new Chain( ProcessBuilder::create( @@ -193,22 +194,8 @@ class FrontController ) ); $chain->add('|', $avconvProc); - ob_end_flush(); - header( - 'Content-Disposition: attachment; filename="'. - html_entity_decode( - pathinfo( - $video->_filename, - PATHINFO_FILENAME - ).'.mp3', - ENT_COMPAT, - 'ISO-8859-1' - ).'"' - ); - header("Content-Type: audio/mpeg"); - passthru($chain->getProcess()->getCommandLine()); - exit; } + return $response->withBody(new PopenStream($chain->getProcess()->getCommandLine())); } } catch (\Exception $e) { $error = $e->getMessage(); From ecba860c5a0e00750508f578532ddb6be7ab8f51 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Thu, 14 Apr 2016 12:48:32 +0200 Subject: [PATCH 2/5] Use curl in silent mode Always append curl custom parameters at the end --- controllers/FrontController.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/controllers/FrontController.php b/controllers/FrontController.php index ab3b5aa..7622ce9 100644 --- a/controllers/FrontController.php +++ b/controllers/FrontController.php @@ -184,12 +184,13 @@ class FrontController $chain = new Chain( ProcessBuilder::create( array_merge( - array('curl'), - $this->config->curl_params, array( + 'curl', + '--silent', '--user-agent', $video->http_headers->{'User-Agent'}, $video->url - ) + ), + $this->config->curl_params ) ) ); From bcf399a9d4a76aeac6d39db82f430167631ea7f1 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Thu, 14 Apr 2016 19:43:38 +0200 Subject: [PATCH 3/5] youtube-dl update --- composer.json | 6 +++--- composer.lock | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index 18a6a5e..6f89a16 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "type": "project", "require": { "smarty/smarty": "~3.1.29", - "rg3/youtube-dl": "2016.04.06", + "rg3/youtube-dl": "2016.04.13", "slim/slim": "~3.3.0", "mathmarques/smarty-view": "~1.1.0", "symfony/yaml": "~3.0.0", @@ -31,11 +31,11 @@ "type": "package", "package": { "name": "rg3/youtube-dl", - "version": "2016.04.06", + "version": "2016.04.13", "source": { "url": "https://github.com/rg3/youtube-dl.git", "type": "git", - "reference": "2016.04.06" + "reference": "9e285387260a019d7471c3bdbd52cc764c0e8700" } } }, { diff --git a/composer.lock b/composer.lock index d6a574e..06119e0 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "0fef6027910cac993af5690ffd131b1c", - "content-hash": "ae728e70b08dd126d55576800f334529", + "hash": "599ad9b618341fa7a25bcc0c3ea5b856", + "content-hash": "2e86be18aae01a848d9df7ebe931d19d", "packages": [ { "name": "container-interop/container-interop", @@ -458,11 +458,11 @@ }, { "name": "rg3/youtube-dl", - "version": "2016.04.06", + "version": "2016.04.13", "source": { "type": "git", "url": "https://github.com/rg3/youtube-dl.git", - "reference": "2016.04.06" + "reference": "9e285387260a019d7471c3bdbd52cc764c0e8700" }, "type": "library" }, From 2ddca6a74356c3af075c3af14ed5a325d67793d6 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Sat, 16 Apr 2016 18:24:07 +0200 Subject: [PATCH 4/5] Set PHP version in Docker build file --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 74e03bb..5dbf4fd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM php:apache +FROM php:5.6-apache RUN apt-get update RUN apt-get install -y libicu-dev xz-utils git zlib1g-dev python npm nodejs-legacy RUN docker-php-ext-install mbstring From 3c4d52e67678178bcc3b745126d39be7753957f3 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Fri, 29 Apr 2016 21:34:57 +0200 Subject: [PATCH 5/5] Add tag in release filename --- .gitignore | 2 +- Gruntfile.js | 10 ++++++++-- package.json | 3 ++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 0fb6d93..af93b59 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,7 @@ vendor/ templates_c/ ffmpeg.tar.xz ffmpeg-*/ -alltube-release.zip +alltube-*.zip coverage/ bower_components/ config.yml diff --git a/Gruntfile.js b/Gruntfile.js index 3dcbf99..1d05fad 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -3,6 +3,11 @@ module.exports = function (grunt) { 'use strict'; grunt.initConfig( { + githash: { + main: { + options: {} + } + }, uglify: { combine: { files: { @@ -52,7 +57,7 @@ module.exports = function (grunt) { compress: { release: { options: { - archive: 'alltube-release.zip' + archive: 'alltube-<%= githash.main.tag %>.zip' }, src: ['*.php', '!config.yml', 'dist/**', 'fonts/**', '.htaccess', 'img/**', 'js/**', 'LICENSE', 'README.md', 'robots.txt', 'sitemap.xml', 'templates/**', 'templates_c/', 'vendor/**', 'classes/**', 'controllers/**', 'bower_components/**', '!vendor/ffmpeg/**', '!vendor/bin/ffmpeg'] } @@ -60,6 +65,7 @@ module.exports = function (grunt) { } ); + grunt.loadNpmTasks('grunt-githash'); grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-contrib-cssmin'); grunt.loadNpmTasks('grunt-contrib-watch'); @@ -70,5 +76,5 @@ module.exports = function (grunt) { grunt.registerTask('default', ['uglify', 'cssmin']); grunt.registerTask('lint', ['phpcs']); grunt.registerTask('test', ['phpunit']); - grunt.registerTask('release', ['default', 'compress']); + grunt.registerTask('release', ['default', 'githash', 'compress']); }; diff --git a/package.json b/package.json index d6213e8..5e4480d 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "grunt-phpcs": "~0.4.0", "grunt-phpunit": "~0.3.6", "grunt-contrib-compress": "~1.2.0", - "bower": "~1.7.1" + "bower": "~1.7.1", + "grunt-githash": "~0.1.3" }, "repository": { "type": "git",