#!/usr/bin/env python # -*- coding: iso-8859-1 -*- # Dinko Korunic 'kreator', 2007. # extract_ed2k.py # script to extract ed2k links from any given material """This script can be used to extract valid ed2k links from any given material. """ __copyright__ = """Copyright (C) 2007 Dinko Korunic, InfoMAR d.o.o. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ __version__ = '0.2' import sys import re def getlinks(iterable = None): """Return one or more ed2k:// links, separated with newlines""" # sanity check if iterable is None: return # ed2k regex (looking pretty much as line noise) ed2k_re_str = r'(ed2k://\|(file|server)\|[^|]+\|[0-9]+\|[^|]+\|(|sources,[^|]+\|)?(|h=[^|]+\|)?/)' ed2k_re = re.compile(ed2k_re_str) for line in iterable: result = ed2k_re.findall(line) if not result: continue for i in result: print "dllink", i[0] if __name__ == '__main__': sys.exit(getlinks(sys.stdin))