-
Notifications
You must be signed in to change notification settings - Fork 15
/
fetchVoiceWork
executable file
·110 lines (93 loc) · 2.79 KB
/
fetchVoiceWork
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#! /usr/bin/perl
use 5.014;
use autodie;
#use LWP::Simple;
use Web::Query;
use JSON;
use utf8;
use Encode;
use DBI;
use Data::Dumper;
use Getopt::Std;
use DJVoiceConfig;
$Getopt::Std::STANDARD_HELP_VERSION = 1;
our $VERSION = 0.1;
my %opts;
getopts('df', \%opts);
use open ":encoding(utf8)";
binmode(STDIN, ':encoding(utf8)');
binmode(STDOUT, ':encoding(utf8)');
binmode(STDERR, ':encoding(utf8)');
my $dir = $DJVoiceConfig::POP_STORAGE_PATH;
my $database = $DJVoiceConfig::POP_DATABASE_PATH;
my $token = $DJVoiceConfig::WUNDERLIST_TOKEN;
my $client_id = $DJVoiceConfig::WUNDERLIST_CLIENT_ID;
my $server_url = $DJVoiceConfig::WUNDERLIST_API_URL;
my $my_uid = $DJVoiceConfig::WUNDERLIST_RECEIVER_UID;
my $ren_uid = $DJVoiceConfig::WUNDERLIST_SENDER_UID;
my @list_id_array = (
$DJVoiceConfig::NEW_VOICEWORK_LIST_ID, # downloaded voiceWork list
$DJVoiceConfig::RECOMMEND_LIST_ID # オススメ作品
);
my $command;
my $respond;
my @data_array;
my @id_array;
if( $#ARGV == -1){
foreach(@list_id_array){
my $list_id = $_;
$command = "curl -s -H \"X-Access-Token: $token\" -H \"X-Client-ID: $client_id\"" .
" -X GET -H \"Content-Type:application/json\"" .
" $server_url/subtasks?list_id=$list_id";
$respond = `$command`;
my $data = decode_json( encode('UTF-8', $respond) );
@data_array = @$data;
foreach(@data_array){
my %data_hash = %$_;
if($data_hash{'completed'} == 1){
$data_hash{'title'} =~ /(RJ[0-9]{6})/;
@id_array = (@id_array, "'$1'");
}
}
}
}else{
foreach(@ARGV){
@id_array = (@id_array, "'$1'") if(/(RJ[0-9]{6})/);;
}
}
my $id_string;
my $query;
if(!defined $opts{'f'}){
$id_string = join (', ', @id_array);
$query = "SELECT id FROM voiceWork WHERE CAST(read AS int) > 0 " .
"AND CAST(read AS int) < 8 AND id IN ($id_string);";
#say $query;
chomp(my $download_list = `sqlite3 $database "$query"`);
@id_array = split( /\n/, $download_list);
}
#print Dumper(@id_array);
if($#id_array != -1){
foreach (@id_array) {
$_ = "-name '*$_*'";
}
my $id_string = join (' -o ', @id_array);
my $command = "find '$dir' -maxdepth 2 \\( $id_string \\) ";
if(defined $opts{'d'}){
say '-----';
print 'download .....';
$command .= "-exec cp -rf '{}' copy \\;";
say $command;
system($command);
$id_string =~ s/-name //g;
$id_string =~ s/\*//g;
$id_string =~ s/ -o/,/g;
say 'done';
}else{
say '-----';
$command .= '-print0 | xargs -0 du -sch | sed "s/\/.*\///g"';
say $command;
system($command);
}
}else{
say 'There is no checked new voiceWork';
}