├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── composer.json └── src ├── Facades └── LaravelYoutubeDownloader.php ├── LaravelYoutubeDownloader.php └── LaravelYoutubeDownloaderServiceProvider.php /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to `laravel-youtube-downloader` will be documented in this file. 4 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) Mo Khosh 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # download youtube videos in your laravel applications (for personal and educational purposes of course) 2 | 3 | [![Latest Version on Packagist](https://img.shields.io/packagist/v/mokhosh/laravel-youtube-downloader.svg?style=flat-square)](https://packagist.org/packages/mokhosh/laravel-youtube-downloader) 4 | [![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/mokhosh/laravel-youtube-downloader/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/mokhosh/laravel-youtube-downloader/actions?query=workflow%3Arun-tests+branch%3Amain) 5 | [![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/mokhosh/laravel-youtube-downloader/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/mokhosh/laravel-youtube-downloader/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain) 6 | [![Total Downloads](https://img.shields.io/packagist/dt/mokhosh/laravel-youtube-downloader.svg?style=flat-square)](https://packagist.org/packages/mokhosh/laravel-youtube-downloader) 7 | 8 | ## Installation 9 | 10 | You can install the package via composer: 11 | 12 | ```bash 13 | composer require mokhosh/laravel-youtube-downloader 14 | ``` 15 | 16 | ## Usage 17 | 18 | ```php 19 | use Mokhosh\Facades\LaravelYoutubeDownloader; 20 | 21 | $videoId = LaravelYoutubeDownloader::getVideoIdFromUrl($youtubeUrl); 22 | $video = LaravelYoutubeDownloader::getYoutubeVideoMeta($videoId); 23 | 24 | $formats = $video->streamingData->formats; 25 | $adaptiveFormats = $video->streamingData->adaptiveFormats; 26 | 27 | $title = $video->videoDetails->title; 28 | $short_description = $video->videoDetails->shortDescription; 29 | $thumbnails = $video->videoDetails->thumbnail->thumbnails; 30 | $thumbnail = end($thumbnails)->url; 31 | $channel_id = $video->videoDetails->channelId; 32 | $channel_name = $video->videoDetails->author; 33 | $views = $video->videoDetails->viewCount; 34 | $video_duration_in_seconds = $video->videoDetails->lengthSeconds; 35 | ``` 36 | 37 | ## Testing 38 | 39 | ```bash 40 | composer test 41 | ``` 42 | 43 | ## Changelog 44 | 45 | Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. 46 | 47 | ## Contributing 48 | 49 | Please see [CONTRIBUTING](CONTRIBUTING.md) for details. 50 | 51 | ## Security Vulnerabilities 52 | 53 | Please review [our security policy](../../security/policy) on how to report security vulnerabilities. 54 | 55 | ## Credits 56 | 57 | - [Mo Khosh](https://github.com/mokhosh) 58 | - [All Contributors](../../contributors) 59 | 60 | ## License 61 | 62 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. 63 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mokhosh/laravel-youtube-downloader", 3 | "description": "download youtube videos in your laravel applications (for personal and educational purposes of course)", 4 | "keywords": [ 5 | "Mo Khosh", 6 | "laravel", 7 | "laravel-youtube-downloader" 8 | ], 9 | "homepage": "https://github.com/mokhosh/laravel-youtube-downloader", 10 | "license": "MIT", 11 | "authors": [ 12 | { 13 | "name": "Mo Khosh", 14 | "email": "mskhoshnazar@gmail.com", 15 | "role": "Developer" 16 | } 17 | ], 18 | "require": { 19 | "php": "^8.1", 20 | "spatie/laravel-package-tools": "^1.14.0", 21 | "illuminate/contracts": "^10.0" 22 | }, 23 | "require-dev": { 24 | "laravel/pint": "^1.0", 25 | "nunomaduro/collision": "^7.8", 26 | "larastan/larastan": "^2.0.1", 27 | "orchestra/testbench": "^8.8", 28 | "pestphp/pest": "^2.20", 29 | "pestphp/pest-plugin-arch": "^2.0", 30 | "pestphp/pest-plugin-laravel": "^2.0", 31 | "phpstan/extension-installer": "^1.1", 32 | "phpstan/phpstan-deprecation-rules": "^1.0", 33 | "phpstan/phpstan-phpunit": "^1.0" 34 | }, 35 | "autoload": { 36 | "psr-4": { 37 | "Mokhosh\\LaravelYoutubeDownloader\\": "src/", 38 | "Mokhosh\\LaravelYoutubeDownloader\\Database\\Factories\\": "database/factories/" 39 | } 40 | }, 41 | "autoload-dev": { 42 | "psr-4": { 43 | "Mokhosh\\LaravelYoutubeDownloader\\Tests\\": "tests/", 44 | "Workbench\\App\\": "workbench/app/" 45 | } 46 | }, 47 | "scripts": { 48 | "post-autoload-dump": "@composer run prepare", 49 | "clear": "@php vendor/bin/testbench package:purge-laravel-youtube-downloader --ansi", 50 | "prepare": "@php vendor/bin/testbench package:discover --ansi", 51 | "build": [ 52 | "@composer run prepare", 53 | "@php vendor/bin/testbench workbench:build --ansi" 54 | ], 55 | "start": [ 56 | "Composer\\Config::disableProcessTimeout", 57 | "@composer run build", 58 | "@php vendor/bin/testbench serve" 59 | ], 60 | "analyse": "vendor/bin/phpstan analyse", 61 | "test": "vendor/bin/pest", 62 | "test-coverage": "vendor/bin/pest --coverage", 63 | "format": "vendor/bin/pint" 64 | }, 65 | "config": { 66 | "sort-packages": true, 67 | "allow-plugins": { 68 | "pestphp/pest-plugin": true, 69 | "phpstan/extension-installer": true 70 | } 71 | }, 72 | "extra": { 73 | "laravel": { 74 | "providers": [ 75 | "Mokhosh\\LaravelYoutubeDownloader\\LaravelYoutubeDownloaderServiceProvider" 76 | ], 77 | "aliases": { 78 | "LaravelYoutubeDownloader": "Mokhosh\\LaravelYoutubeDownloader\\Facades\\LaravelYoutubeDownloader" 79 | } 80 | } 81 | }, 82 | "minimum-stability": "dev", 83 | "prefer-stable": true 84 | } -------------------------------------------------------------------------------- /src/Facades/LaravelYoutubeDownloader.php: -------------------------------------------------------------------------------- 1 | getCurlPostData($videoId)); 25 | curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate'); 26 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 27 | curl_setopt($ch, CURLOPT_POST, 1); 28 | 29 | $result = curl_exec($ch); 30 | $error = curl_errno($ch); 31 | 32 | curl_close($ch); 33 | 34 | if ($error) { 35 | throw new \Exception(curl_error($ch)); 36 | } 37 | 38 | return json_decode($result); 39 | } 40 | 41 | protected function getCurlPostData($videoId) 42 | { 43 | return <<name('laravel-youtube-downloader'); 19 | } 20 | } 21 | --------------------------------------------------------------------------------