LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Blogs > linux-related notes
User Name
Password

Notices


Just annotations of little "how to's", so I know I can find how to do something I've already done when I need to do it again, in case I don't remember anymore, which is not unlikely. Hopefully they can be useful to others, but I can't guarantee that it will work, or that it won't even make things worse.
Rate this Entry

Bash conversion of Opera sessions to "netscape standard" bookmarks

Posted 06-11-2014 at 03:34 AM by the dsc

You run it on the session folder (.win files, usually on ~/.opera/sessions/), and it will generate a single html file with all the bookmarks (taken from the last visited URL for any given tab in that session, hence the file/variable "lasturl" -- the session files record some "history", but this isn't being exported/converted here), and coded "subfolders" for each session file, with the filenames as titles. Every time it runs it rewrites this generated html file.

It may be buggy but I don't know of any alternative yet, except the extremely slow manual method of opening each session and bookmarking all tabs. But even then, it seems that Chrome isn't able to import Opera's own html-exported bookmarks. It must follow the "netscape standard" (used by chrome html export/import).

Requires the program "recode", which perhaps would be more properly used by converting a temporary file rather than piped output. But then there would be mixed code and I don't know how to deal with that, so perhaps it's slower than it could be.

It can be somewhat CPU intensive, one may want to add some subsecond sleep somewhere, or leash it with nice or cpulimit.


Code:
#!/bin/bash
# This so-called "software" is COMPLETELY UNLICENSED and barely tested. Use at your own risk
# Seriously. You shouldn't go on executing stuff one posts on the internet without analyzing it carefully.

 
 cat > opera-exported-bookmarks.html<<-netscape-bookmark-header
 <!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>
    <DT><H3 ADD_DATE="0" LAST_MODIFIED="1402265568" PERSONAL_TOOLBAR_FOLDER="true">BOOKMARKS FROM OPERA</H3>
netscape-bookmark-header


for sessionfile in *.win ; do

sessionname="$(echo "$sessionfile" | sed 's|.win||')"

cat >> opera-exported-bookmarks.html<<-folderstart
<DT><H3 ADD_DATE="0" LAST_MODIFIED="0">$sessionname</H3>
    <DL><p>" 
folderstart



for hist in `grep  "history url]" "$sessionfile"` ; do 

if
[[ -n "$hist" ]] ; then current="$(echo $hist | sed 's|history.*||;s|^\[||')" 

url=$(grep -A 2 "\["$current"history url\]" "$sessionfile" | grep 0=http | sed 's|0=||'  | recode ascii..html ) 

title=$(grep -A 2 "\["$current"history title" "$sessionfile" | grep 0= | sed 's|0=||' | recode ascii..html ) 

if [[ -n "$url" ]] ; then

if [[ -z "$title" ]] ; then echo FAKETITLE ; title="$(echo $url |sed s'|^http://||;s|^www.||;s|\..*||')...$(echo $url | tail -c 20 )"
fi



cat >> opera-exported-bookmarks.html<<-lasturls
<DT><A HREF="$url" ADD_DATE="0">$title</A>
lasturls

fi







fi ; done 

echo '</DL><p>' >> opera-exported-bookmarks.html 

done

echo '</DL><p>' >> opera-exported-bookmarks.html
Posted in Uncategorized
Views 1405 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 07:46 AM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration