public function sync($location)
 {
     $yt = $this->includes();
     $start = 0;
     $videos = array();
     $total = false;
     while ($start < $total || $total === false) {
         $videoFeed = $yt->getuserUploads(Config::get("youtube/username"));
         $total = $videoFeed->getTotalResults()->text;
         foreach ($videoFeed as $video) {
             $videos[] = $video;
         }
         $start = count($videos);
     }
     $ids = array();
     $info = array();
     $class = get_class($this);
     foreach ($videos as $video) {
         $source = $video->getVideoId();
         $model = new WildfireMedia();
         if ($found = $model->filter("media_class", $class)->filter("source", $source)->first()) {
             $found->update_attributes(array('status' => 1));
         } else {
             $found = $model->update_attributes(array('source' => $source, 'uploaded_location' => $video->getID()->text, 'status' => 1, 'media_class' => $class, 'media_type' => self::$name, 'ext' => "", 'content' => $video->getVideoDescription(), 'file_type' => "video", 'title' => $video->getTitle()->text, 'hash' => md5(time()), 'sync_location' => $location));
         }
         $ids[] = $found->primval;
         $info[] = $found;
         //categorisation
         foreach ($video->getVideoTags() as $tag) {
             $model = new WildfireCategory();
             if (($tag = trim($tag)) && $tag) {
                 if ($cat = $model->filter("title", $tag)->first()) {
                     $found->categories = $cat;
                 } else {
                     $found->categories = $model->update_attributes(array('title' => $tag));
                 }
             }
         }
     }
     $media = new WildfireMedia();
     foreach ($ids as $id) {
         $media->filter("id", $id, "!=");
     }
     foreach ($media->filter("status", 1)->filter("media_class", $class)->filter("sync_location", $location)->all() as $missing) {
         $missing->update_attributes(array('status' => -1));
     }
     return $info;
 }
 public function sync($location)
 {
     $info = array();
     list($service_key, $id) = explode("@", $location);
     $service = $this->fetch[$service_key];
     $single = $this->singular[$service_key];
     $type = $single . "_id";
     //find the photoset name
     $method = "flickr.photosets.getInfo";
     $set_url = $this->api_base . "?" . $type . "=" . $id . "&method=" . $method . "&nojsoncallback=1&format=json&api_key=" . Config::get("flickr/key") . "&per_page=500&user_id=" . Config::get("flickr/user_id");
     $curl = new WaxBackgroundCurl(array('url' => $set_url));
     $set_data = json_decode($curl->fetch());
     $cat = new WildfireCategory();
     //find the category based on the photoset
     if (($name = $set_data->photoset->title->_content) && !($found_cat = $cat->filter("title", $name)->first())) {
         $found_cat = $cat->update_attributes(array('title' => $name));
     }
     $url = $this->api_base . "?" . $type . "=" . $id . "&method=" . $service . "&nojsoncallback=1&format=json&api_key=" . Config::get("flickr/key") . "&per_page=500&user_id=" . Config::get("flickr/user_id");
     $curl = new WaxBackgroundCurl(array('url' => $url));
     $data = json_decode($curl->fetch());
     $class = get_class($this);
     if ($data->{$single}->total) {
         $ids = array();
         foreach ($data->{$single}->photo as $pic) {
             $source = $pic->id;
             $model = new WildfireMedia();
             $info_url = $this->api_base . "?method=" . $this->fetch['photo'] . "&photo_id={$source}&nojsoncallback=1&format=json&api_key=" . Config::get("flickr/key") . "&per_page=500&user_id=" . Config::get("flickr/user_id");
             $ncurl = new WaxBackgroundCurl(array('url' => $info_url));
             if ($pic_info = json_decode($ncurl->fetch())) {
                 if ($found = $model->filter("media_class", $class)->filter("source", $pic->id)->first()) {
                     $found->update_attributes(array('status' => 1));
                 } else {
                     $found = $model->update_attributes(array('source' => $source, 'uploaded_location' => str_replace(Config::get("flickr/user_id"), "@USER@", str_replace(Config::get("flickr/key"), "@KEY@", $info_url)), 'status' => 1, 'media_class' => $class, 'media_type' => self::$name, 'ext' => $pic_info->photo->originalformat, 'file_type' => $pic_info->photo->media == "photo" ? "image/" . $pic_info->photo->originalformat : "video", 'title' => $pic->title, 'hash' => $pic->secret, 'sync_location' => $location));
                 }
                 $ids[] = $found->primval;
                 $info[] = $found;
                 //join
                 $found->categories = $found_cat;
                 //tags -> categories
                 foreach ((array) $pic_info->photo->tags->tag as $tag) {
                     $model = new WildfireCategory();
                     if (($tag = trim($tag->_content)) && $tag) {
                         if ($cat = $model->filter("title", $tag)->first()) {
                             $found->categories = $cat;
                         } else {
                             $found->categories = $model->update_attributes(array('title' => $tag));
                         }
                     }
                 }
             }
         }
         $media = new WildfireMedia();
         foreach ($ids as $id) {
             $media->filter("id", $id, "!=");
         }
         foreach ($media->filter("status", 1)->filter("media_class", $class)->filter("sync_location", $location)->all() as $missing) {
             $missing->update_attributes(array('status' => -1));
         }
     }
     return $info;
 }
 public function sync($location)
 {
     $videos = $this->get_videos();
     $ids = array();
     $info = array();
     $class = get_class($this);
     foreach ((array) $videos as $video) {
         $model = new WildfireMedia();
         $url = $video->urls->url[0]->_content;
         if ($found = $model->filter("media_class", $class)->filter("source", $video->id)->first()) {
             $found->update_attributes(array('status' => 1));
         } else {
             $found = $model->update_attributes(array('source' => $video->id, 'uploaded_location' => $url, 'status' => 1, 'media_class' => $class, 'media_type' => self::$name, 'ext' => "", 'content' => $video->description, 'file_type' => "video", 'title' => $video->title, 'hash' => md5($video->upload_date), 'sync_location' => $location));
         }
         $ids[] = $found->primval;
         $info[] = $found;
         //categorisation
         foreach (explode(",", $video->tags) as $tag) {
             $model = new WildfireCategory();
             if (($tag = trim($tag)) && $tag) {
                 if ($cat = $model->filter("title", $tag)->first()) {
                     $found->categories = $cat;
                 } else {
                     $found->categories = $model->update_attributes(array('title' => $tag));
                 }
             }
         }
     }
     $media = new WildfireMedia();
     foreach ($ids as $id) {
         $media->filter("id", $id, "!=");
     }
     foreach ($media->filter("status", 1)->filter("media_class", $class)->filter("sync_location", $location)->all() as $missing) {
         $missing->update_attributes(array('status' => -1));
     }
     return $info;
 }