1. #1
    Avatar von Ta1lor
    Registriert seit
    15.11.2011
    Beiträge
    767
    Thanked 832 Times in 435 Posts

    Standard [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";

    hf & gl
    Geändert von Ta1lor (09.07.2013 um 19:42 Uhr)

  2. The Following 2 Users Say Thank You to Ta1lor For This Useful Post:

    Mentos (22.09.2012), Roxithro (22.09.2012)

Ähnliche Themen

  1. [PERL] Vbulletin login
    Von Ta1lor im Forum Andere
    Antworten: 0
    Letzter Beitrag: 22.09.2012, 12:58
  2. VB.Net Textbox Image
    Von rVs14 im Forum .Net
    Antworten: 3
    Letzter Beitrag: 18.06.2012, 15:38
  3. [S] Pokemon Diamant/Perl-Rom
    Von Strike im Forum Sonstige Games
    Antworten: 4
    Letzter Beitrag: 28.05.2012, 13:13
  4. Win7 Image erstellen
    Von DANP im Forum Windows
    Antworten: 4
    Letzter Beitrag: 12.05.2012, 18:44
  5. Perl to Php
    Von uncopyable im Forum Andere
    Antworten: 1
    Letzter 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.