line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#! perl |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Data::iRealPro::Output::JSON -- parse iRealPro data and produce JSON |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# Author : Johan Vromans |
6
|
|
|
|
|
|
|
# Created On : Fri Jan 15 19:15:00 2016 |
7
|
|
|
|
|
|
|
# Last Modified By: Johan Vromans |
8
|
|
|
|
|
|
|
# Last Modified On: Thu Nov 1 21:09:11 2018 |
9
|
|
|
|
|
|
|
# Update Count : 1102 |
10
|
|
|
|
|
|
|
# Status : Unknown, Use with caution! |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
################ Common stuff ################ |
13
|
|
|
|
|
|
|
|
14
|
2
|
|
|
2
|
|
1937
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
68
|
|
15
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
48
|
|
16
|
2
|
|
|
2
|
|
9
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
93
|
|
17
|
2
|
|
|
2
|
|
567
|
use utf8; |
|
2
|
|
|
|
|
16
|
|
|
2
|
|
|
|
|
12
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
package Data::iRealPro::Output::JSON; |
20
|
|
|
|
|
|
|
|
21
|
2
|
|
|
2
|
|
81
|
use parent qw( Data::iRealPro::Output::Base ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
10
|
|
22
|
|
|
|
|
|
|
|
23
|
2
|
|
|
2
|
|
1496
|
use JSON::PP; |
|
2
|
|
|
|
|
31582
|
|
|
2
|
|
|
|
|
983
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub process { |
26
|
1
|
|
|
1
|
0
|
944
|
my ( $self, $u, $options ) = @_; |
27
|
|
|
|
|
|
|
|
28
|
1
|
|
50
|
|
|
10
|
$self->{output} ||= $options->{output} || "__new__.json"; |
|
|
|
33
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
|
|
7
|
my $json = JSON::PP->new->utf8(1)->pretty->indent->canonical; |
31
|
1
|
|
|
|
|
182
|
$json->allow_blessed->convert_blessed; |
32
|
|
|
|
|
|
|
*UNIVERSAL::TO_JSON = sub { |
33
|
3
|
|
|
3
|
|
271
|
my $obj = "".$_[0]; |
34
|
|
|
|
|
|
|
return $obj =~ /=HASH\(/ |
35
|
3
|
|
|
|
|
17
|
? { %{$_[0]} } |
36
|
|
|
|
|
|
|
: $obj =~ /=ARRAY\(/ |
37
|
3
|
0
|
|
|
|
13
|
? [ @{$_[0]} ] |
|
0
|
50
|
|
|
|
0
|
|
38
|
|
|
|
|
|
|
: undef |
39
|
|
|
|
|
|
|
; |
40
|
1
|
|
|
|
|
36
|
}; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# Process the song(s). |
43
|
1
|
|
|
|
|
7
|
my @goners = qw( variant debug a2 data raw_tokens cells |
44
|
|
|
|
|
|
|
transpose _transpose dataxp ); |
45
|
1
|
|
|
|
|
5
|
for my $item ( $u, $u->{playlist} ) { |
46
|
2
|
|
|
|
|
12
|
delete( $item->{$_} ) for @goners; |
47
|
|
|
|
|
|
|
} |
48
|
1
|
|
|
|
|
2
|
my $songix; |
49
|
1
|
|
|
|
|
2
|
foreach my $song ( @{ $u->{playlist}->{songs} } ) { |
|
1
|
|
|
|
|
4
|
|
50
|
1
|
|
|
|
|
2
|
$songix++; |
51
|
|
|
|
|
|
|
warn( sprintf("Song %3d: %s\n", $songix, $song->{title}) ) |
52
|
1
|
50
|
|
|
|
4
|
if $self->{verbose}; |
53
|
1
|
|
|
|
|
2
|
{ local $song->{_transpose} = 0; |
|
1
|
|
|
|
|
3
|
|
54
|
1
|
|
|
|
|
8
|
$song->tokens; } |
55
|
1
|
|
|
|
|
9
|
delete( $song->{$_} ) for @goners; |
56
|
|
|
|
|
|
|
} |
57
|
1
|
50
|
|
|
|
6
|
if ( ref( $self->{output} ) ) { |
|
|
0
|
|
|
|
|
|
58
|
1
|
|
|
|
|
6
|
${ $self->{output} } = $json->encode($u); |
|
1
|
|
|
|
|
3622
|
|
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
elsif ( $self->{output} eq "-" ) { |
61
|
0
|
|
|
|
|
|
binmode( STDOUT, ':utf8' ); |
62
|
0
|
|
|
|
|
|
print( $json->encode($u) ); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
else { |
65
|
|
|
|
|
|
|
open( my $fd, ">:utf8", $self->{output} ) |
66
|
0
|
0
|
|
|
|
|
or die( "Cannot create ", $self->{output}, " [$!]\n" ); |
67
|
0
|
|
|
|
|
|
$fd->print( $json->encode($u) ); |
68
|
0
|
|
|
|
|
|
$fd->close; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |