Exemplo n.º 1
0
<?php

require_once '../../configs/init.config.php';
require_once './classes/AddonYoutube.class.php';
$idx = Request('idx');
$IM = new iModule();
$Attachment = $IM->getModule('attachment');
if ($idx == null) {
    exit;
}
$results = new stdClass();
$youtubeInfo = $Attachment->getFileExtraInfo($idx, 'youtube');
if ($youtubeInfo != null) {
    $youtube = new AddonYoutube();
    $data = $youtube->get('https://www.googleapis.com/youtube/v3/videos?part=status%2Csnippet%2CprocessingDetails%2Cplayer&id=' . $youtubeInfo->id);
    if ($data != null) {
        $item = $data->items[0];
        $results->id = $item->id;
        $results->status = $item->status->uploadStatus;
        $Attachment->setFileExtraInfo($idx, 'youtube', $results);
        $results->thumbnail = $Attachment->getAttachmentUrl($idx, 'thumbnail');
        if ($results->thumbnail == null) {
            $thumbnail = $youtube->saveThumbnail($item, $Attachment->getTempPath(true));
            if ($thumbnail != null) {
                $file = $Attachment->db()->select($Attachment->table->attachment)->where('idx', $idx)->getOne();
                $image = getimagesize($thumbnail);
                if ($Attachment->createThumbnail($thumbnail, $IM->getAttachmentPath() . '/' . $file->path . '.thumb', $image[0] <= $image[1] ? 200 : 0, $image[0] > $image[1] ? 200 : 0, true) == true) {
                    $results->thumbnail = $Attachment->getAttachmentUrl($idx, 'thumbnail');
                }
            }
        }
Exemplo n.º 2
0
require_once $Addon->getPath() . '/classes/AddonYoutube.class.php';
if ($target == 'attachment') {
    $Module = $IM->getModule('attachment');
    if ($action == 'load') {
        for ($i = 0, $loop = sizeof($values->files); $i < $loop; $i++) {
            if ($values->files[$i]->type == 'video') {
                $values->files[$i]->youtube = $Module->getFileExtraInfo($values->files[$i]->idx, 'youtube');
            }
        }
    }
    if ($action == 'upload') {
        if ($results->success == true) {
            if ($values->fileInfo->type == 'video') {
                $uploaded = null;
                $youtube = new AddonYoutube();
                if ($values->status == 'METADATA') {
                    $youtubeInfo = new stdClass();
                    $youtubeInfo->location = $youtube->getUploadLocation($values->fileInfo);
                    if ($youtubeInfo->location != null) {
                        $Module->setFileExtraInfo($values->fileInfo->idx, 'youtube', $youtubeInfo);
                    }
                } else {
                    $youtubeInfo = $Module->getFileExtraInfo($values->fileInfo->idx, 'youtube');
                    if ($youtubeInfo->location != null) {
                        $uploaded = $youtube->upload($youtubeInfo->location, $values->fileInfo, $values->chunkBytes, $values->chunkRangeStart);
                        if (isset($uploaded->etag) == true && isset($uploaded->id) == true && isset($uploaded->status) == true) {
                            $youtubeInfo = new stdClass();
                            $youtubeInfo->id = $uploaded->id;
                            $youtubeInfo->status = $uploaded->status->uploadStatus;
                            $Module->setFileExtraInfo($values->fileInfo->idx, 'youtube', $youtubeInfo);