line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Store::File::MediaHaven; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
177968
|
use Catmandu::Sane; |
|
3
|
|
|
|
|
395879
|
|
|
3
|
|
|
|
|
17
|
|
6
|
3
|
|
|
3
|
|
782
|
use Moo; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
13
|
|
7
|
3
|
|
|
3
|
|
884
|
use Carp; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
211
|
|
8
|
3
|
|
|
3
|
|
1058
|
use Catmandu; |
|
3
|
|
|
|
|
278886
|
|
|
3
|
|
|
|
|
17
|
|
9
|
3
|
|
|
3
|
|
1973
|
use Catmandu::Store::File::MediaHaven::Index; |
|
3
|
|
|
|
|
13
|
|
|
3
|
|
|
|
|
117
|
|
10
|
3
|
|
|
3
|
|
1066
|
use Catmandu::Store::File::MediaHaven::Bag; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
110
|
|
11
|
3
|
|
|
3
|
|
947
|
use Catmandu::MediaHaven; |
|
3
|
|
|
|
|
12
|
|
|
3
|
|
|
|
|
116
|
|
12
|
3
|
|
|
3
|
|
27
|
use namespace::clean; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
27
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
with 'Catmandu::FileStore'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
has 'url' => (is => 'ro' , required => 1); |
17
|
|
|
|
|
|
|
has 'username' => (is => 'ro' , required => 1); |
18
|
|
|
|
|
|
|
has 'password' => (is => 'ro' , required => 1); |
19
|
|
|
|
|
|
|
has 'record_query' => (is => 'ro' , default => sub { "q=%%2B(MediaObjectFragmentId:%s)"; }); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has id_fixer => (is => 'ro' , init_arg => 'record_id_fix', coerce => sub {Catmandu->fixer($_[0])},); |
22
|
|
|
|
|
|
|
has 'mh' => (is => 'lazy'); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _build_mh { |
25
|
0
|
|
|
0
|
|
|
my $self = shift; |
26
|
0
|
|
|
|
|
|
return Catmandu::MediaHaven->new( |
27
|
|
|
|
|
|
|
url => $self->url, |
28
|
|
|
|
|
|
|
username => $self->username, |
29
|
|
|
|
|
|
|
password => $self->password, |
30
|
|
|
|
|
|
|
record_query => $self->record_query, |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
1; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
__END__ |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=pod |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 NAME |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
Catmandu::Store::File::MediaHaven - A Catmandu::FileStore to access files in the Zeticon MediaHaven server |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 SYNOPSIS |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# From the command line |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
$ cat catmandu.yml |
49
|
|
|
|
|
|
|
--- |
50
|
|
|
|
|
|
|
store: |
51
|
|
|
|
|
|
|
mh: |
52
|
|
|
|
|
|
|
package: MediaHaven |
53
|
|
|
|
|
|
|
options: |
54
|
|
|
|
|
|
|
url: https://archief.viaa.be/mediahaven-rest-api/resources/media |
55
|
|
|
|
|
|
|
username: ... |
56
|
|
|
|
|
|
|
password: ... |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# Export a list of all file containers |
59
|
|
|
|
|
|
|
$ catmandu export mh to YAML |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# Export a list of all file containers based on a query |
62
|
|
|
|
|
|
|
$ catmandu export mh --query "+(MediaObjectFragmentTitle:data)" |
63
|
|
|
|
|
|
|
$ catmandu export mh --query "+(MediaObjectFragmentTitle:data)" --sort "+=MediaObjectFragmentTitle" |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
$ Count all file containers |
66
|
|
|
|
|
|
|
$ catmandu count mh |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# Export a list of all files in container '1234' |
69
|
|
|
|
|
|
|
$ catmandu export mh --bag 1234 to YAML |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# Download the file 'myfile.txt' from the container '1234' |
72
|
|
|
|
|
|
|
$ catmandu stream mh --bag 1234 --id myfile.txt to /tmp/output.txt |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# From Perl |
76
|
|
|
|
|
|
|
use Catmandu; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
my $store = Catmandu->store('File::MediaHaven' , |
79
|
|
|
|
|
|
|
url => '...' , |
80
|
|
|
|
|
|
|
username => '...' , |
81
|
|
|
|
|
|
|
password => '...' , |
82
|
|
|
|
|
|
|
); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
my $index = $store->index; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# List all folder |
87
|
|
|
|
|
|
|
$index->bag->each(sub { |
88
|
|
|
|
|
|
|
my $container = shift; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
print "%s\n" , $container->{_id}; |
91
|
|
|
|
|
|
|
}); |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# Get the folder |
94
|
|
|
|
|
|
|
my $files = $index->files('1234'); |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# Retrieve a file |
97
|
|
|
|
|
|
|
my $file = $files->get('foobar.txt'); |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# Stream the contents of a file |
100
|
|
|
|
|
|
|
$files->stream(IO::File->new('>foobar.txt'), $file); |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 METHODS |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head2 new(%connection_parameters) |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Create a new Catmandu::Store::File::MediaHaven with the following connection |
107
|
|
|
|
|
|
|
parameters: |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=over |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=item url |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Required. The URL to the MediaHaven REST endpoint. |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=item username |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Required. Username used to connect to MediaHaven. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=item password |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Required. Password used to connect to MediaHaven. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=item record_query |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Optional. MediaHaven query to extract a given identifier from the database. |
126
|
|
|
|
|
|
|
Default: "q=%%2B(MediaObjectFragmentId:%s)" |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item record_id_fix |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Optional. One or more L<Catmandu::Fix> commands or a Fix script used to |
131
|
|
|
|
|
|
|
extract the C<_id> bag identifier from the MediaHaven record. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=back |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 INHERITED METHODS |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
This Catmandu::FileStore implements: |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=over 3 |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=item L<Catmandu::FileStore> |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=back |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
The index Catmandu::Bag in this Catmandu::Store implements: |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=over 3 |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item L<Catmandu::Bag> |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=item L<Catmandu::Searchable> |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=item L<Catmandu::FileBag::Index> |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=back |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
The file Catmandu::Bag in this Catmandu::Store implements: |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=over 3 |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=item L<Catmandu::Bag> |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=item L<Catmandu::FileBag> |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=back |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 SEE ALSO |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
L<Catmandu::Store::File::MediaHaven::Index>, |
171
|
|
|
|
|
|
|
L<Catmandu::Store::File::MediaHaven::Bag>, |
172
|
|
|
|
|
|
|
L<Catmandu::FileStore> |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=cut |