Thema: [PERL] /b/ image downloader
-
22.09.2012, 01:24 #1
[PERL] 4chan image downloader
Sup faggots,
da mir c# auf den Sack geht und ich kein bock habe json in cpp zu parsen oder eine socket library zu schreiben habe ich das "Projekt" mal in perl umgesetzt.
Ihr braucht:
WWW::Mechanize
JSON
Dazu einfach:
# cpan
# install JSON
# install WWW::Mechanize
Gegebenenfalls noch JSON::XS wenn es bei JSON nicht schon dabei ist.
Aufruf:
./download.pl https://boards.4chan.org/b/res/424778925
Es können mehrere URLs angegeben werden, einfach mit einem Leerzeichen trennen. Dateien landen default in /root/pic (LEGT DEN ORDNER AN BEVOR IHR OHNE PLAN WAS MACHT), könnt ihr aber im Script ändern (Variable $folder).
EDIT: Geht jetzt mit jedem Board.
Source:
PHP-Code:#!/usr/bin/perl
use strict;
use WWW::Mechanize;
use JSON -support_by_pp;
my $url;
my $board;
foreach my $arg (@ARGV)
{
parseURL($arg);
downloadJSON($url);
}
sub downloadJSON
{
my $download = WWW::Mechanize->new(autocheck => 0);
$download->get($url);
if ($download->success())
{
my $source = $download->content();
my $json = new JSON;
my $jsonText = $json->allow_nonref->utf8->relaxed->escape_slash->loose->allow_singlequote->allow_barekey->decode($source);
foreach my $posts(@{$jsonText->{posts}})
{
my $pic = $posts->{tim} . $posts->{ext};
if ($pic != "")
{
downloadPicture( $posts->{tim} . $posts->{ext} );
}
}
} else
{
print "looks like the thread 404'd\n";
}
}
sub downloadPicture
{
my $folder = "/root/pic/";
my $download = WWW::Mechanize->new(autocheck => 0);
my $file = $folder . $_[0];
if ( -e $file)
{
print "file " . $file . " already exists\n";
} else
{
$download->get( "http://images.4chan.org/$board/src/" . $_[0] );
if ($download->success())
{
open (my $picture, ">$file") || die $!;
print $picture $download->content;
print "downloading " . $file . "\n";
close ($picture);
} else
{
print "failed";
}
}
}
sub parseURL
{
my $oldUrl = $_[0];
$url = $oldUrl;
$oldUrl =~ s/http(s):\/\/boards.4chan.org\///;
$oldUrl =~ s/\/res\/[0-9]{1,15}//;
$board = $oldUrl;
$url =~ s/http(s):\/\/boards.4chan.org\/$board\/res\//http:\/\/api.4chan.org\/$board\/res\//;
$url = $url . ".json";
}
Geändert von Ta1lor (09.07.2013 um 19:42 Uhr)
-
The Following 2 Users Say Thank You to Ta1lor For This Useful Post:
Ähnliche Themen
-
[PERL] Vbulletin login
Von Ta1lor im Forum AndereAntworten: 0Letzter Beitrag: 22.09.2012, 12:58 -
VB.Net Textbox Image
Von rVs14 im Forum .NetAntworten: 3Letzter Beitrag: 18.06.2012, 15:38 -
[S] Pokemon Diamant/Perl-Rom
Von Strike im Forum Sonstige GamesAntworten: 4Letzter Beitrag: 28.05.2012, 13:13 -
Win7 Image erstellen
Von DANP im Forum WindowsAntworten: 4Letzter Beitrag: 12.05.2012, 18:44 -
Perl to Php
Von uncopyable im Forum AndereAntworten: 1Letzter Beitrag: 20.12.2011, 23:05
Stichworte
Diese Seite nutzt Cookies, um das Nutzererlebnis zu verbessern. Klicken Sie hier, um das Cookie-Tracking zu deaktivieren.