@@ -314,6 +314,29 @@ public function getMedia($id, $license_name, $subaccount_id = NULL)
314
314
* @param string $output_file if null the downloaded file will be echoed on standard output
315
315
*/
316
316
public function downloadMedia ($ download_url , $ output_file = NULL )
317
+ {
318
+ return $ this ->_download ($ download_url , $ output_file );
319
+ }
320
+
321
+ /**
322
+ * Download a media comp and write it to a file if necessary
323
+ *
324
+ * @param string $download_url URL as returned by getMediaComp()
325
+ * @param string $output_file if null the downloaded file will be echoed on standard output
326
+ */
327
+ public function downloadMediaComp ($ download_url , $ output_file = NULL )
328
+ {
329
+ return $ this ->_download ($ download_url , $ output_file , false );
330
+ }
331
+
332
+ /**
333
+ * Download a content and write it to a file if necessary
334
+ *
335
+ * @param string $download_url URL
336
+ * @param string $output_file if null the downloaded file will be echoed on standard output
337
+ * @param bool $http_auth set curl password if needed
338
+ */
339
+ private function _download ($ download_url , $ output_file = NULL , $ http_auth = true )
317
340
{
318
341
$ ch = $ this ->_getCurlHandler ($ download_url );
319
342
@@ -327,7 +350,9 @@ public function downloadMedia($download_url, $output_file = NULL)
327
350
}
328
351
329
352
curl_setopt ($ ch , CURLOPT_FILE , $ output_fd );
330
- curl_setopt ($ ch , CURLOPT_USERPWD , $ this ->_getHttpAuth (TRUE , TRUE ));
353
+ if ($ http_auth ) {
354
+ curl_setopt ($ ch , CURLOPT_USERPWD , $ this ->_getHttpAuth (TRUE , TRUE ));
355
+ }
331
356
332
357
$ response = curl_exec ($ ch );
333
358
0 commit comments