Mercurial > defr > drupal > scald > scald_dailymotion
changeset 2:c57b2ac8f84c
Fluidify feed processing and prevent duplicate errors.
author | Franck Deroche <franck@defr.org> |
---|---|
date | Mon, 19 Jul 2010 13:41:45 +0200 |
parents | e851124eabe3 |
children | 2a63a6e15166 |
files | scald_dailymotion.module |
diffstat | 1 files changed, 31 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- 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); +}