ayesh / instagram-download
Instagram图片和视频下载器,具有URL验证和cURL集成。
v5.0.0
2020-04-01 17:01 UTC
Requires
- php: ^7.4
- ext-curl: *
Requires (Dev)
- phpstan/phpstan: ^0.12.18
- phpunit/phpunit: ^9.0.2
README
Instagram照片和视频下载助手库。
新功能:检查TikTokOff - TikTok视频在线下载器(无水印)
2020年5月22日更新:由于Instagram不再允许匿名用户查看照片/视频,该库目前无法使用。正在开发新版本7,但尚无确切时间表。现在只能使用IGTV视频。
旧版和不支持版本
旧版和最小支持版本
我主要编写这个类是为了我的在线Instagram照片、视频和IGTV下载器,但我认为分享这个片段供您扩展。
- 验证Instagram URL(域名验证,URL路径验证)。
- 使用OG属性来检测图片和视频URL。
- 支持Instagram照片、视频和Instagram TV视频
- 详细的错误报告和适当的异常。
- 完整的单元测试
- 除了PHP curl扩展(可能已经启用)之外没有其他依赖项
要求
- PHP 7.4
- Curl
感谢
- MetaData - 元数据解析正则表达式和curl类。
安装
使用composer 在您的项目中运行以下命令以安装库。
composer require ayesh/instagram-download
不使用composer 从Github下载zip文件,并配置您的autoload处理器从下载内容中的src
目录自动加载PSR-4 Ayesh\InstagramDownload
命名空间。
您还可以手动引入文件。因为2017年您没有使用一个不错的自动加载机制,所以会有一定程度的罪恶感。
require_once 'src/InstagramDownload.php'
用法
<?php use Ayesh\InstagramDownload\InstagramDownload; $url = 'http://instagram.com/p/tmwAlCGygb/'; try { $client = new InstagramDownload($url); $url = $client->getDownloadUrl(); // Returns the download URL. $type = $client->getType(); // Returns "image" or "video" depending on the media type. } catch (\InvalidArgumentException $exception) { /* * \InvalidArgumentException exceptions will be thrown if there is a validation * error in the URL. You might want to break the code flow and report the error * to your form handler at this point. */ $error = $exception->getMessage(); } catch (\RuntimeException $exception) { /* * \RuntimeException exceptions will be thrown if the URL could not be * fetched, parsed, or a media could not be extracted from the URL. */ $error = $exception->getMessage(); }