Mercurial > defr > drupal > scald > scald_dailymotion
comparison scald_dailymotion.module @ 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 |
comparison
equal
deleted
inserted
replaced
| 1:e851124eabe3 | 2:c57b2ac8f84c |
|---|---|
| 45 ) | 45 ) |
| 46 ); | 46 ); |
| 47 } | 47 } |
| 48 | 48 |
| 49 /** | 49 /** |
| 50 * Creates an atom based on a DailyMotion video id. | 50 * Creates an atom based on a DailyMotion video id or an object |
| 51 * @param $video_id | 51 * containing the video informations.. |
| 52 * Unique identifier of the video on dailymotion | 52 * @param $video |
| 53 * Unique identifier of the video on dailymotion, or object | |
| 54 * returned by scald_dailymotion_video. | |
| 53 * @return integer | 55 * @return integer |
| 54 * Unique identifier of the new atom | 56 * Unique identifier of the new atom |
| 55 */ | 57 */ |
| 56 function scald_dailymotion_register($video_id) { | 58 function scald_dailymotion_register($video) { |
| 57 global $user; | 59 global $user; |
| 58 // Fetch the needed informations from DailyMotion | 60 // Fetch the needed informations from DailyMotion |
| 59 $infos = scald_dailymotion_video($video_id); | 61 if (is_object($video)) { |
| 62 $infos = $video; | |
| 63 } | |
| 64 else { | |
| 65 $infos = scald_dailymotion_video($video); | |
| 66 } | |
| 67 // Check if the video has already been imported to prevent duplicated | |
| 68 $old = scald_dailymotion_already_imported($infos->id); | |
| 69 if ($old) { | |
| 70 return $old; | |
| 71 } | |
| 60 // Download a copy of the video thumbnail. This makes it possible | 72 // Download a copy of the video thumbnail. This makes it possible |
| 61 // to do interesting things when used with ImageCache for example. | 73 // to do interesting things when used with ImageCache for example. |
| 62 $thumb = drupal_http_request($infos->thumbnail['src']); | 74 $thumb = drupal_http_request($infos->thumbnail['src']); |
| 63 $dir = file_directory_path() . '/dailymotion'; | 75 $dir = file_directory_path() . '/dailymotion'; |
| 64 if ($thumb->code == 200 && file_check_directory($dir)) { | 76 if ($thumb->code == 200 && file_check_directory($dir)) { |
| 144 */ | 156 */ |
| 145 function scald_dailymotion_video($id) { | 157 function scald_dailymotion_video($id) { |
| 146 $items = scald_dailymotion_feed('video', $id); | 158 $items = scald_dailymotion_feed('video', $id); |
| 147 return $items[0]; | 159 return $items[0]; |
| 148 } | 160 } |
| 161 | |
| 162 /** | |
| 163 * Checks if a video has already been imported, based on its video | |
| 164 * id. | |
| 165 * @param $id | |
| 166 * The video identifier | |
| 167 * @return mixed | |
| 168 * FALSE if the video was never imported, the scald identifier of | |
| 169 * the video otherwise. | |
| 170 */ | |
| 171 function scald_dailymotion_already_imported($id) { | |
| 172 $query = array('provider' => 'scald_dailymotion', 'base_id' => $id); | |
| 173 return scald_search($query, FALSE, TRUE); | |
| 174 } |
