Skip to content

Instantly share code, notes, and snippets.

@xaicron
Created February 6, 2010 14:52
Show Gist options
  • Select an option

  • Save xaicron/296749 to your computer and use it in GitHub Desktop.

Select an option

Save xaicron/296749 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
use utf8;
use Win32;;
use Win32::GuiTest ':ALL';
use Win32::Clipboard;
use Win32::Unicode '-native';
use YAML 0.71 qw/LoadFile/;
use Data::Recursive::Encode;
use Time::HiRes qw/sleep/;
my $file = shift || die "Usage: $0 config.yaml";
my $data = Data::Recursive::Encode->encode(cp932 => LoadFile $file);
UnicodeSemantics 1;
my $clip = Win32::Clipboard();
$clip->Empty;
my ($win, @wins) = FindWindowLike 0 => '^Gracenote';
die 'Oops!' if @wins;
my $childs = [ GetChildWindows $win ];
SetForegroundWindow $win;
my $MessageBox = Win32::API->new('user32', 'MessageBoxA', 'NPPN', 'N');
&main();exit;
sub main {
set_data_lang();
set_title($data->{title});
set_artist($data->{artist});
$MessageBox->Call(0, Encode::encode(cp932 => 'ジャンルを選択して、このダイアログを閉じてください'), 'perl', 0x00000030 | 0x00040000);
SetForegroundWindow $win;
select_track_tab();
set_tracks($data->{tracks});
}
# Album Tab
{
sub set_data_lang {
my $lang_combo = get_next_component('^データ言語$');
SetFocus $lang_combo;
SelComboItem $lang_combo, 44; # 日本語
}
sub set_title {
my $title = shift;
my $title_edit = get_next_component('^アルバム情報$');
SetFocus $title_edit;
sleep 0.1;
SendKeys '{END}';
SendKeys '{BS}' for (0..8);
$clip->Set($title);
SendKeys '^v';
}
sub set_artist {
my $artist = shift;
my $artist_edit = get_next_component('^レコーディング アーティスト$');
SetFocus $artist_edit;
sleep 0.1;
$clip->Set($artist);
SendKeys '^v';
}
}
# Track Tab
{
sub select_track_tab {
my ($tab1) = FindWindowLike $win, '^Tab1$' or die 'Oops';
SetFocus $tab1;
sleep 0.1;
SendKeys '{RIGHT}';
}
sub set_tracks {
my $tracks = shift;
my ($track_list, $i) = get_next_component('^トラック 1/\d+$');
my $track_edit = $childs->[$i + 2];
for my $track (@$tracks) {
SetFocus $track_edit;
sleep 0.1;
SendKeys '{END}';
SendKeys '{BS}' for (0..9);
$clip->Set($track);
SendKeys '^v';
SendKeys '+{TAB}';
SendKeys '{DOWN}';
}
}
}
sub get_next_component {
my $reg = shift;
my $i = 0;
for (; $i < @$childs; $i++) {
last if GetWindowText($childs->[$i]) =~ /$reg/;
}
return $childs, $i + 1 if wantarray;
return $childs->[$i + 1];
}
sub dump_info {
my $component = shift;
for my $child (GetChildWindows $component) {
my $depth = GetChildDepth $component, $child;
my $class = GetClassName $child;
my $text = GetWindowText $child;
printf "%s%s(%s)\n", '--' x $depth, $class, $text;
}
}
---
title: ほげー
artist: ふがー
tracks:
- 俺の塩でバーニングぅ!!
- 赤いきつねとあの頃と
- スパ王 ~裸王への道~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment