Changeset 15731
- Timestamp:
- Jun 15, 2012, 3:52:59 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/piwigo_import_tree/piwigo_import_tree.pl
r15730 r15731 58 58 59 59 # Login to Piwigo 60 my $form = { 61 method => 'pwg.session.login', 62 username => $conf{username}, 63 password => $conf{password}, 64 }; 65 66 $result = $ua->post( 67 $conf{base_url}.'/ws.php?format=json', 68 $form 69 ); 60 piwigo_login(); 70 61 71 62 # Fill an "album path to album id" cache … … 75 66 $conf{base_url}.'/ws.php?format=json', 76 67 { 77 78 79 80 68 method => 'pwg.categories.getList', 69 recursive => 1, 70 fullname => 1, 71 } 81 72 ); 82 73 83 74 my $albums_aref = from_json($response->content)->{result}->{categories}; 84 75 foreach my $album_href (@{$albums_aref}) { 85 76 $piwigo_albums{ $album_href->{name} } = $album_href->{id}; 86 77 } 87 78 # print Dumper(\%piwigo_albums)."\n\n"; 88 79 89 80 if (defined $opt{parent_album_id}) { 90 foreach my $album_path (keys %piwigo_albums) { 91 if ($piwigo_albums{$album_path} == $opt{parent_album_id}) { 92 $conf{parent_album_id} = $opt{parent_album_id}; 93 $conf{parent_album_path} = $album_path; 94 } 95 } 96 if (not defined $conf{parent_album_path}) { 97 print "Parent album ".$opt{parent_album_id}." does not exist\n"; 98 exit(); 99 } 81 foreach my $album_path (keys %piwigo_albums) { 82 if ($piwigo_albums{$album_path} == $opt{parent_album_id}) { 83 $conf{parent_album_id} = $opt{parent_album_id}; 84 $conf{parent_album_path} = $album_path; 85 } 86 } 87 88 if (not defined $conf{parent_album_path}) { 89 print "Parent album ".$opt{parent_album_id}." does not exist\n"; 90 exit(); 91 } 100 92 } 101 93 … … 110 102 #--------------------------------------------------------------------- 111 103 104 sub piwigo_login { 105 $ua->post( 106 $conf{base_url}.'/ws.php?format=json', 107 { 108 method => 'pwg.session.login', 109 username => $conf{username}, 110 password => $conf{password}, 111 } 112 ); 113 } 114 112 115 sub fill_photos_of_album { 113 my %params = @_; 114 115 if (defined $photos_of_album{ $params{album_id} }) { 116 return 1; 117 } 118 119 my $response = $ua->post( 116 my %params = @_; 117 118 if (defined $photos_of_album{ $params{album_id} }) { 119 return 1; 120 } 121 122 piwigo_login(); 123 my $response = $ua->post( 120 124 $conf{base_url}.'/ws.php?format=json', 121 125 { … … 124 128 } 125 129 ); 126 130 127 131 foreach my $image_href (@{from_json($response->content)->{result}{images}{_content}}) { 128 132 $photos_of_album{ $params{album_id} }{ $image_href->{file} } = 1; … … 131 135 132 136 sub photo_exists { 133 137 my %params = @_; 134 138 135 139 fill_photos_of_album(album_id => $params{album_id}); 136 140 137 141 if (defined $photos_of_album{ $params{album_id} }{ $params{file} }) { 138 142 return 1; … … 144 148 145 149 sub add_album { 146 my %params = @_; 147 148 # print Dumper(\%params); 149 150 my %params = @_; 151 150 152 my $form = { 151 153 method => 'pwg.categories.add', 152 154 name => $params{name}, 153 155 }; 154 156 155 157 if (defined $params{parent}) { 156 158 $form->{parent} = $params{parent}; 157 159 } 158 160 161 piwigo_login(); 159 162 my $response = $ua->post( 160 163 $conf{base_url}.'/ws.php?format=json', … … 193 196 } 194 197 198 piwigo_login(); 195 199 my $response = $ua->post( 196 200 $conf{base_url}.'/ws.php?format=json',
Note: See TracChangeset
for help on using the changeset viewer.