Last active
March 9, 2017 03:30
-
-
Save BoltsJ/cbe8e166d8ba18b0f60e45037c888bdb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
=item Copyright | |
Copyright 2016 Joseph R. Nosie | |
This program is free software: you can redistribute it and/or modify | |
it under the terms of the GNU General Public License as published by | |
the Free Software Foundation, either version 3 of the License, or | |
(at your option) any later version. | |
This program is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
You should have received a copy of the GNU General Public License | |
along with this program. If not, see <http://www.gnu.org/licenses/>. | |
=cut | |
use strict; | |
use warnings; | |
use File::MMagic; | |
use List::MoreUtils qw/uniq/; | |
use LWP::Simple qw/get/; | |
my @urls; | |
my %files; | |
while(<>) { | |
next unless /URL/; | |
/".*URL":\s*"(.*)",$/; | |
next if $1 =~ /^$/; | |
push(@urls, $1); | |
} | |
for (uniq(@urls)) { | |
my $a = $_; | |
s#[.:=?%&/-]##g; | |
$files{$a} = $_; | |
} | |
my $ft = new File::MMagic; | |
mkdir "Images"; | |
mkdir "Models"; | |
while (my ($k, $v) = each(%files)) { | |
print "Fetching \"" . $k . "\"...\n"; | |
my $f = get($k); | |
my $t = $ft->checktype_contents($f); | |
my $fh; | |
if ($t =~ /^image\/png$/) { | |
open(my $fh, ">Images/$v.png"); | |
print $fh $f; | |
close($fh); | |
} elsif ($t =~ /^image\/jpeg$/) { | |
open(my $fh, ">Images/$v.jpg"); | |
print $fh $f; | |
close($fh); | |
} elsif ($t =~ /^text\/plain$/) { | |
open(my $fh, ">Models/$v.obj"); | |
print $fh $f; | |
close($fh); | |
} else { | |
print "Unknown type or empty file.\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Getting errors on OS 10.12.3, perl v5.16.0, latest XCode.
Fetching "https://lithi.io/FragaholiC/Secret.Hitler/bags/6players.ballot.box.jpg"...
Unknown type or empty file.
Looks like it's trying to compare file type "application/octet-stream" even for files that are jpg.
EDIT: Ah, I found it. OS X 10.11+ breaks SSL... I'm looking up solutions.
Basically have to use "brew" to install openssl, then add IO::Socket::SSL; and then run the script from the terminal using "perl script", otherwise it uses /usr/bin/perl rather than the updated version.