# HG changeset patch # User Franck Deroche # Date 1279539705 -7200 # Node ID c57b2ac8f84c67bbbe9c9e9a050406a447bc9dc4 # Parent e851124eabe34a162d4b6099cfe42421809fbf11 Fluidify feed processing and prevent duplicate errors. diff -r e851124eabe3 -r c57b2ac8f84c scald_dailymotion.module --- a/scald_dailymotion.module Fri Jul 16 17:42:09 2010 +0200 +++ b/scald_dailymotion.module Mon Jul 19 13:41:45 2010 +0200 @@ -47,16 +47,28 @@ } /** - * Creates an atom based on a DailyMotion video id. - * @param $video_id - * Unique identifier of the video on dailymotion + * Creates an atom based on a DailyMotion video id or an object + * containing the video informations.. + * @param $video + * Unique identifier of the video on dailymotion, or object + * returned by scald_dailymotion_video. * @return integer * Unique identifier of the new atom */ -function scald_dailymotion_register($video_id) { +function scald_dailymotion_register($video) { global $user; // Fetch the needed informations from DailyMotion - $infos = scald_dailymotion_video($video_id); + if (is_object($video)) { + $infos = $video; + } + else { + $infos = scald_dailymotion_video($video); + } + // Check if the video has already been imported to prevent duplicated + $old = scald_dailymotion_already_imported($infos->id); + if ($old) { + return $old; + } // Download a copy of the video thumbnail. This makes it possible // to do interesting things when used with ImageCache for example. $thumb = drupal_http_request($infos->thumbnail['src']); @@ -146,3 +158,17 @@ $items = scald_dailymotion_feed('video', $id); return $items[0]; } + +/** + * Checks if a video has already been imported, based on its video + * id. + * @param $id + * The video identifier + * @return mixed + * FALSE if the video was never imported, the scald identifier of + * the video otherwise. + */ +function scald_dailymotion_already_imported($id) { + $query = array('provider' => 'scald_dailymotion', 'base_id' => $id); + return scald_search($query, FALSE, TRUE); +}