hi!
Da ich bislang kein vernünftiges Programm gefunden habe, das meine
Opera-Hotlist in Mozilla-Bookmarks konvertiert, und Mozilla das
Format von Opera auch nicht lesen kann, habe ich gerade ein kleines
Perl-Skript geschrieben, das die Bookmark-Liste von Opera ausliest
und ein Bookmark-File erstellt, das problemlos von Mozilla importiert
werden kann. Dabei bleiben vor allem die Ordnerstruktur und die für
Bookmarks eingestellten Shortcuts erhalten. Das zweite Feature habe
ich oft bei anderer Software vermisst.
Naja, also falls jemand das Programm auch gebrauchen kann, poste ich
mal hier den Quellcode. Damit kann man übrigens auch seine Opera
Hotlist in eine HTML-Linkliste verwandeln, da das Mozilla-Format ja
auch dafür geeignet ist... ;)
=== cut ===
#!/usr/bin/perl
o2m.pl - Opera to Mozilla bookmark converter
Converts the Opera hotlist v2.0 to a Mozilla bookmark file.
This program should also take care of the bookmark/folder
hierarchy, shortcuts and descriptions. USE AT YOUR OWN RISK!
Example usage: o2m.pl Opera5.adr bookmarks.html
Don't replace your original bookmarks.html with the output file
of this program but create a new one and import this file into
your Mozilla bookmarks.
(c) Frank Schoenmann fs@tower.de, 2002-08-09
my ($input, $output) = @ARGV;
open FILE, "<$input" or die "Could not read file $input: $!";
my @lines = <FILE>;
close FILE;
open FILE, ">$output" or die "Could not write file $output: $!";
print FILE headerHTML();
print FILE parseOpera(@lines)->[0];
print FILE footerHTML();
close FILE;
Forward declarations
sub folderHTML($$$$);
sub bookmarkHTML($$$$$$);
sub strip($);
Parser
sub parseOpera(@) {
my @lines = @_;
my ($line, $output);
while ($line !~ /^-/) {
if ($line =~ /#URL/) {
my %bookmark;
while (($line = shift @lines) !~ /^$/m) {
my ($key, $value) = map { strip $_ } split /=/, $line;
$bookmark{$key} = $value;
}
$output .= bookmarkHTML $bookmark{'NAME'}, $bookmark{'URL'},
$bookmark{'CREATED'}, $bookmark{'VISITED'},
$bookmark{'SHORT NAME'}, $bookmark{'DESCRIPTION'};
} elsif ($line =~ /#FOLDER/) {
my %folder;
while (($line = shift @lines) !~ /^$/m) {
my ($key, $value) = map { strip $_ } split /=/, $line;
$folder{$key} = $value;
}
my $content = parseOpera(@lines);
$output .= folderHTML $folder{'NAME'}, $folder{'CREATED'},
$folder{'VISITED'}, $content->[0];
@lines = @{@$content->[1]};
}
$line = shift @lines;
}
return [$output, @lines];
}
HTML creation routines
sub folderHTML($$$$) {
my ($name, $created, $visited, $content) = @_;
return <<"EOT";
<DT><H3 ADD_DATE="$created" LAST_MODIFIED="$created" ID="NC:BookmarksRoot#$f519bc5c">$name</H3>
<DL><p>
$content
</DL><p>
EOT
}
sub bookmarkHTML($$$$$$) {
my ($name, $url, $created, $visited, $shortcut, $description) = @_;
my $output = <<"EOT";
<DT><A HREF="$url" ADD_DATE="$created" LAST_VISIT="$visited" LAST_MODIFIED="$created" SHORTCUTURL="$shortcut" LAST_CHARSET="ISO-8859-1">$name</A>
EOT
if ($description) {
$output .= "<DD>$description";
}
return $output;
}
sub headerHTML() {
return <<"EOT";
<!DOCTYPE NETSCAPE-Bookmark-file-1>
<!-- This is an automatically generated file.
It will be read and overwritten.
Do Not Edit! -->
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<TITLE>Bookmarks</TITLE>
<H1>Bookmarks</H1>
<DL><p>
EOT
}
sub footerHTML() {
return <<"EOT";
</DL><p>
EOT
}
Strip whitespaces
sub strip($) {
my $line = shift;
$line =~ s/^\s*(.*?)\s*$/$1/;
return $line;
}
=== cut ===
Vielleicht hat ja jemand Verbesserungsvorschläge oder findet noch
einen Bug...
bye, Frank!