sub_categories_array = array(); foreach ($pt->sub_categories as $cat_key => $subs) { $pt->sub_categories_array["'".$cat_key."'"] = ''; foreach ($subs as $sub_key => $sub_value) { $selected = ''; if (!empty($_GET['sub_category_id'])) { $selected = ($_GET['sub_category_id'] == $sub_key) ? 'selected' : ''; } $pt->sub_categories_array["'".$cat_key."'"] .= ''; } } $query = ''; $offset = ''; $cursor = ''; $multi_query = ''; $limit = 50; $respond_error = 0; $twitch_user_id = 0; $page_id = 1; $page = 'current'; if (empty($pt->config->twitch_api)) { $respond_error = 1; $error_text = 'please put your Twitch Client Id in Settings > General Settings to start import videos from Twitch.'; } if (!empty($_GET['query']) || !empty($_GET['multi-query'])) { if (empty($pt->config->twitch_access_token)) { header("Location: https://id.twitch.tv/oauth2/authorize?client_id=".$pt->config->twitch_api."&scope=bits:read+openid&response_type=token%20id_token&redirect_uri=".PT_LoadAdminLinkSettings('import-from-twitch')); exit(); } if (!empty($_GET['query'])) { $query = PT_Secure($_GET['query']); } $clientId = $pt->config->twitch_api; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://api.twitch.tv/helix/search/channels?query='.$query); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET'); $headers = array(); $headers[] = 'Client-ID: ' . $clientId; $headers[] = 'Authorization: Bearer '.$pt->config->twitch_access_token; curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $result = curl_exec($ch); if (curl_errno($ch)) { echo 'Error:' . curl_error($ch); } curl_close($ch); if (!empty($result)) { $json = json_decode($result,true); if (!empty($json) && !empty($json['data'])) { $twitch_user_id = $json['data'][0]['id']; if (!empty($_GET['limit']) && $limit < 101) { $limit = (int) PT_Secure($_GET['limit']); } if (!empty($_GET['page-query'])) { $page = $_GET['page-query']; } if (!empty($_GET['cursor'])) { $cursor = PT_Secure($_GET['cursor']); } $query = urlencode($query); for ($i=0; $i < 100; $i++) { $channelsApi = 'https://api.twitch.tv/helix/videos?first='.$limit.'&user_id='.$twitch_user_id; if (!empty($cursor) && $page == 'next') { $channelsApi = 'https://api.twitch.tv/helix/videos?first='.$limit.'&after='.$cursor.'&user_id='.$twitch_user_id; } if (!empty($cursor) && $page == 'previous') { $channelsApi = 'https://api.twitch.tv/helix/videos?first='.$limit.'&before='.$cursor.'&user_id='.$twitch_user_id; } $ch = curl_init(); curl_setopt_array($ch, array( CURLOPT_HTTPHEADER => array( 'Client-ID: ' . $clientId, 'Authorization: Bearer '.$pt->config->twitch_access_token ), CURLOPT_RETURNTRANSFER => true, CURLOPT_URL => $channelsApi )); $response = curl_exec($ch); curl_close($ch); if (!empty($response)) { $get_videos = json_decode($response,true); if (!empty($get_videos['data'])) { if (!empty($get_videos['pagination']) && !empty($get_videos['pagination']['cursor'])) { $cursor = PT_Secure($get_videos['pagination']['cursor']); $page = 'next'; } $ids = array(); foreach ($get_videos['data'] as $key => $video) { $check_if_exists = $db->where('twitch', $video['id'])->getValue(T_VIDEOS, 'count(*)'); if ($check_if_exists == 0) { $ids[] = $video['id']; } } if (!empty($ids)) { break; } else{ } } elseif (!empty($get_videos) && !empty($get_videos['error']) && !empty($get_videos['message'])) { $respond_error = 1; $error_text = $get_videos['message']; break; } } else{ $respond_error = 1; $error_text = 'No videos found'; } } } elseif (!empty($json) && !empty($json['error']) && !empty($json['message'])) { if (strtolower($json['error']) == 'unauthorized') { header("Location: https://id.twitch.tv/oauth2/authorize?client_id=".$pt->config->twitch_api."&scope=bits:read+openid&response_type=token%20id_token&redirect_uri=".PT_LoadAdminLinkSettings('import-from-twitch')); exit(); } $respond_error = 1; $error_text = $json['message']; } } else{ $respond_error = 1; $error_text = 'Something went wrong Please try again later'; } } $user_id = 0; $username = ''; if (!empty($_GET['username']) && isset($_GET['username'])) { $username = PT_Secure($_GET['username']); $user = $db->where('username', $username)->getOne(T_USERS); if (!empty($user)) { $user_id = $user->id; } else{ $respond_error = 1; $error_text = 'user not found'; } } $category_filter = array_keys(ToArray($pt->categories))[0]; if (!empty($_GET['category_id'])) { if (in_array($_GET['category_id'], array_keys(ToArray($pt->categories)))) { $category_filter = $_GET['category_id']; } } $get_ini = ini_get('max_input_vars'); $auto_import = 0; if (!empty($_GET['auto_import'])) { $auto_import = 1; } ?>

Import From Twitch

If you want to import more than 180 videos by one click, you need to increase max_input_vars in your php.ini file.
Import Videos From Twitch
sub_categories_array["'1'"])) { ?> style="display: none;" id="sub_category_div">

Videos

$video) { $video['new_duration'] = '00:00'; $hour_added = false; $min_added = false; if (strpos($video['duration'], 'h') !== false) { $hour = explode('h', $video['duration']); if (!empty($hour) && !empty($hour[0]) && is_numeric($hour[0])) { if ($hour[0] < 10) { $video['new_duration'] = '0'.$hour[0]; } else{ $video['new_duration'] = $hour[0]; } $video['duration'] = $hour[1]; $hour_added = true; } } if (strpos($video['duration'], 'm') !== false) { $min = explode('m', $video['duration']); if (!empty($min) && !empty($min[0]) && is_numeric($min[0])) { if ($hour_added) { $video['new_duration'] .= ':'; } if ($min[0] < 10) { if ($hour_added) { $video['new_duration'] .= '0'.$min[0]; } else{ $video['new_duration'] = '0'.$min[0]; } } else{ if ($hour_added) { $video['new_duration'] .= $min[0]; } else{ $video['new_duration'] = $min[0]; } } $video['duration'] = $min[1]; $min_added = true; } } if (strpos($video['duration'], 's') !== false) { $sec = explode('s', $video['duration']); if (!empty($sec) && !empty($sec[0]) && is_numeric($sec[0])) { if ($min_added) { $video['new_duration'] .= ':'; } if ($sec[0] < 10) { if ($min_added) { $video['new_duration'] .= '0'.$sec[0]; } else{ $video['new_duration'] = '00:0'.$sec[0]; } } else{ if ($min_added) { $video['new_duration'] .= $sec[0]; } else{ $video['new_duration'] = '00:'.$sec[0]; } } $min_added = true; } } $thumb = PT_GetMedia('upload/photos/thumbnail.jpg'); if (!empty($video['thumbnail_url'])) { $thumb = str_replace('%{width}', '00', $video['thumbnail_url']); $thumb = str_replace('%{height}', '00', $thumb); } $thumb = str_replace('http://', 'https://', $thumb); $tags = ''; $duration = '00:00'; if (!empty($video['new_duration'])) { $duration = $video['new_duration']; } $title = ''; if (!empty($video['title'])) { $title = $video['title']; } $description = ''; if (!empty($video['description'])) { $description = $video['description']; } $array_data = array( 'ID' => $video['id'], 'TITLE' => $title, 'DESC' => $description, 'THUMB' => $thumb, 'TAGS' => $tags, 'DURATION' => $duration ); echo PT_LoadAdminPage('import-from-twitch/list', $array_data); } } else { echo '
No videos found, try another page.
'; } ?>

Auto Import Successfully Completed!

videos successfully imported.

Error found while fetching the videos!