use zUtil;

sub gocomics
{
    my $html = shift;
    my $outname = shift;
    my ( @rValue ) = ();
    my ( $title, $url, $blurb );
    my $image = "";

    print "---------------------------- gocomics --------------------------\n";
    print "html: $html\n";

    # $html =~ s/&amp;/&/gixs;
    # $html =~ s/&gt;/>/gixs;
    # $html =~ s/&lt;/</gixs;
    # print "hmtl: $html\n";

    # while( $html =~ s/<picture class="item-comic-image">.*?<img.*?src="(.*?)".*?picture>//s )
    # {
    #     $image=$1;

    #     print "Found image: $image\n";

    #     push @rValue, {
    #         'description'  => $image,
    #     };
    # }

    if ( $image =~ /^$/ ) {
        if( $html =~ /<picture class=\"gc-card__image.*?\"><img class=\"lazyload.*?\".*?data-srcset=\"(https:\/\/assets.amuniversal.com\/\w*?) .*?\" \/><\/picture>/gsi) {
            $image=$1;

            push @rValue, {
                'description'  => $image,
            };
        }
    }
    if ( $image =~ /^$/ ) {
        if( $html =~ /<picture class=\"gc-card.*?\"><img class=\"lazyload.*?\".*?src=\"(http:\/\/assets.amuniversal.com\/\w*?)\" \/>/gsi) {
            $image=$1;

            push @rValue, {
                'description'  => $image,
            };
        }
    }

    $resultHash = $rValue[0];
    $fetch_img=$resultHash->{'description'};

    # only uncomment this if the link to the image doesn't work
    # print "running: wget \"$fetch_img\" -O /usr/local/zeddweb/zii/scratch/$outname";
    # system( "wget \"$fetch_img\" -O /usr/local/zeddweb/zii/scratch/$outname");
    # system( "chmod", "ugo+rw", "/usr/local/zeddweb/zii/scratch/$outname");

    return @rValue;
}

return 1;

