<?php namespace Source\Lib;
use Dever;
class Datavalue
{
    public function updateStart($data)
    {
        $host = Dever::host();
        if (isset($data['value']) && $data['value']) {
            if (!strstr($data['value'], $host)) {
                $result = Dever::load('video', 'api')->remote($data['value'], false, true);
                if (isset($result['vid'])) {
                    $data['remote'] = $result['value'];
                    $data['value'] = $result['video']['url'];
                    $data['name'] = $result['title'] ? $result['title'] : $result['desc'];
                    $data['vid'] = $result['vid'];
                }
            }
        }
        return $data;
    }

    public function updateEnd($data)
    {
        if (isset($data['video']) && $data['video'] == 1) {
            $info = Dever::db('info_data_value')->find($data['id']);
            Dever::load('video', 'source')->update($info, 3);
        }
        return $data;
    }
}