################################################################################################### # "TINAMIwall / 他人任せの壁紙 for TINAMI version 20160125" " by gori.sh (http://gori.sh aoki@gori.sh @gori_sh)" # #-------------------------------------------------------------------------------------------------- # # このスクリプトは、TINAMI(http://www.tinami.com)の20位までのランキング(http://www.tinami.com/ranking) # からランダムで画像を選び出し、デスクトップの壁紙に設定するスクリプトです。 # # 実行には Windows PowerShell が必要です。v2.0で動作確認をしています。 # # Windows 7,8 では標準搭載されています。 # Windows XP、Windows Server 2003、Windows Vista、および Windows Server 2008 の方は、 # こちらからダウンロードしてください。http://support.microsoft.com/kb/968929 # # エクスプローラの右クリックから「PowerShellで実行」を選ぶと、壁紙が変更されます。 # # ※実行出来ない場合 # 管理ツール → Windows PowerShell Modules を起動 # 入力画面で "Set-ExecutionPolicy Unrestricted" と入力、実行 # するとps1スクリプトが実行可能になります。 # # ※最小化で実行する場合 # tinamiwall.vbsをご利用下さい。 # http://gori.sh/program/archive/tinamiwall.vbs # # ※タスクスケジューラから実行する場合 # powershell (path)tinamiwall.ps1 、 # もしくは上記のtinamiwall.vbsを登録してください。 # ################################################################################################## # # オプション はここで指定してください。 # カテゴリを指定します。 # 1:イラスト 3:モデル 5:コスプレ になります。(マンガと小説は選択出来ません) $category = 1 # ダウンロードした作品を保存するファイル名を指定します。 # 空欄の場合、マイピクチャ以下にtinamiwallというファイルを作成します。 $file = "" # ################################################################################################### # # バージョン情報 # 20160125 無限ループに陥るパターンがあったため、対処 # 20140120 一部のディスプレイドライバでリサイズ機能が動いていなかったバグを除去 # 20131203 ユーザ限定画像を引いた場合に壁紙が変わらないバグを除去 # 20110816 最小化実行とかマニュアルとオプションの整備 # 20110801 壁紙の描き変えを安定化(SystemParametersInfo) # 縦横比を変えずにデスクトップに合うようリサイズ # 20110728 初期版 # ################################################################################################### #以下プログラム # TINAMI-api アクセス用キー $apikey="4e3102ccb9b7d" # 保存先ディレクトリ(デフォルトではマイピクチャ\tinamiwall) if($file -eq ""){ $file=[System.Environment]::getFolderPath([System.Environment+SpecialFolder]::MyPictures) + "\WallpaperDaily" } $file2 = $file + "_.bmp" # ID指定、デバグ用 $id = 0 #--- $error.clear() function get-url([string]$url) { [void]([Reflection.Assembly]::LoadWithPartialName("System.Web")) $webReq = [Net.HttpWebRequest]::Create($url) $webReq.TimeOut = 60000 # 60000=1分 $webReq.Method = "GET" $webReq.UserAgent = "TINAMIwall version 20160125" $webRes = $webReq.GetResponse() if($error.count -ne 0){exit 0} $reader = New-Object IO.StreamReader($webRes.GetResponseStream(), $webRes.ContentEncoding) $reader.ReadToEnd() $reader.Close() $webRes.Close() } do{ if($id -eq 0){ "--ランキングの取得中" # http://api.tinami.com/ranking?api_key=4e3102ccb9b7d&category=1 $http=get-url("http://api.tinami.com/ranking?api_key=" + $apikey + "&category=" + $category) $id=(([xml]$http).rsp.contents.content | get-random).id } "--画像情報の取得中" "id : " + $id # http://api.tinami.com/content/info?api_key=4e3102ccb9b7d&cont_id= $http=get-url("http://api.tinami.com/content/info?api_key=" + $apikey + "&cont_id=" + $id) $xml=[xml]$http if($xml.rsp.stat -ne "ok"){ $id=0 } } while ($id -eq 0) "title : " + $xml.rsp.content.title "creator : " + $xml.rsp.content.creator.name "--画像のダウンロード中" # ※非公開だが、認証の必要が無ければ http://api.tinami.com/image?api_key=4e3102ccb9b7d&cont_id= でいけるらしい $wc = New-Object Net.WebClient $wc.Credentials = [System.Net.CredentialCache]::DefaultCredentials $wc.DownloadFile($xml.rsp.content.image.url, $file) $wc.Dispose(); "--リサイズ中" [void][reflection.assembly]::loadwithpartialname("system.drawing") [void][reflection.assembly]::loadwithpartialname("system.drawing.imaging") $srcImg=new-object system.drawing.bitmap($file) $ximg=$srcImg.width $yimg=$srcImg.height $xdes=(gwmi win32_videocontroller).currenthorizontalresolution $ydes=(gwmi win32_videocontroller).currentverticalresolution if(($xdes -gt 0) -and ($ydes -gt 0)){ $pimg=($ximg / $yimg) $pdes=($xdes / $ydes) if($pimg -lt $pdes){ #縦に合わせる $xnew=($ximg * $ydes) / $yimg $ynew=$ydes }else{ #横に合わせる $xnew=$xdes $ynew=($yimg * $xdes) / $ximg } $dstImg = New-Object System.Drawing.Bitmap($srcImg, $xnew, $ynew) $g = [System.Drawing.Graphics]::FromImage($dstImg) $g.InterpolationMode = [System.Drawing.Drawing2D.InterpolationMode]::Default $g.DrawImage($srcImg, 0, 0, $xnew, $ynew) $dstImg.Save($file2, [System.Drawing.Imaging.ImageFormat]::Bmp) $dstImg.Dispose() }else{ #画面サイズ取得エラー $srcImg.Save($file2, [System.Drawing.Imaging.ImageFormat]::Bmp) } $srcImg.Dispose() "--壁紙へ設定中" Set-ItemProperty -path "HKCU:Control Panel\Desktop" -name TileWallpaper -value 0 Set-ItemProperty -path "HKCU:Control Panel\Desktop" -name WallpaperStyle -value 0 $signature=@' [DllImport("user32.dll")] public static extern uint SystemParametersInfo(uint uiAction, uint uiParam, string pvParam, uint fWinIni); '@ $type = Add-Type -MemberDefinition $signature -Name Win32Utils -Namespace SystemParametersInfo -PassThru # 20=SPI_SETDESKWALLPAPER $type::SystemParametersInfo(20, 0, $file2, 3) | out-null "--終了" #リサイズで時間がかかるようになったので表示遅延は無しに #sleep -s 3 rm $file2 exit 0