Guest User

Untitled

a guest
Mar 6th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. package Plagger::Plugin::Filter::Cws2Fws;
  2.  
  3. require 5.6.0;
  4.  
  5. use strict;
  6. use base qw( Plagger::Plugin );
  7. use Compress::Zlib;
  8.  
  9. sub register {
  10. my($self, $context) = @_;
  11. $context->register_hook(
  12. $self,
  13. 'update.entry.fixup' => \&filter,
  14. );
  15. }
  16.  
  17. sub filter {
  18. my($self, $context, $args) = @_;
  19.  
  20. my $entry = $args->{entry};
  21.  
  22. my $enclosure = $entry->enclosure;
  23. if (!defined $enclosure) {
  24. $context->log( error => q{Can't find an enclosure.} );
  25. return;
  26. }
  27.  
  28. eval { $enclosure->local_path };
  29. if ($@) {
  30. $context->log( error => q{Can't get local file.} );
  31. return;
  32. }
  33.  
  34. # detect CWS
  35. my $local_path = $enclosure->local_path;
  36. if ((-s $local_path) < 8) {
  37. return;
  38. }
  39. open(my $fh, $local_path) or return;
  40. my $header;
  41. read $fh, $header, 8;
  42. if ($header !~ /^CWS/) {
  43. close $fh;
  44. return;
  45. }
  46.  
  47. # fix position
  48. if (length($header) > 8) {
  49. $header = substr($header, 0, 8);
  50. seek($fh, 8, 0);
  51. }
  52.  
  53. # read body.
  54. local $/; # enable localized slurp mode
  55. my $buffer = <$fh>;
  56. close $fh;
  57.  
  58. # output file.
  59. open(my $out, '> ' . $local_path) or return; # overwrite!
  60. $header =~ s/^C/F/;
  61. $buffer = uncompress($buffer);
  62. print $out $header;
  63. print $out $buffer;
  64. close $out;
  65.  
  66. $context->log( info => 'Complete Cws2Fws.' );
  67. }
  68.  
  69. 1;
  70. __END__
  71.  
  72. =head1 NAME
  73.  
  74. Plagger::Plugin::Filter::Cws2Fws - convert swf file from CWS to FWS.
  75.  
  76. =head1 SYNOPSIS
  77.  
  78. - module: Filter::Cws2Fws
  79.  
  80. =head1 DESCRIPTION
  81.  
  82. convert swf file from CWS to FWS.
  83.  
  84. =head1 CONFIG
  85.  
  86. - module: Filter::Cws2Fws
  87.  
  88. =head1 AUTHOR
  89.  
  90. miya2000
  91.  
  92. =head1 SEE ALSO
  93.  
  94. L<Plagger>
  95.  
  96. =cut
Add Comment
Please, Sign In to add comment