daily pastebin goal
40%
SHARE
TWEET

Untitled

a guest Jul 17th, 2016 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Get-youtubesearch() {
  2. Param(
  3.     [Parameter(Mandatory = $true)][string]$search,
  4.     [AllowEmptyString()]$max_page = 5,
  5.     [AllowEmptyString()]$copyright = "any",
  6.     [AllowEmptyString()]$youtube_key="<your key>"
  7. )
  8.    
  9. $Search_results = invoke-restmethod "https://www.googleapis.com/youtube/v3/search?part=snippet&q=$search&type=video&videoLicense=$copyright&key=$youtube_key"
  10. $page_count = 1
  11. $video_list = @()
  12.  
  13.     while(($Search_results.nextPageToken) -and ($page_count -le $max_page)) {
  14.     $next_page=$Search_results.nextPageToken
  15.  
  16.         foreach($video_info in $search_results.items) {
  17.         $video_id = $video_info.id.videoid
  18.         $video_stats = invoke-restmethod "https://www.googleapis.com/youtube/v3/videos?part=statistics&id=$video_id&key=$youtube_key"
  19.         [int]$views = $video_stats.items.statistics.viewcount
  20.         [int]$likes = $video_stats.items.statistics.likecount
  21.         [int]$dislikes = $video_stats.items.statistics.dislikeCount
  22.         $title = $video_info.snippet.title
  23.         $link = "https://youtube.com/watch?v=$video_id"
  24.  
  25.             $video_list += new-object psobject -Property @{
  26.                 title = "$title";
  27.                 video_id = "$video_id";
  28.                 likes = $likes;
  29.                 dislikes = $dislikes;
  30.                 views = "$views";
  31.                 link = "$link";
  32.             }          
  33.        
  34.         }
  35.  
  36.     $Search_results = invoke-restmethod "https://www.googleapis.com/youtube/v3/search?part=snippet&pageToken=$next_page&type=video&q=$search&videoLicense=$copyright&key=$youtube_key"
  37.     $page_count++
  38.     }
  39.    
  40. return $video_list
  41. }
  42.  
  43. function get-youtubepopular() {
  44. Param(
  45.     [AllowEmptyString()]$max_page = 5,
  46.     [AllowEmptyString()]$copyright = "any",
  47.     [AllowEmptyString()]$youtube_key="<your key>"
  48. )
  49.  
  50. $Search_results = invoke-restmethod "https://www.googleapis.com/youtube/v3/videos?chart=mostPopular&key=$youtube_key&part=snippet"
  51. $page_count = 1
  52. $video_list = @()
  53.  
  54.     while(($Search_results.nextPageToken) -and ($page_count -le $max_page)) {
  55.     $next_page=$Search_results.nextPageToken
  56.  
  57.         foreach($video_info in $search_results.items) {
  58.         $video_id = $video_info.id
  59.         echo "second search"
  60.         $video_stats = invoke-restmethod "https://www.googleapis.com/youtube/v3/videos?part=statistics&id=$video_id&key=$youtube_key"
  61.         [int]$views = $video_stats.items.statistics.viewcount
  62.         [int]$likes = $video_stats.items.statistics.likecount
  63.         [int]$dislikes = $video_stats.items.statistics.dislikeCount
  64.         $title = $video_info.snippet.title
  65.         $link = "https://youtube.com/watch?v=$video_id"
  66.  
  67.             $video_list += new-object psobject -Property @{
  68.                 title = "$title";
  69.                 video_id = "$video_id";
  70.                 likes = $likes;
  71.                 dislikes = $dislikes;
  72.                 views = $views;
  73.                 link = "$link";
  74.             }          
  75.        
  76.         }
  77.  
  78.     $Search_results = invoke-restmethod "https://www.googleapis.com/youtube/v3/videos?chart=mostPopular&pageToken=$next_page&key=$youtube_key"
  79.     $page_count++
  80.     }
  81.    
  82. return $video_list
  83. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top