| author | Fabien Ninoles <fabien@tzone.org> | 
| Sun, 22 Sep 2013 22:07:04 -0400 | |
| changeset 9 | e3a2bb2bae8d | 
| parent 8 | 98065a298da0 | 
| child 10 | d7e256c9aec9 | 
| permissions | -rwxr-xr-x | 
| 0 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 1 | #!/usr/bin/python3 | 
| 2 
3675dd7daf59
Take filename from command line arguments, add copyright and better readme text.
 Fabien Ninoles <fabien@tzone.org> parents: 
1diff
changeset | 2 | # | 
| 
3675dd7daf59
Take filename from command line arguments, add copyright and better readme text.
 Fabien Ninoles <fabien@tzone.org> parents: 
1diff
changeset | 3 | # Update HIB - Scrapper for the HumbleBundle library page. | 
| 
3675dd7daf59
Take filename from command line arguments, add copyright and better readme text.
 Fabien Ninoles <fabien@tzone.org> parents: 
1diff
changeset | 4 | # Copyright (C) 2012, Fabien Ninoles <- fabien - AT - tzone . org -> | 
| 
3675dd7daf59
Take filename from command line arguments, add copyright and better readme text.
 Fabien Ninoles <fabien@tzone.org> parents: 
1diff
changeset | 5 | # | 
| 
3675dd7daf59
Take filename from command line arguments, add copyright and better readme text.
 Fabien Ninoles <fabien@tzone.org> parents: 
1diff
changeset | 6 | # This program is free software: you can redistribute it and/or modify | 
| 
3675dd7daf59
Take filename from command line arguments, add copyright and better readme text.
 Fabien Ninoles <fabien@tzone.org> parents: 
1diff
changeset | 7 | # it under the terms of the GNU General Public License as published by | 
| 
3675dd7daf59
Take filename from command line arguments, add copyright and better readme text.
 Fabien Ninoles <fabien@tzone.org> parents: 
1diff
changeset | 8 | # the Free Software Foundation, either version 3 of the License, or | 
| 
3675dd7daf59
Take filename from command line arguments, add copyright and better readme text.
 Fabien Ninoles <fabien@tzone.org> parents: 
1diff
changeset | 9 | # (at your option) any later version. | 
| 8 
98065a298da0
Update to handle audio type as "standard" (always download).
 Fabien Ninoles <fabien@tzone.org> parents: 
7diff
changeset | 10 | # | 
| 2 
3675dd7daf59
Take filename from command line arguments, add copyright and better readme text.
 Fabien Ninoles <fabien@tzone.org> parents: 
1diff
changeset | 11 | # This program is distributed in the hope that it will be useful, | 
| 
3675dd7daf59
Take filename from command line arguments, add copyright and better readme text.
 Fabien Ninoles <fabien@tzone.org> parents: 
1diff
changeset | 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| 
3675dd7daf59
Take filename from command line arguments, add copyright and better readme text.
 Fabien Ninoles <fabien@tzone.org> parents: 
1diff
changeset | 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 
| 
3675dd7daf59
Take filename from command line arguments, add copyright and better readme text.
 Fabien Ninoles <fabien@tzone.org> parents: 
1diff
changeset | 14 | # GNU General Public License for more details. | 
| 
3675dd7daf59
Take filename from command line arguments, add copyright and better readme text.
 Fabien Ninoles <fabien@tzone.org> parents: 
1diff
changeset | 15 | # | 
| 
3675dd7daf59
Take filename from command line arguments, add copyright and better readme text.
 Fabien Ninoles <fabien@tzone.org> parents: 
1diff
changeset | 16 | # You should have received a copy of the GNU General Public License | 
| 
3675dd7daf59
Take filename from command line arguments, add copyright and better readme text.
 Fabien Ninoles <fabien@tzone.org> parents: 
1diff
changeset | 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | 
| 
3675dd7daf59
Take filename from command line arguments, add copyright and better readme text.
 Fabien Ninoles <fabien@tzone.org> parents: 
1diff
changeset | 18 | |
| 9 
e3a2bb2bae8d
Add bs4 support, removing the need for tidy up the page first.
 Fabien Ninoles <fabien@tzone.org> parents: 
8diff
changeset | 19 | import bs4 | 
| 0 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 20 | from pprint import pprint | 
| 4 
e102d2bb7a9e
Update to download multiple version.
 Fabien Ninoles <fabien@tzone.org> parents: 
2diff
changeset | 21 | from itertools import chain, groupby | 
| 
e102d2bb7a9e
Update to download multiple version.
 Fabien Ninoles <fabien@tzone.org> parents: 
2diff
changeset | 22 | import logging | 
| 
e102d2bb7a9e
Update to download multiple version.
 Fabien Ninoles <fabien@tzone.org> parents: 
2diff
changeset | 23 | import operator | 
| 0 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 24 | |
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 25 | class Download: | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 26 |     subst = { "arc32"         : ("x86",),
 | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 27 |               "arc64"         : ("x64",),
 | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 28 |               "i386.deb"      : ("x86","deb"),
 | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 29 |               "x86_64.deb"    : ("x64", "deb"),
 | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 30 |               "i686.rpm"      : ("x86", "rpm"),
 | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 31 |               ".i386.rpm"     : ("x86", "rpm"),
 | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 32 |               "x86_64.rpm"    : ("x64", "rpm"),
 | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 33 |               ".x86_64.rpm"   : ("x64", "rpm"),
 | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 34 |               "i386.tar.gz"   : ("x86", "tgz"),
 | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 35 |               "x86_64.tar.gz" : ("x64", "tgz"),
 | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 36 |               ".tar.gz"       : ("tgz",),
 | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 37 |               ".deb"          : ("deb",),
 | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 38 |               ".rpm"          : ("rpm",),
 | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 39 |               "32-bit"        : ("x86",),
 | 
| 5 | 40 |               "64-bit"        : ("x64",),
 | 
| 41 |               "(HD)"          : ("HD",),
 | |
| 6 
0c6d2ed2cd7c
Add download script production for http only links.
 Fabien Ninoles <fabien@tzone.org> parents: 
5diff
changeset | 42 |               "(MP3)"         : ("MP3",),
 | 
| 0 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 43 | } | 
| 9 
e3a2bb2bae8d
Add bs4 support, removing the need for tidy up the page first.
 Fabien Ninoles <fabien@tzone.org> parents: 
8diff
changeset | 44 | def __init__(self, dltype, soup): | 
| 0 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 45 | self.dltype = dltype | 
| 9 
e3a2bb2bae8d
Add bs4 support, removing the need for tidy up the page first.
 Fabien Ninoles <fabien@tzone.org> parents: 
8diff
changeset | 46 | ids = [attr for attr in soup["class"] if attr != "download"] | 
| 
e3a2bb2bae8d
Add bs4 support, removing the need for tidy up the page first.
 Fabien Ninoles <fabien@tzone.org> parents: 
8diff
changeset | 47 | button = soup.find(class_="flexbtn") | 
| 
e3a2bb2bae8d
Add bs4 support, removing the need for tidy up the page first.
 Fabien Ninoles <fabien@tzone.org> parents: 
8diff
changeset | 48 | desc = button.span.string | 
| 
e3a2bb2bae8d
Add bs4 support, removing the need for tidy up the page first.
 Fabien Ninoles <fabien@tzone.org> parents: 
8diff
changeset | 49 |         ids.extend(desc.split(" "))
 | 
| 
e3a2bb2bae8d
Add bs4 support, removing the need for tidy up the page first.
 Fabien Ninoles <fabien@tzone.org> parents: 
8diff
changeset | 50 | self.id = " ".join(ids) | 
| 0 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 51 | def cleanup(attr): | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 52 | attr = attr.strip() | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 53 |             if attr not in ("Download","small",""):
 | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 54 | for s in self.subst.get(attr,(attr,)): | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 55 | yield s | 
| 9 
e3a2bb2bae8d
Add bs4 support, removing the need for tidy up the page first.
 Fabien Ninoles <fabien@tzone.org> parents: 
8diff
changeset | 56 | self.attrs = set(chain.from_iterable(cleanup(attr) for attr in ids)) | 
| 0 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 57 | urls = button.a.attrs | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 58 | self.torrent = urls["data-bt"] | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 59 | self.web = urls["data-web"] | 
| 9 
e3a2bb2bae8d
Add bs4 support, removing the need for tidy up the page first.
 Fabien Ninoles <fabien@tzone.org> parents: 
8diff
changeset | 60 | details = soup.find(class_="dldetails").find(class_="dlsize") | 
| 
e3a2bb2bae8d
Add bs4 support, removing the need for tidy up the page first.
 Fabien Ninoles <fabien@tzone.org> parents: 
8diff
changeset | 61 | size = details.find(class_="mbs") | 
| 
e3a2bb2bae8d
Add bs4 support, removing the need for tidy up the page first.
 Fabien Ninoles <fabien@tzone.org> parents: 
8diff
changeset | 62 | md5 = details.find(class_="dlmd5") | 
| 
e3a2bb2bae8d
Add bs4 support, removing the need for tidy up the page first.
 Fabien Ninoles <fabien@tzone.org> parents: 
8diff
changeset | 63 | date = details.find(class_="dldate") | 
| 
e3a2bb2bae8d
Add bs4 support, removing the need for tidy up the page first.
 Fabien Ninoles <fabien@tzone.org> parents: 
8diff
changeset | 64 | self.size = size.string if size else "Unknown" | 
| 
e3a2bb2bae8d
Add bs4 support, removing the need for tidy up the page first.
 Fabien Ninoles <fabien@tzone.org> parents: 
8diff
changeset | 65 | self.md5 = md5.string if md5 else "Unknown" | 
| 
e3a2bb2bae8d
Add bs4 support, removing the need for tidy up the page first.
 Fabien Ninoles <fabien@tzone.org> parents: 
8diff
changeset | 66 | self.date = date.string if date else "Unknown" | 
| 0 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 67 | def format(self, prefix=""): | 
| 5 | 68 | res = prefix + '<download type="' + self.dltype + '" id="' + self.id + '">\n' | 
| 0 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 69 | res += prefix + " <web>" + self.web + "</web>\n" | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 70 | res += prefix + " <torrent>" + self.torrent + "</torrent>\n" | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 71 | res += prefix + " <size>" + self.size + "</size>\n" | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 72 | res += prefix + " <md5>" + self.md5 + "</md5>\n" | 
| 9 
e3a2bb2bae8d
Add bs4 support, removing the need for tidy up the page first.
 Fabien Ninoles <fabien@tzone.org> parents: 
8diff
changeset | 73 | res += prefix + " <date>" + self.date + "</date>\n" | 
| 0 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 74 | res += prefix + "</download>" | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 75 | return res | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 76 | def __repr__(self): | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 77 | return self.format() | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 78 | |
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 79 | class Downloads: | 
| 9 
e3a2bb2bae8d
Add bs4 support, removing the need for tidy up the page first.
 Fabien Ninoles <fabien@tzone.org> parents: 
8diff
changeset | 80 | def __init__(self, soup): | 
| 
e3a2bb2bae8d
Add bs4 support, removing the need for tidy up the page first.
 Fabien Ninoles <fabien@tzone.org> parents: 
8diff
changeset | 81 | self.id = [class_ for class_ in soup["class"] if class_ != "downloads"][0] | 
| 0 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 82 | self.elements = [] | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 83 | self.others = [] | 
| 9 
e3a2bb2bae8d
Add bs4 support, removing the need for tidy up the page first.
 Fabien Ninoles <fabien@tzone.org> parents: 
8diff
changeset | 84 | self.addchilds(soup) | 
| 
e3a2bb2bae8d
Add bs4 support, removing the need for tidy up the page first.
 Fabien Ninoles <fabien@tzone.org> parents: 
8diff
changeset | 85 | def addchilds(self, soup): | 
| 
e3a2bb2bae8d
Add bs4 support, removing the need for tidy up the page first.
 Fabien Ninoles <fabien@tzone.org> parents: 
8diff
changeset | 86 | for child in soup.children: | 
| 
e3a2bb2bae8d
Add bs4 support, removing the need for tidy up the page first.
 Fabien Ninoles <fabien@tzone.org> parents: 
8diff
changeset | 87 | if type(child) is not bs4.element.Tag: | 
| 
e3a2bb2bae8d
Add bs4 support, removing the need for tidy up the page first.
 Fabien Ninoles <fabien@tzone.org> parents: 
8diff
changeset | 88 | continue | 
| 
e3a2bb2bae8d
Add bs4 support, removing the need for tidy up the page first.
 Fabien Ninoles <fabien@tzone.org> parents: 
8diff
changeset | 89 | classes = child["class"] if "class" in child.attrs else [] | 
| 
e3a2bb2bae8d
Add bs4 support, removing the need for tidy up the page first.
 Fabien Ninoles <fabien@tzone.org> parents: 
8diff
changeset | 90 |             if [True for attr in classes if attr in ("arc-toggle", "downloads")]:
 | 
| 0 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 91 | self.addchilds(child) | 
| 9 
e3a2bb2bae8d
Add bs4 support, removing the need for tidy up the page first.
 Fabien Ninoles <fabien@tzone.org> parents: 
8diff
changeset | 92 | elif "download" in classes: | 
| 0 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 93 | self.elements.append(Download(self.id, child)) | 
| 9 
e3a2bb2bae8d
Add bs4 support, removing the need for tidy up the page first.
 Fabien Ninoles <fabien@tzone.org> parents: 
8diff
changeset | 94 |             elif [True for attr in classes if attr in ("clearfix","label")]:
 | 
| 0 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 95 | pass | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 96 | else: | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 97 | self.others.append(child) | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 98 | def __iter__(self): | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 99 | return iter(self.elements) | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 100 | def format(self, prefix = ""): | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 101 | res = prefix + '<downloads id="' + self.id + '">\n' | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 102 | if self.elements: | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 103 | for el in self.elements: | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 104 | res += el.format(prefix + " ") + "\n" | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 105 | if self.others: | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 106 | res += prefix + " <others>\n" | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 107 | for o in self.others: | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 108 | res += o.format(prefix + " ") + "\n" | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 109 | res += prefix + " </others>\n" | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 110 | res += prefix + "</downloads>" | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 111 | return res | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 112 | def __repr__(self): | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 113 | return self.format() | 
| 8 
98065a298da0
Update to handle audio type as "standard" (always download).
 Fabien Ninoles <fabien@tzone.org> parents: 
7diff
changeset | 114 | |
| 0 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 115 | class Game: | 
| 9 
e3a2bb2bae8d
Add bs4 support, removing the need for tidy up the page first.
 Fabien Ninoles <fabien@tzone.org> parents: 
8diff
changeset | 116 | def __init__(self, soup): | 
| 0 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 117 | self.title = "unknown" | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 118 | self.downloads = [] | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 119 | self.others = [] | 
| 9 
e3a2bb2bae8d
Add bs4 support, removing the need for tidy up the page first.
 Fabien Ninoles <fabien@tzone.org> parents: 
8diff
changeset | 120 | for child in soup.children: | 
| 
e3a2bb2bae8d
Add bs4 support, removing the need for tidy up the page first.
 Fabien Ninoles <fabien@tzone.org> parents: 
8diff
changeset | 121 | if type(child) is not bs4.element.Tag: | 
| 
e3a2bb2bae8d
Add bs4 support, removing the need for tidy up the page first.
 Fabien Ninoles <fabien@tzone.org> parents: 
8diff
changeset | 122 | continue | 
| 
e3a2bb2bae8d
Add bs4 support, removing the need for tidy up the page first.
 Fabien Ninoles <fabien@tzone.org> parents: 
8diff
changeset | 123 | classes = child["class"] if "class" in child.attrs else [] | 
| 
e3a2bb2bae8d
Add bs4 support, removing the need for tidy up the page first.
 Fabien Ninoles <fabien@tzone.org> parents: 
8diff
changeset | 124 | if "gameinfo" in classes: | 
| 
e3a2bb2bae8d
Add bs4 support, removing the need for tidy up the page first.
 Fabien Ninoles <fabien@tzone.org> parents: 
8diff
changeset | 125 | self.title = child.find(class_="title").a.string.strip() | 
| 
e3a2bb2bae8d
Add bs4 support, removing the need for tidy up the page first.
 Fabien Ninoles <fabien@tzone.org> parents: 
8diff
changeset | 126 | elif "downloads" in classes: | 
| 0 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 127 | self.downloads.append(Downloads(child)) | 
| 9 
e3a2bb2bae8d
Add bs4 support, removing the need for tidy up the page first.
 Fabien Ninoles <fabien@tzone.org> parents: 
8diff
changeset | 128 | elif [True for attr in classes if attr in ["icn", "clearfix"]]: | 
| 0 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 129 | pass | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 130 | else: | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 131 | self.others.append(child) | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 132 | def __repr__(self): | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 133 | res = "<game>\n" | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 134 | res += " <title>" + self.title + "</title>\n" | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 135 | if self.downloads: | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 136 | res += " <downloads>\n" | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 137 | for dl in self.downloads: | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 138 |                 res += dl.format("    ") + "\n"
 | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 139 | res += " </downloads>\n" | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 140 | if self.others: | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 141 | res += " <others>\n" | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 142 | for o in self.others: | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 143 |                 res += o.format("    ") + "\n"
 | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 144 | res += " </others>\n" | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 145 | res += "</game>" | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 146 | return res | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 147 | |
| 9 
e3a2bb2bae8d
Add bs4 support, removing the need for tidy up the page first.
 Fabien Ninoles <fabien@tzone.org> parents: 
8diff
changeset | 148 | def parseGamesFromSoup(soup): | 
| 
e3a2bb2bae8d
Add bs4 support, removing the need for tidy up the page first.
 Fabien Ninoles <fabien@tzone.org> parents: 
8diff
changeset | 149 | for row in soup.find_all(class_="row"): | 
| 0 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 150 | yield Game(row) | 
| 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 151 | |
| 1 
fb1ab147b2dd
Add downloading of torrent files.
 Fabien Ninoles <fabien@tzone.org> parents: 
0diff
changeset | 152 | def parseGamesFromFile(filename): | 
| 9 
e3a2bb2bae8d
Add bs4 support, removing the need for tidy up the page first.
 Fabien Ninoles <fabien@tzone.org> parents: 
8diff
changeset | 153 | for game in parseGamesFromSoup(bs4.BeautifulSoup(open(filename))): | 
| 1 
fb1ab147b2dd
Add downloading of torrent files.
 Fabien Ninoles <fabien@tzone.org> parents: 
0diff
changeset | 154 | yield game | 
| 0 
1e76c59aa3a6
Initial version: parse tidy file and select a suitable download url.
 Fabien Ninoles <fabien@tzone.org> parents: diff
changeset | 155 | |
| 8 
98065a298da0
Update to handle audio type as "standard" (always download).
 Fabien Ninoles <fabien@tzone.org> parents: 
7diff
changeset | 156 | class FileSelector: | 
| 1 
fb1ab147b2dd
Add downloading of torrent files.
 Fabien Ninoles <fabien@tzone.org> parents: 
0diff
changeset | 157 | def scoreDownload(self, dl): | 
| 
fb1ab147b2dd
Add downloading of torrent files.
 Fabien Ninoles <fabien@tzone.org> parents: 
0diff
changeset | 158 | if dl.dltype == "audio": | 
| 8 
98065a298da0
Update to handle audio type as "standard" (always download).
 Fabien Ninoles <fabien@tzone.org> parents: 
7diff
changeset | 159 | if not dl.attrs: # Empty set, so we simply take it. | 
| 
98065a298da0
Update to handle audio type as "standard" (always download).
 Fabien Ninoles <fabien@tzone.org> parents: 
7diff
changeset | 160 | return 1 | 
| 1 
fb1ab147b2dd
Add downloading of torrent files.
 Fabien Ninoles <fabien@tzone.org> parents: 
0diff
changeset | 161 | if "FLAC" in dl.attrs: | 
| 4 
e102d2bb7a9e
Update to download multiple version.
 Fabien Ninoles <fabien@tzone.org> parents: 
2diff
changeset | 162 | return 1 | 
| 
e102d2bb7a9e
Update to download multiple version.
 Fabien Ninoles <fabien@tzone.org> parents: 
2diff
changeset | 163 | if "OGG" in dl.attrs: | 
| 8 
98065a298da0
Update to handle audio type as "standard" (always download).
 Fabien Ninoles <fabien@tzone.org> parents: 
7diff
changeset | 164 | return 1 | 
| 1 
fb1ab147b2dd
Add downloading of torrent files.
 Fabien Ninoles <fabien@tzone.org> parents: 
0diff
changeset | 165 | if "MP3" in dl.attrs: | 
| 8 
98065a298da0
Update to handle audio type as "standard" (always download).
 Fabien Ninoles <fabien@tzone.org> parents: 
7diff
changeset | 166 | return 1 | 
| 1 
fb1ab147b2dd
Add downloading of torrent files.
 Fabien Ninoles <fabien@tzone.org> parents: 
0diff
changeset | 167 | if "website" in dl.attrs: | 
| 
fb1ab147b2dd
Add downloading of torrent files.
 Fabien Ninoles <fabien@tzone.org> parents: 
0diff
changeset | 168 | return -1 | 
| 8 
98065a298da0
Update to handle audio type as "standard" (always download).
 Fabien Ninoles <fabien@tzone.org> parents: 
7diff
changeset | 169 |             raise Exception("Unknown audio type: %r" % (dl.attrs))
 | 
| 1 
fb1ab147b2dd
Add downloading of torrent files.
 Fabien Ninoles <fabien@tzone.org> parents: 
0diff
changeset | 170 |         if dl.dltype in ("mac","windows"):
 | 
| 
fb1ab147b2dd
Add downloading of torrent files.
 Fabien Ninoles <fabien@tzone.org> parents: 
0diff
changeset | 171 | return -1 | 
| 
fb1ab147b2dd
Add downloading of torrent files.
 Fabien Ninoles <fabien@tzone.org> parents: 
0diff
changeset | 172 | if dl.dltype == "linux": | 
| 
fb1ab147b2dd
Add downloading of torrent files.
 Fabien Ninoles <fabien@tzone.org> parents: 
0diff
changeset | 173 | score = 1 | 
| 
fb1ab147b2dd
Add downloading of torrent files.
 Fabien Ninoles <fabien@tzone.org> parents: 
0diff
changeset | 174 | if "x64" in dl.attrs: | 
| 4 
e102d2bb7a9e
Update to download multiple version.
 Fabien Ninoles <fabien@tzone.org> parents: 
2diff
changeset | 175 | score += 2 | 
| 1 
fb1ab147b2dd
Add downloading of torrent files.
 Fabien Ninoles <fabien@tzone.org> parents: 
0diff
changeset | 176 | if "deb" in dl.attrs: | 
| 
fb1ab147b2dd
Add downloading of torrent files.
 Fabien Ninoles <fabien@tzone.org> parents: 
0diff
changeset | 177 | score += 1 | 
| 8 
98065a298da0
Update to handle audio type as "standard" (always download).
 Fabien Ninoles <fabien@tzone.org> parents: 
7diff
changeset | 178 | if "Stream" in dl.attrs: | 
| 
98065a298da0
Update to handle audio type as "standard" (always download).
 Fabien Ninoles <fabien@tzone.org> parents: 
7diff
changeset | 179 | score -= 1 | 
| 1 
fb1ab147b2dd
Add downloading of torrent files.
 Fabien Ninoles <fabien@tzone.org> parents: 
0diff
changeset | 180 | return score | 
| 
fb1ab147b2dd
Add downloading of torrent files.
 Fabien Ninoles <fabien@tzone.org> parents: 
0diff
changeset | 181 | if dl.dltype == "android": | 
| 
fb1ab147b2dd
Add downloading of torrent files.
 Fabien Ninoles <fabien@tzone.org> parents: 
0diff
changeset | 182 | return -1 | 
| 5 | 183 | if dl.dltype == "ebook": | 
| 184 | if "MOBI" in dl.attrs: | |
| 185 | return -1 | |
| 186 | if "HD" in dl.attrs: | |
| 187 | return 2 | |
| 188 | return 1 | |
| 1 
fb1ab147b2dd
Add downloading of torrent files.
 Fabien Ninoles <fabien@tzone.org> parents: 
0diff
changeset | 189 |         raise Exception("Unknown dls type: %r" % (dl,))
 | 
| 
fb1ab147b2dd
Add downloading of torrent files.
 Fabien Ninoles <fabien@tzone.org> parents: 
0diff
changeset | 190 | |
| 
fb1ab147b2dd
Add downloading of torrent files.
 Fabien Ninoles <fabien@tzone.org> parents: 
0diff
changeset | 191 | def chooseDownloads(self, dls): | 
| 
fb1ab147b2dd
Add downloading of torrent files.
 Fabien Ninoles <fabien@tzone.org> parents: 
0diff
changeset | 192 | return sorted(((self.scoreDownload(dl),dl) for dl in dls), key=lambda x: x[0], reverse=True) | 
| 
fb1ab147b2dd
Add downloading of torrent files.
 Fabien Ninoles <fabien@tzone.org> parents: 
0diff
changeset | 193 | |
| 
fb1ab147b2dd
Add downloading of torrent files.
 Fabien Ninoles <fabien@tzone.org> parents: 
0diff
changeset | 194 | def __call__(self, dls): | 
| 
fb1ab147b2dd
Add downloading of torrent files.
 Fabien Ninoles <fabien@tzone.org> parents: 
0diff
changeset | 195 | return self.chooseDownloads(dls) | 
| 
fb1ab147b2dd
Add downloading of torrent files.
 Fabien Ninoles <fabien@tzone.org> parents: 
0diff
changeset | 196 | |
| 4 
e102d2bb7a9e
Update to download multiple version.
 Fabien Ninoles <fabien@tzone.org> parents: 
2diff
changeset | 197 | def selectHighestScore(scores): | 
| 
e102d2bb7a9e
Update to download multiple version.
 Fabien Ninoles <fabien@tzone.org> parents: 
2diff
changeset | 198 | if scores: | 
| 
e102d2bb7a9e
Update to download multiple version.
 Fabien Ninoles <fabien@tzone.org> parents: 
2diff
changeset | 199 | get_first = operator.itemgetter(0) | 
| 
e102d2bb7a9e
Update to download multiple version.
 Fabien Ninoles <fabien@tzone.org> parents: 
2diff
changeset | 200 | score, dls = next(groupby(sorted(scores, key = get_first, reverse=True), get_first)) | 
| 
e102d2bb7a9e
Update to download multiple version.
 Fabien Ninoles <fabien@tzone.org> parents: 
2diff
changeset | 201 | if score > 0: | 
| 
e102d2bb7a9e
Update to download multiple version.
 Fabien Ninoles <fabien@tzone.org> parents: 
2diff
changeset | 202 | return list(dl for s, dl in dls) | 
| 
e102d2bb7a9e
Update to download multiple version.
 Fabien Ninoles <fabien@tzone.org> parents: 
2diff
changeset | 203 | else: | 
| 
e102d2bb7a9e
Update to download multiple version.
 Fabien Ninoles <fabien@tzone.org> parents: 
2diff
changeset | 204 | return [] | 
| 
e102d2bb7a9e
Update to download multiple version.
 Fabien Ninoles <fabien@tzone.org> parents: 
2diff
changeset | 205 |     logging.debug("Empty scores list: %r", scores)
 | 
| 
e102d2bb7a9e
Update to download multiple version.
 Fabien Ninoles <fabien@tzone.org> parents: 
2diff
changeset | 206 | return [] | 
| 
e102d2bb7a9e
Update to download multiple version.
 Fabien Ninoles <fabien@tzone.org> parents: 
2diff
changeset | 207 | |
| 2 
3675dd7daf59
Take filename from command line arguments, add copyright and better readme text.
 Fabien Ninoles <fabien@tzone.org> parents: 
1diff
changeset | 208 | def main(fn): | 
| 
3675dd7daf59
Take filename from command line arguments, add copyright and better readme text.
 Fabien Ninoles <fabien@tzone.org> parents: 
1diff
changeset | 209 | selector = FileSelector() | 
| 
3675dd7daf59
Take filename from command line arguments, add copyright and better readme text.
 Fabien Ninoles <fabien@tzone.org> parents: 
1diff
changeset | 210 | downloads = [] | 
| 
3675dd7daf59
Take filename from command line arguments, add copyright and better readme text.
 Fabien Ninoles <fabien@tzone.org> parents: 
1diff
changeset | 211 | for game in parseGamesFromFile(fn): | 
| 
3675dd7daf59
Take filename from command line arguments, add copyright and better readme text.
 Fabien Ninoles <fabien@tzone.org> parents: 
1diff
changeset | 212 | for dls in game.downloads: | 
| 4 
e102d2bb7a9e
Update to download multiple version.
 Fabien Ninoles <fabien@tzone.org> parents: 
2diff
changeset | 213 | scores = list(selector(dls)) | 
| 
e102d2bb7a9e
Update to download multiple version.
 Fabien Ninoles <fabien@tzone.org> parents: 
2diff
changeset | 214 | choosen = selectHighestScore(scores) | 
| 2 
3675dd7daf59
Take filename from command line arguments, add copyright and better readme text.
 Fabien Ninoles <fabien@tzone.org> parents: 
1diff
changeset | 215 | for score, dl in scores: | 
| 9 
e3a2bb2bae8d
Add bs4 support, removing the need for tidy up the page first.
 Fabien Ninoles <fabien@tzone.org> parents: 
8diff
changeset | 216 |                 print("[%s] %2d | %-20s | %-15s | %-10s | %-25s | %s " % (
 | 
| 2 
3675dd7daf59
Take filename from command line arguments, add copyright and better readme text.
 Fabien Ninoles <fabien@tzone.org> parents: 
1diff
changeset | 217 | "*" if dl in choosen else " ", | 
| 
3675dd7daf59
Take filename from command line arguments, add copyright and better readme text.
 Fabien Ninoles <fabien@tzone.org> parents: 
1diff
changeset | 218 | score, | 
| 8 
98065a298da0
Update to handle audio type as "standard" (always download).
 Fabien Ninoles <fabien@tzone.org> parents: 
7diff
changeset | 219 | game.title, | 
| 2 
3675dd7daf59
Take filename from command line arguments, add copyright and better readme text.
 Fabien Ninoles <fabien@tzone.org> parents: 
1diff
changeset | 220 | dls.id, | 
| 9 
e3a2bb2bae8d
Add bs4 support, removing the need for tidy up the page first.
 Fabien Ninoles <fabien@tzone.org> parents: 
8diff
changeset | 221 | dls.date, | 
| 2 
3675dd7daf59
Take filename from command line arguments, add copyright and better readme text.
 Fabien Ninoles <fabien@tzone.org> parents: 
1diff
changeset | 222 | ", ".join(sorted(dl.attrs)), | 
| 
3675dd7daf59
Take filename from command line arguments, add copyright and better readme text.
 Fabien Ninoles <fabien@tzone.org> parents: 
1diff
changeset | 223 | dl.torrent)) | 
| 
3675dd7daf59
Take filename from command line arguments, add copyright and better readme text.
 Fabien Ninoles <fabien@tzone.org> parents: 
1diff
changeset | 224 | if dl in choosen: | 
| 
3675dd7daf59
Take filename from command line arguments, add copyright and better readme text.
 Fabien Ninoles <fabien@tzone.org> parents: 
1diff
changeset | 225 | downloads.append(dl) | 
| 
3675dd7daf59
Take filename from command line arguments, add copyright and better readme text.
 Fabien Ninoles <fabien@tzone.org> parents: 
1diff
changeset | 226 | if not scores: | 
| 
3675dd7daf59
Take filename from command line arguments, add copyright and better readme text.
 Fabien Ninoles <fabien@tzone.org> parents: 
1diff
changeset | 227 |                 print("No download for",dls.id)
 | 
| 
3675dd7daf59
Take filename from command line arguments, add copyright and better readme text.
 Fabien Ninoles <fabien@tzone.org> parents: 
1diff
changeset | 228 |             print("-" * 80)
 | 
| 1 
fb1ab147b2dd
Add downloading of torrent files.
 Fabien Ninoles <fabien@tzone.org> parents: 
0diff
changeset | 229 | |
| 2 
3675dd7daf59
Take filename from command line arguments, add copyright and better readme text.
 Fabien Ninoles <fabien@tzone.org> parents: 
1diff
changeset | 230 | import urllib.request | 
| 
3675dd7daf59
Take filename from command line arguments, add copyright and better readme text.
 Fabien Ninoles <fabien@tzone.org> parents: 
1diff
changeset | 231 | import urllib.parse | 
| 
3675dd7daf59
Take filename from command line arguments, add copyright and better readme text.
 Fabien Ninoles <fabien@tzone.org> parents: 
1diff
changeset | 232 | import os | 
| 6 
0c6d2ed2cd7c
Add download script production for http only links.
 Fabien Ninoles <fabien@tzone.org> parents: 
5diff
changeset | 233 |     urlfile = open('http-download.sh','w')
 | 
| 2 
3675dd7daf59
Take filename from command line arguments, add copyright and better readme text.
 Fabien Ninoles <fabien@tzone.org> parents: 
1diff
changeset | 234 | opener = urllib.request.build_opener() | 
| 4 
e102d2bb7a9e
Update to download multiple version.
 Fabien Ninoles <fabien@tzone.org> parents: 
2diff
changeset | 235 | for dl in (dl for dl in downloads): | 
| 
e102d2bb7a9e
Update to download multiple version.
 Fabien Ninoles <fabien@tzone.org> parents: 
2diff
changeset | 236 | if dl.torrent: | 
| 
e102d2bb7a9e
Update to download multiple version.
 Fabien Ninoles <fabien@tzone.org> parents: 
2diff
changeset | 237 | try: | 
| 
e102d2bb7a9e
Update to download multiple version.
 Fabien Ninoles <fabien@tzone.org> parents: 
2diff
changeset | 238 | fn = os.path.basename(urllib.parse.urlsplit(dl.torrent).path) | 
| 
e102d2bb7a9e
Update to download multiple version.
 Fabien Ninoles <fabien@tzone.org> parents: 
2diff
changeset | 239 | if os.path.exists(fn): | 
| 
e102d2bb7a9e
Update to download multiple version.
 Fabien Ninoles <fabien@tzone.org> parents: 
2diff
changeset | 240 |                     logging.info("Skipping existing torrent %s", fn)
 | 
| 
e102d2bb7a9e
Update to download multiple version.
 Fabien Ninoles <fabien@tzone.org> parents: 
2diff
changeset | 241 | else: | 
| 
e102d2bb7a9e
Update to download multiple version.
 Fabien Ninoles <fabien@tzone.org> parents: 
2diff
changeset | 242 |                     logging.info("Saving %s as %s", dl.torrent, fn)
 | 
| 
e102d2bb7a9e
Update to download multiple version.
 Fabien Ninoles <fabien@tzone.org> parents: 
2diff
changeset | 243 | with opener.open(dl.torrent) as u: | 
| 
e102d2bb7a9e
Update to download multiple version.
 Fabien Ninoles <fabien@tzone.org> parents: 
2diff
changeset | 244 | with open(fn,"wb") as f: | 
| 
e102d2bb7a9e
Update to download multiple version.
 Fabien Ninoles <fabien@tzone.org> parents: 
2diff
changeset | 245 | f.write(u.read()) | 
| 
e102d2bb7a9e
Update to download multiple version.
 Fabien Ninoles <fabien@tzone.org> parents: 
2diff
changeset | 246 | except: | 
| 
e102d2bb7a9e
Update to download multiple version.
 Fabien Ninoles <fabien@tzone.org> parents: 
2diff
changeset | 247 |                 logging.exception("Error with download %r", dl)
 | 
| 
e102d2bb7a9e
Update to download multiple version.
 Fabien Ninoles <fabien@tzone.org> parents: 
2diff
changeset | 248 | else: | 
| 
e102d2bb7a9e
Update to download multiple version.
 Fabien Ninoles <fabien@tzone.org> parents: 
2diff
changeset | 249 |             logging.info("No torrent, url is %s", dl.web)
 | 
| 6 
0c6d2ed2cd7c
Add download script production for http only links.
 Fabien Ninoles <fabien@tzone.org> parents: 
5diff
changeset | 250 | fn = os.path.basename(urllib.parse.urlsplit(dl.web).path) | 
| 8 
98065a298da0
Update to handle audio type as "standard" (always download).
 Fabien Ninoles <fabien@tzone.org> parents: 
7diff
changeset | 251 |             urlfile.write("wget --progress=bar -c -O %s \"%s\"\n" % (fn,dl.web))
 | 
| 
98065a298da0
Update to handle audio type as "standard" (always download).
 Fabien Ninoles <fabien@tzone.org> parents: 
7diff
changeset | 252 | |
| 1 
fb1ab147b2dd
Add downloading of torrent files.
 Fabien Ninoles <fabien@tzone.org> parents: 
0diff
changeset | 253 | |
| 
fb1ab147b2dd
Add downloading of torrent files.
 Fabien Ninoles <fabien@tzone.org> parents: 
0diff
changeset | 254 | |
| 2 
3675dd7daf59
Take filename from command line arguments, add copyright and better readme text.
 Fabien Ninoles <fabien@tzone.org> parents: 
1diff
changeset | 255 | if __name__ == '__main__': | 
| 
3675dd7daf59
Take filename from command line arguments, add copyright and better readme text.
 Fabien Ninoles <fabien@tzone.org> parents: 
1diff
changeset | 256 | import sys | 
| 4 
e102d2bb7a9e
Update to download multiple version.
 Fabien Ninoles <fabien@tzone.org> parents: 
2diff
changeset | 257 | logging.getLogger().setLevel(logging.INFO) | 
| 2 
3675dd7daf59
Take filename from command line arguments, add copyright and better readme text.
 Fabien Ninoles <fabien@tzone.org> parents: 
1diff
changeset | 258 | main(sys.argv[1]) |