Skip to content

Instantly share code, notes, and snippets.

@BoltsJ
Last active March 9, 2017 03:30
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save BoltsJ/cbe8e166d8ba18b0f60e45037c888bdb to your computer and use it in GitHub Desktop.
Save BoltsJ/cbe8e166d8ba18b0f60e45037c888bdb to your computer and use it in GitHub Desktop.
#!/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";
}
}
@BoltsJ
Copy link
Author

BoltsJ commented Jul 2, 2016

To use, make the script executable and run it from the terminal.

chmod +x TTS-dl.pl
./TTS-dl.pl <path to mod or save json>

This will create two folders Images and Models that contain the downloaded assets which you can copy into your mods folder.

@BoltsJ
Copy link
Author

BoltsJ commented Jul 11, 2016

Resource for Perl on OSX: http://learn.perl.org/installing/osx.html

@Jabrwock
Copy link

Jabrwock commented Mar 9, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment