Пример #1
0
    } else {
        $sizebefore = 0;
        $f = fopen($filename, "wb");
    }
    if (!$f) {
        $api->log(LOG_CRIT, "cannot write to " . $filename . " for task '" . $task["id"] . "'");
        $api->setTaskFailedUnlock($task["id"]);
        continue;
    }
    curl_setopt($curl, CURLOPT_FILE, $f);
    $res = curl_exec($curl);
    $info = curl_getinfo($curl);
    fclose($f);
    if ($res) {
        // and mark the media as "locally downloaded"
        $api->mediaUpdate($task["mediaid"], array("status" => MEDIA_LOCAL_AVAILABLE));
        // and ask for its metadata if requested to:
        if ($task["params"]["dometadata"]) {
            $api->queueAdd(TASK_DO_METADATA, $task["mediaid"], METADATA_RETRY);
        }
        // ok, transfer finished, let's mark it done
        $api->setTaskProcessedUnlock($task["id"]);
        $api->log(LOG_INFO, "Download task " . $task["id"] . " finished for media " . $task["mediaid"] . "");
    } else {
        // if we failed, we just mark it as failed, this will retry 5 min from now ...
        $api->setTaskFailedUnlock($task["id"]);
        print_r($info);
        $api->log(LOG_WARNING, "Download task " . $task["id"] . " failed or unfinished for media " . $task["mediaid"] . "");
    }
}
// while (true)
Пример #2
0
     $api->log(LOG_CRIT, "Got task '" . $task["id"] . "' but media '" . $task["mediaid"] . "' didn't allow to find the file using adapter '" . $task["adapter"] . "' !!");
     $api->setTaskFailedUnlock($task["id"]);
     continue;
 }
 if (!file_exists($filename) || filesize($filename) == 0) {
     $api->log(LOG_CRIT, "Got task '" . $task["id"] . "' but file '" . $filename . "' not found or has zero size!!");
     $api->setTaskFailedUnlock($task["id"]);
     continue;
 }
 // ok, now we use ffmpeg to get the metadata of the downloaded media
 // depending on FFMPEG / AVCONV version, we use one parser or the other ...
 $metadata = $ffmpeg->getFfmpegMetadata($filename);
 if ($metadata) {
     if (count($metadata["tracks"]) == 0) {
         // Store the metadata in the media object:
         $api->mediaUpdate($task["mediaid"], array("status" => MEDIA_METADATA_FAILED, "metadata" => serialize($metadata)));
         // Queue the task to tell the client that we had an error getting the metadata
         $api->queueAdd(TASK_SEND_METADATAERROR, $task["mediaid"], API_RETRY);
         // ok, transfer finished, let's mark it done
         $api->setTaskProcessedUnlock($task["id"]);
         $api->log(LOG_DEBUG, "Failed (properly) while processing task '" . $task["id"] . "', metadata for media '" . $task["mediaid"] . "'");
     } else {
         // Store the metadata in the media object:
         $api->mediaUpdate($task["mediaid"], array("status" => MEDIA_METADATA_OK, "metadata" => serialize($metadata)));
         // Queue the task to tell the client that we have the metadata
         $api->queueAdd(TASK_SEND_METADATA, $task["mediaid"], API_RETRY);
         // ok, transfer finished, let's mark it done
         $api->setTaskProcessedUnlock($task["id"]);
         $api->log(LOG_DEBUG, "Successully processed task '" . $task["id"] . "', metadata for media '" . $task["mediaid"] . "'");
     }
 } else {