Skip to content

Instantly share code, notes, and snippets.

@da1nonly
Created September 23, 2013 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save da1nonly/6668055 to your computer and use it in GitHub Desktop.
Save da1nonly/6668055 to your computer and use it in GitHub Desktop.
youtube import wordpress
if($type == 'youtube'){
$playlist_id = $_POST['convert'];
if($old !== 'Data'){
$url = "https://gdata.youtube.com/feeds/api/playlists/".$playlist_id."?v=2&alt=json&max-results=50";
$data = json_decode(file_get_contents($url),true);
$info = $data["feed"];
$video = $info["entry"];
for($i=0;$i<count($video);$i++){
if($video[$i]['link'][0]['href'] != ""){
$text_title = str_replace("'", '', $video[$i]['title']['$t']);
$link .= $text_title.',';
parse_str( parse_url( $video[$i]['link'][0]['href'], PHP_URL_QUERY ), $my_array_of_vars );
$link2 = "https://www.youtube.com/watch?v=".$my_array_of_vars['v'];
$link .= $link2.'$';
}
}
$old = $link;
$new = array();
$dataArrays = explode( "$", $old );
// $dataArrays = ["name1, url1", "name2, url2", "name3, url3"];
foreach( $dataArrays as $dataArray ) {
$separated = explode( ",", $dataArray );
// $separated = ["name1", "url1"];
array_push( $new, array(
'name' => trim($separated[0]),
'url' => trim($separated[1])
) );
}
if (empty($new) )
add_post_meta($post_id, 'custom_video', $new, true);
elseif (!empty( $new ) && $new != $old )
update_post_meta($post_id, 'custom_video', $new, true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment