Advertisement
Guest User

hitomi-get-new2.pl - handle new picture names Jan 2020

a guest
Jan 11th, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.95 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. $url=shift;
  4. unless ($url =~ m!https://hitomi.la/\w+/.*-(\d+)\.html$!) { die "ungültige URL"; }
  5. $gallid=$1;
  6. warn "trying to retrieve hitomi gallery $gallid\n";
  7.  
  8. $subdom = shift;
  9.  
  10. open(F,"wget -4nv -O - '$url'|");
  11. while (<F>) {
  12.   if (m!<h1><a[^>]+>(.*)<\/a>!) {
  13.     $title = $1;
  14.   }
  15.   elsif (m!href="/artist/[^>]+>(.*)</a>!) {
  16.    push(@artist,$1);
  17.  }
  18.  elsif (m!href="/group/[^>]+>(.*)</a>!) {
  19.     push(@group,$1);
  20.   }
  21.   elsif (m!href="/series/[^>]+>(.*)</a>!) {
  22.    push(@series,$1) unless $1 eq 'original';
  23.  }
  24.  elsif (m!<td>Language</td><td><a href="/index-(\w+)-1.html!) {
  25.     $lang=$1;
  26.   }
  27.   elsif (m!href="/tag/[^>]+>(.*)</a>!) {
  28.    $tag=$1; $tag =~ s/ ♂/_M/; $tag =~ s/ ♀/_F/; $tag =~ s/ /_/g;
  29.    push(@tag,$tag);
  30.  }
  31. }
  32. close(F);
  33. open(F,"wget -4nv -O - https://ltn.hitomi.la/galleries/$gallid.js|");
  34. while (<F>) {
  35.  while (s!,"hash":"(\w{61}(\w\w)(\w))","haswebp":\d,"name":"([^"]+\.(\w+))"!!) {
  36.    # push(@imgurl,"/galleries/$gallid/$1");
  37.     push(@imgurl,"/images/$3/$2/$1.$5");
  38.     $rename{"$1.$5"}=$4;
  39.   }
  40. }
  41. close(F);
  42. unless ($title) { die "no title extracted, wrong URL?"; }
  43. $name=$title;
  44. if (@artist) { $name .= '_'.join(",",@artist); }
  45. if (@group) { $name .= '('.join(",",@group).')'; }
  46. $name =~ s!&#39;!'!g;
  47. $name =~ s!&quot;!"!g;
  48. $name =~ s!&amp;!&!g;
  49. $name =~ s!/!#!g;
  50. if (length($name)>200) {
  51.  warn "shortening overlong name $name\n";
  52.  $name = substr($name,0,200);
  53. }
  54. $name .= '.'.$gallid;
  55. if ( -e $name ) {
  56.     die "$name exists - duplicate download request";
  57. }
  58. warn "mkdir ".$name."\n";
  59. mkdir ($name) && chdir ($name) || die "couldn't mkdir,chdir $name";
  60. warn "tags are ".join(",",@tag)."\n";
  61. warn "will fetch ".scalar(@imgurl)." images.\n";
  62. if ($lang) { warn "language is $lang\n"; }
  63. unless ($subdom) {
  64.  $first = shift @imgurl;
  65.  $subdom = 'ca';
  66.  warn "trying subdom $subdom\n";
  67.  system "wget -4nv --referer=https://hitomi.la/reader/$gallid.html --no-use-server-timestamps https://$subdom.hitomi.la$first";
  68.  if ($?) {
  69.  $subdom = 'aa';
  70.  warn "trying subdom $subdom\n";
  71.  system "wget -4nv --referer=https://hitomi.la/reader/$gallid.html --no-use-server-timestamps https://$subdom.hitomi.la$first";
  72.  if ($?) {
  73.  $subdom = 'ba';
  74.  warn "trying subdom $subdom\n";
  75.  system "wget -4nv --referer=https://hitomi.la/reader/$gallid.html --no-use-server-timestamps https://$subdom.hitomi.la$first";
  76.  if ($?) {
  77.    chdir (".."); rmdir ($name);
  78.    die "unknown subdom";
  79.  }
  80.  }
  81.  }
  82. }
  83. warn "using subdom $subdom\n";
  84. system "wget -4nv --referer=https://hitomi.la/reader/$gallid.html --no-use-server-timestamps ".join(" ",map { "https://$subdom.hitomi.la".$_ } @imgurl);
  85.  foreach $f (keys(%rename)) {
  86.    rename($f,$rename{$f});
  87.  }
  88. if ($lang) { open(F,">00LANG_$lang"); close(F); }
  89. if (@series) { open(F,">00SERIES_".join(",",@series)); close(F); }
  90. while (scalar(@tag)>10) {
  91.  open(F,">00TAGS_".join(",",splice(@tag,0,10))); close(F);
  92. }
  93. open(F,">00TAGS_".join(",",@tag)); close(F);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement