Youtube にはAPIがあるので、これまで紹介してきたのと同様にPowerShellでAPIを叩いて検索が可能です。これを使えば、PowerShell DSC のセッションなど多くの「海外のセッション動画」が取得できるのです。*1
年末、年始の時間を利用してセッション動画を見てみたい人にどうぞ。
目次
API仕様
何はともあれ、API仕様を知っておかないとですね。
検索してみよう
ということで DSC についてでも探しましょう。
クエリは、 Desired
State
Configuration
PowerShell
の組み合わせで。
Invoke-RestMethod -uri "https://gdata.youtube.com/feeds/api/videos?v=2&q=Desired+State+Configuration+PowerShell"
etag : W/"CEcAQH47eCp7I2A9WhFSEE0." id : tag:youtube.com,2008:video:ZbyyVqTr-es published : 2013-06-12T01:54:01.000Z updated : 2013-06-12T01:54:01.000Z category : {category, category} title : Desired State Configuration in Windows Server 2012 R2 PowerShell content : content link : {link, link, link, link...} author : author accessControl : {yt:accessControl, yt:accessControl, yt:accessControl, yt:accessControl...} group : group statistics : statistics etag : W/"C0cNR347eCp7I2A9Wh5QGUw." id : tag:youtube.com,2008:video:0m_AecJOLF0 published : 2013-11-08T11:30:42.000Z updated : 2013-11-08T11:44:56.000Z category : {category, category} title : Community Video - Desired State Configuration in PowerShell 4.0 content : content link : {link, link, link, link...} author : author accessControl : {yt:accessControl, yt:accessControl, yt:accessControl, yt:accessControl...} comments : comments group : group statistics : statistics etag : W/"CE8DR347eCp7I2A9Wh5WGUQ." id : tag:youtube.com,2008:video:ELZkFG143iE published : 2013-08-19T20:57:11.000Z updated : 2013-12-02T14:01:16.000Z category : {category, category} title : Desired State Configuration in Windows Server 2012 R2 PowerShell content : content link : {link, link, link, link...} author : author accessControl : {yt:accessControl, yt:accessControl, yt:accessControl, yt:accessControl...} group : group statistics : statistics etag : W/"D0YBRH47eCp7I2A9Wh5WFE8." id : tag:youtube.com,2008:video:w3A2RmppBG4 published : 2013-07-11T20:59:53.000Z updated : 2013-11-26T00:19:15.000Z category : {category, category} title : DevOps, Desired State, and Microsoft Windows content : content link : {link, link, link, link...} author : author accessControl : {yt:accessControl, yt:accessControl, yt:accessControl, yt:accessControl...} comments : comments group : group rating : {gd:rating, yt:rating} statistics : statistics etag : W/"CU4ARn47eCp7I2A9Wh5WFks." id : tag:youtube.com,2008:video:iqoF89cYeBg published : 2013-11-28T08:26:55.000Z updated : 2013-11-28T18:39:07.000Z category : {category, category} title : Windows Server 2012 Tutorial: Desired State Configuration |video2brain.com content : content link : {link, link, link, link...} author : author accessControl : {yt:accessControl, yt:accessControl, yt:accessControl, yt:accessControl...} comments : comments where : where hd : group : group rating : {gd:rating, yt:rating} statistics : statistics etag : W/"D0UGSX47eCp7I2A9Wh5QE08." id : tag:youtube.com,2008:video:_EHNQAL4Unw published : 2013-11-01T06:36:40.000Z updated : 2013-11-01T17:00:28.000Z category : {category, category} title : Использование PowerShell Desired State Configuration content : content link : {link, link, link, link...} author : author accessControl : {yt:accessControl, yt:accessControl, yt:accessControl, yt:accessControl...} comments : comments hd : group : group rating : {gd:rating, yt:rating} statistics : statistics etag : W/"CEAFQH47eCp7I2A9Wh5UFEU." id : tag:youtube.com,2008:video:zYWHfY8_oyg published : 2013-12-19T19:51:51.000Z updated : 2013-12-19T19:51:51.000Z category : {category, category} title : PowerShell Desired State Configuration DSC and Windows DevOps content : content link : {link, link, link, link...} author : author accessControl : {yt:accessControl, yt:accessControl, yt:accessControl, yt:accessControl...} comments : comments hd : group : group statistics : statistics etag : W/"CEMMRn47eCp7I2A9Wh5TEEw." id : tag:youtube.com,2008:video:heMj0ePj57A published : 2013-09-22T23:11:53.000Z updated : 2013-09-24T08:48:07.000Z category : {category, category} title : PowerShell4 Desired State Configuration In Windows 8.1 RTM content : content link : {link, link, link, link...} author : author accessControl : {yt:accessControl, yt:accessControl, yt:accessControl, yt:accessControl...} comments : comments hd : group : group rating : {gd:rating, yt:rating} statistics : statistics etag : W/"DEMGQ347eCp7I2A9Wh5XGU8." id : tag:youtube.com,2008:video:0-VetSMhGLY published : 2013-11-15T19:22:05.000Z updated : 2013-11-20T05:47:02.000Z category : {category, category} title : System Center Virtual User Group #22 JoeThompson Session content : content link : {link, link, link, link...} author : author accessControl : {yt:accessControl, yt:accessControl, yt:accessControl, yt:accessControl...} comments : comments group : group statistics : statistics etag : W/"DEcCR347eCp7I2A9Wh5VEEk." id : tag:youtube.com,2008:video:x7-m44NcGWU published : 2013-04-09T18:08:58.000Z updated : 2013-12-03T04:47:46.000Z category : {category, category} title : 4. Using Powershell in Windows Server 2012 to configure DHCP server content : content link : {link, link, link, link...} author : author accessControl : {yt:accessControl, yt:accessControl, yt:accessControl, yt:accessControl...} comments : comments hd : group : group rating : {gd:rating, yt:rating} statistics : statistics etag : W/"CkcCRX47eCp7I2A9WhBaGEg." id : tag:youtube.com,2008:video:e3bivT9BIYg published : 2013-05-29T17:54:24.000Z updated : 2013-05-29T17:54:24.000Z category : {category, category} title : Advanced Automation Using Windows PowerShell 30 content : content link : {link, link, link, link...} author : author accessControl : {yt:accessControl, yt:accessControl, yt:accessControl, yt:accessControl...} hd : group : group statistics : statistics etag : W/"D08CSX47eCp7I2A9Wh5VFE4." id : tag:youtube.com,2008:video:3HAjO8yiANM published : 2013-06-15T12:54:02.000Z updated : 2013-12-07T17:04:28.000Z category : {category, category} title : Creating SharePoint Service Applications with Powershell content : content link : {link, link, link, link...} author : author accessControl : {yt:accessControl, yt:accessControl, yt:accessControl, yt:accessControl...} comments : comments hd : group : group rating : {gd:rating, yt:rating} statistics : statistics etag : W/"DEMASH47eCp7I2A9WhFaE0o." id : tag:youtube.com,2008:video:bzOJdD8nE3Y published : 2013-09-17T00:07:29.000Z updated : 2013-09-17T00:07:29.000Z category : {category, category} title : 10 Ways to Conquer Your Fear of PowerShell content : content link : {link, link, link, link...} author : author accessControl : {yt:accessControl, yt:accessControl, yt:accessControl, yt:accessControl...} group : group statistics : statistics etag : W/"DUIHR347eCp7I2A9WhBXGUQ." id : tag:youtube.com,2008:video:cMMWiOtCc6Y published : 2013-04-03T13:58:56.000Z updated : 2013-04-03T13:58:56.000Z category : {category, category} title : Windows Azure PowerShell Demos - EPC Group content : content link : {link, link, link, link...} author : author accessControl : {yt:accessControl, yt:accessControl, yt:accessControl, yt:accessControl...} group : group statistics : statistics etag : W/"C0MHQX47eCp7I2A9Wh5WEUU." id : tag:youtube.com,2008:video:G4Lk6cGqubQ published : 2013-03-18T10:30:41.000Z updated : 2013-11-23T04:37:10.000Z control : control category : {category, category} title : Server 2012 NIC Teaming Powershell - Video 30 content : content link : {link, link, link, link} author : author accessControl : {yt:accessControl, yt:accessControl, yt:accessControl, yt:accessControl...} comments : comments hd : group : group rating : {gd:rating, yt:rating} statistics : statistics etag : W/"CUQMRH47eCp7I2A9Wh5WEkU." id : tag:youtube.com,2008:video:4GNPfaokP6U published : 2013-03-18T17:44:47.000Z updated : 2013-11-24T08:56:25.000Z category : {category, category} title : Server 2012 Core Ip Dns Join Domain (PowerShell) content : content link : {link, link, link, link...} author : author accessControl : {yt:accessControl, yt:accessControl, yt:accessControl, yt:accessControl...} comments : comments group : group rating : {gd:rating, yt:rating} statistics : statistics etag : W/"DkIMRX47eCp7I2A9Wh5VFko." id : tag:youtube.com,2008:video:tXbk9quKshQ published : 2013-12-10T11:21:23.000Z updated : 2013-12-10T11:23:04.000Z category : {category, category} title : Install SharePoint 2013 with PowerShell - Setup Configuration Intro content : content link : {link, link, link, link...} author : author accessControl : {yt:accessControl, yt:accessControl, yt:accessControl, yt:accessControl...} comments : comments hd : group : group statistics : statistics etag : W/"DUcAQn47eCp7I2A9Wh5UF0s." id : tag:youtube.com,2008:video:agTxrXtwVns published : 2012-12-17T22:35:17.000Z updated : 2013-12-23T02:50:43.000Z control : control category : {category, category} title : Windows Server 2012 NIC Teaming with Powershell content : content link : {link, link, link, link} author : author accessControl : {yt:accessControl, yt:accessControl, yt:accessControl, yt:accessControl...} comments : comments hd : group : group rating : {gd:rating, yt:rating} statistics : statistics etag : W/"A0cFQ347eCp7I2A9Wh5UEUg." id : tag:youtube.com,2008:video:Y3e_KeE4t0E published : 2013-06-04T19:31:12.000Z updated : 2013-12-16T01:56:52.000Z category : {category, category} title : Windows Server 2012 - PowerShell - Introduccion content : content link : {link, link, link, link...} author : author accessControl : {yt:accessControl, yt:accessControl, yt:accessControl, yt:accessControl...} comments : comments where : where hd : group : group rating : {gd:rating, yt:rating} recorded : 2013-06-04 statistics : statistics etag : W/"CUAFQn47eCp7I2A9Wh5UEkQ." id : tag:youtube.com,2008:video:8cCinfjV-q4 published : 2013-02-24T19:50:15.000Z updated : 2013-12-17T15:21:53.000Z category : {category, category} title : Windows PowerShell - Variables, Types, and Operators - EPC Group content : content link : {link, link, link, link...} author : author accessControl : {yt:accessControl, yt:accessControl, yt:accessControl, yt:accessControl...} group : group statistics : statistics etag : W/"C0AERH47eCp7I2A9Wh5VFkQ." id : tag:youtube.com,2008:video:0rE6kXvK8J8 published : 2013-04-17T14:26:59.000Z updated : 2013-12-10T16:08:25.000Z category : {category, category} title : Take Control of the Cloud with the Windows Azure PowerShell Cmdlets content : content link : {link, link, link, link...} author : author accessControl : {yt:accessControl, yt:accessControl, yt:accessControl, yt:accessControl...} hd : group : group statistics : statistics etag : W/"A0QFRn47eCp7I2A9Wh5SGUg." id : tag:youtube.com,2008:video:S0qoBXZDeSU published : 2013-02-05T01:12:23.000Z updated : 2013-10-16T21:35:17.000Z category : {category, category} title : MicroNugget: PowerShell v3 Remoting in Windows Server 2012 content : content link : {link, link, link, link...} author : author accessControl : {yt:accessControl, yt:accessControl, yt:accessControl, yt:accessControl...} comments : comments hd : group : group rating : {gd:rating, yt:rating} statistics : statistics etag : W/"C0UGQH47eCp7I2A9WhBWGUo." id : tag:youtube.com,2008:video:hCa2GvDOsQo published : 2013-04-14T20:27:01.000Z updated : 2013-04-14T20:27:01.000Z category : {category, category} title : Automate Hyper-V with PowerShell and C# - EPC Group content : content link : {link, link, link, link...} author : author accessControl : {yt:accessControl, yt:accessControl, yt:accessControl, yt:accessControl...} hd : group : group statistics : statistics etag : W/"AkECRX47eCp7I2A9WhBTE0Q." id : tag:youtube.com,2008:video:PVyraGz4K1c published : 2013-02-09T08:31:04.000Z updated : 2013-02-09T08:31:04.000Z category : {category, category} title : Group Policy Reporting and Analysis with Windows PowerShell - EPC Group content : content link : {link, link, link, link...} author : author accessControl : {yt:accessControl, yt:accessControl, yt:accessControl, yt:accessControl...} hd : group : group statistics : statistics etag : W/"C0AARH47eCp7I2A9WhBWEkg." id : tag:youtube.com,2008:video:Sb6jFZZ0ZpU published : 2013-04-06T12:35:45.000Z updated : 2013-04-06T12:35:45.000Z category : {category, category} title : Creating a Failover Cluster using Powershell content : content link : {link, link, link, link...} author : author accessControl : {yt:accessControl, yt:accessControl, yt:accessControl, yt:accessControl...} comments : comments hd : group : group statistics : statistics
見にくいので絞りましょう。
タイトル、公開日、更新日、作者、リンクアドレスを、公開日順に表示します。
Invoke-RestMethod -uri "https://gdata.youtube.com/feeds/api/videos?v=2&q=DSC+PowerShell" ` | %{[PSCustomObject]@{ Title = $_.title Published = $_.published Updated = $_.Updated Author = $_.author.name Link = $_.content.src }} ` | sort Published -Descending
Title : Xbox One Giveaway Published : 2013-12-26T23:05:04.000Z Updated : 2013-12-29T08:25:33.000Z Author : TechnoScoop Link : https://www.youtube.com/v/yRxYH0P-WrM?version=3&f=videos&app=youtube_gdata Title : Top 5 iOS 7 Jailbreak Tweaks Published : 2013-12-25T23:34:48.000Z Updated : 2013-12-27T20:07:21.000Z Author : TechnoScoop Link : https://www.youtube.com/v/My35PjOccj8?version=3&f=videos&app=youtube_gdata Title : PowerShell Desired State Configuration DSC and Windows DevOps Published : 2013-12-19T19:51:51.000Z Updated : 2013-12-19T19:51:51.000Z Author : Siva Padisetty Link : https://www.youtube.com/v/zYWHfY8_oyg?version=3&f=videos&app=youtube_gdata Title : Alcatel_itol_s_knockon Published : 2013-12-19T14:39:22.000Z Updated : 2013-12-28T08:12:52.000Z Author : demo ringhk Link : https://www.youtube.com/v/K-EnDCBVgPQ?version=3&f=videos&app=youtube_gdata Title : Columna de Tecnologia Telefe Noticias Rosario: Accesorios Logitech Published : 2013-12-14T19:21:43.000Z Updated : 2013-12-18T23:25:01.000Z Author : TEKNOMEDIA ROSARIO Link : https://www.youtube.com/v/5eNiQ5SQ8V4?version=3&f=videos&app=youtube_gdata Title : Honeydru Car Charger Review Published : 2013-11-26T01:02:32.000Z Updated : 2013-12-26T00:05:20.000Z Author : TechnoScoop Link : https://www.youtube.com/v/4hdTXg_93LE?version=3&f=videos&app=youtube_gdata Title : Science Protocol - Part 3 Published : 2013-11-25T21:34:13.000Z Updated : 2013-12-09T16:27:13.000Z Author : Raumina Rezai Link : https://www.youtube.com/v/HJyXL7Ht6rg?version=3&f=videos&app=youtube_gdata Title : System Center Virtual User Group #22 JoeThompson Session Published : 2013-11-15T19:22:05.000Z Updated : 2013-11-20T05:47:02.000Z Author : Scott Moss Link : https://www.youtube.com/v/0-VetSMhGLY?version=3&f=videos&app=youtube_gdata Title : Odoyo PowerShell Ex Review Published : 2013-11-10T18:48:42.000Z Updated : 2013-12-26T00:06:30.000Z Author : TechnoScoop Link : https://www.youtube.com/v/nlYVlHGReJU?version=3&f=videos&app=youtube_gdata Title : Sony Cybershot DSC-WX9 Review Published : 2013-11-08T20:26:49.000Z Updated : 2013-12-26T00:06:34.000Z Author : TechnoScoop Link : https://www.youtube.com/v/FjOtJKOecmc?version=3&f=videos&app=youtube_gdata Title : Community Video - Desired State Configuration in PowerShell 4.0 Published : 2013-11-08T11:30:42.000Z Updated : 2013-11-08T11:44:56.000Z Author : MVP South Asia Link : https://www.youtube.com/v/0m_AecJOLF0?version=3&f=videos&app=youtube_gdata Title : Jupiter - high exposure Published : 2013-11-04T18:18:41.000Z Updated : 2013-11-04T18:22:30.000Z Author : karczas Link : https://www.youtube.com/v/iMBNCKVU3HE?version=3&f=videos&app=youtube_gdata Title : Использование PowerShell Desired State Configuration Published : 2013-11-01T06:36:40.000Z Updated : 2013-11-01T17:00:28.000Z Author : Журнал "Системный администратор" Link : https://www.youtube.com/v/_EHNQAL4Unw?version=3&f=videos&app=youtube_gdata Title : The new PowerShell? for the Z1? Published : 2013-10-24T02:08:59.000Z Updated : 2013-10-24T02:11:09.000Z Author : HDMUSA Link : https://www.youtube.com/v/yPKqkBwnPZ8?version=3&f=videos&app=youtube_gdata Title : Download Site Creator - Script Published : 2013-10-18T03:02:16.000Z Updated : 2013-10-18T03:02:16.000Z Author : WhyWhyComeBack Link : rtsp://r2---sn-a5m7zu7e.c.youtube.com/CiILENy73wIaGQknaiW9m3ooYRMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp Title : PowerShell4 Desired State Configuration In Windows 8.1 RTM Published : 2013-09-22T23:11:53.000Z Updated : 2013-09-24T08:48:07.000Z Author : Mohamed Meligy Link : https://www.youtube.com/v/heMj0ePj57A?version=3&f=videos&app=youtube_gdata Title : Desired State Configuration in Windows Server 2012 R2 PowerShell Published : 2013-08-19T20:57:11.000Z Updated : 2013-12-02T14:01:16.000Z Author : EPC Group.net Link : https://www.youtube.com/v/ELZkFG143iE?version=3&f=videos&app=youtube_gdata Title : WSUS FINAL Published : 2013-07-09T16:37:55.000Z Updated : 2013-07-09T16:37:55.000Z Author : henriquez hhenriquez Link : https://www.youtube.com/v/-y2GIWKpsQs?version=3&f=videos&app=youtube_gdata Title : Desired State Configuration in Windows Server 2012 R2 PowerShell Published : 2013-06-12T01:54:01.000Z Updated : 2013-06-12T01:54:01.000Z Author : EPC Group.net Link : https://www.youtube.com/v/ZbyyVqTr-es?version=3&f=videos&app=youtube_gdata Title : New Software for DSC 2012 Recruitment: New Guidelines for DSC 2012 Recruitments Published : 2012-10-27T06:02:42.000Z Updated : 2012-10-27T06:02:43.000Z Author : aegindia Link : https://www.youtube.com/v/4IU2r5hvkho?version=3&f=videos&app=youtube_gdata Title : power shell rocket 4 Published : 2012-10-09T03:22:05.000Z Updated : 2013-06-06T02:08:05.000Z Author : Jamietje punt Link : https://www.youtube.com/v/6fyHiqbf8g8?version=3&f=videos&app=youtube_gdata Title : DSC 9725 Published : 2012-02-27T22:32:54.000Z Updated : 2013-09-29T10:32:09.000Z Author : Тученька Link : https://www.youtube.com/v/dAbblamONqM?version=3&f=videos&app=youtube_gdata Title : 2 Z-5500's & 2 Z-2300's - Mic Test on Sony DSC-S930 Published : 2011-09-29T19:59:04.000Z Updated : 2013-12-04T00:56:15.000Z Author : al3x440 Link : https://www.youtube.com/v/G5Y8IS1qIe8?version=3&f=videos&app=youtube_gdata Title : 08-18-11 Practice 78 Published : 2011-08-19T02:28:18.000Z Updated : 2011-08-27T17:12:37.000Z Author : miteymites11 Link : https://www.youtube.com/v/LpR9asIikhY?version=3&f=videos&app=youtube_gdata Title : DSC Business Accounting Training Published : 2011-02-16T21:21:04.000Z Updated : 2011-02-16T21:21:04.000Z Author : cmidsc Link : https://www.youtube.com/v/LboXvvgi_Xc?version=3&f=videos&app=youtube_gdata
前回の記事でやったようにブラウザで自動表示すれば、検索結果をすぐに確認できます。
後は PowerShellでフィルタかけられるので便利ですね。
本題
さて検索はおまけで、本題はPowerShell でもヘルパーを用意したらどうだろうなのです、はい。
つまり、必要となる処理を事前に定義してしまう方向で考えようということです。
対象のスクリプト
Invoke-RestMethod -uri "https://gdata.youtube.com/feeds/api/videos?v=2&q=DSC+PowerShell" ` | %{[PSCustomObject]@{ Title = $_.title Published = $_.published Updated = $_.Updated Author = $_.author.name Link = $_.content.src }} ` | sort Published -Descending
この中の Foreach-Object で処理しているオブジェクトの合成。これを事前定義してしまうことができます。
Filter を利用する
パイプラインに入力されたストリームを順次処理する。これは、PowerShell において Filter で処理されるのが定石です。
Functionがストリーム経由でパイプラインに渡されたオブジェクト全体を1つとして処理していたにのに対して、Filter を使えばパイプラインへの入力をストリーム処理 -> 各オブジェクトを順次処理可能になります。簡単にいうと、process{} 節だけをもつFunctionなのですが、まぁ便利です。
で、今回のをFilterを使って、オブジェクト処理を定義するとこのようになります。
filter Filter-YoutubeApi { [PSCustomObject]@{ Title = [string]$_.title Published = [datetime]$_.published Updated = [datetime]$_.Updated Author = [string]$_.author.name Link = [uri]$_.content.src } }
これでどう変わるかというと、記述がこれで済みます。
Invoke-RestMethod -uri "https://gdata.youtube.com/feeds/api/videos?v=2&q=DSC+PowerShell" ` | Filter-YoutubeApi ` | sort Published -Descending `
何度も登場するストリーム処理パターンを定義しておく。他言語でやる手法が、今ようやくPowerShellでも取り上げられつつあります。*2
まとめ
近くいくつかのパターンをまとめる予定です。map や reduce などの処理をまとめておいて、Moduleに組み込む。こういったやり方でコレクションを処理しやすくなります。
ちなみに、Filter はPowerShell におけるパイプラインを通した繰り返し処理で最速の手段です。Foreach-Object や V3の省略記法 などよりずっと早いです。Where-Objectなどのコレクションフィルタリングでも示しています。
GitHubにおいておきます。