#!/usr/bin/perl
#

$date_cmd2 =`/bin/date '+%d/%m/%Y'`;
$date2 = $date_cmd2;

$prog = substr ($0, rindex ($0, '/') + 1);
if ($#ARGV < 0) {             # imprimo usage si lo paso sin args
 print "usage: $prog nomarch(s)\n";
 print "  use: Saca los ^M de nomarch(s)\n";
 exit;
 }

foreach $nomarch (@ARGV) {
 if (! -e "$nomarch") {print "ERROR: no existe $nomarch inexistant\n";next;}
 open (FILEIN,"$nomarch") || die "ERROR: no puedo leer $nomarch: $!\n";

 $fileout = $nomarch;
 print $fileout if ($fileout =~ s/\?//);
 print $fileout if ($fileout =~ s/\&//);

 open (FILEOUT,">$fileout.html") || die "ERROR: no puedo crear $fileout.html: $!\n";

# Header fondos.com.ar 

 print FILEOUT "<html><!pre> \n";
 print FILEOUT "<!--#include file=\"top.html\" --> \n";
 print FILEOUT "<!--#include file=\"header1-en.html\" --> \n";
 print FILEOUT "</center><!pre> \n";
print FILEOUT "<!link rel=stylesheet href=/nostr/style.css> \n";
 print FILEOUT "<!--#echo var=\"DOCUMENT_NAME\" --> \n";
 print FILEOUT "<p><a href=https://ba.net/news/archive>BA.net News Social Posts Archive Index (SEO)</a><p> \n";

 print FILEOUT "<p><a href=https://ba.net/nostr>Live News Posts</a><p> \n";

 print FILEOUT "<p><a href=https://ba.net/localai/vpn/cloud-gpus.html>AI Social Manager</a><p> \n";

 while (<FILEIN>) {

     $_ =~ s/\n/<br>/gi;

     $_ =~ s/https:\/\/x.com\/(.*)/<a href=\"https:\/\/nitter.net\/$1\" target=_blank>nitter.net\/$1<\/a> <br>X.com reader link no account required/gi;

$_ =~ s/(https?:\/\/\S+\.(?:jpg|jpeg|png|gif|webp))/<center><img src=\"$1\" width=90% height=auto><\/center>/gi;


$_ =~ s/https:\/\/tidal.com\/track\/(.*?)\//<center><iframe width=90% height=200 src=\"https:\/\/embed.tidal.com\/tracks\/$1><\/iframe><\/center>/gi;

$_ =~ s/https:\/\/www.youtube.com\/watch\?v=(.*?) /'<center><iframe width=100% max-width=550 height=350 src=\"https:\/\/www.youtube-nocookie.com\/embed\/$1\?rel=0\&color=white\" frameborder=0 allow=fullscreen><\/iframe><\/center> /gi;

$_ =~ s/https:\/\/www.youtube.com\/watch\?v=(.*?)\n/<center><iframe width=100% max-width=550 height=350 src=\"https:\/\/www.youtube-nocookie.com\/embed\/$1\?rel=0\&color=white\" frameborder=0 allow=fullscreen><\/iframe><\/center> /gi;

$_ =~ s/https:\/\/youtu.be\/([^\/\?]+)/<center><iframe width=100% max-width=550 height=350 src=\"https:\/\/www.youtube-nocookie.com\/embed\/$1\?rel=0\&color=white\" frameborder=0 allow=fullscreen><\/iframe><\/center> /gi;

$_ =~ s/(https?:\/\/\S+\.(?:mpeg4|mp4|mpg4|webm))/<center><video width=\"100%\" max-width=550 height=\"350\" controls playsinline><source src=\"$1\" type="video\/mp4"><\/video><\/center>/gi;




	 print FILEOUT $_;
     }


# footer noticiasdot.com

 print FILEOUT "<!--#include file=\"footer1-en.html\" --> \n";


 close (FILEIN);
 close (FILEOUT);

print "$nomarch\n";
# unlink ($nomarch) || die "ERROR: no puedo borrar archivo original $nomarch: $!\n";
# rename("$fileout.html",$nomarch) || die "ERROR: no puedo renombrar $fileout.html a $nomarch: $!\n";

}

