|      5 # |      5 # | 
|      6 # This program is free software: you can redistribute it and/or modify |      6 # This program is free software: you can redistribute it and/or modify | 
|      7 # it under the terms of the GNU General Public License as published by |      7 # it under the terms of the GNU General Public License as published by | 
|      8 # the Free Software Foundation, either version 3 of the License, or |      8 # the Free Software Foundation, either version 3 of the License, or | 
|      9 # (at your option) any later version. |      9 # (at your option) any later version. | 
|     10 #  |     10 # | 
|     11 # This program is distributed in the hope that it will be useful, |     11 # This program is distributed in the hope that it will be useful, | 
|     12 # but WITHOUT ANY WARRANTY; without even the implied warranty of |     12 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|     13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the |     13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|     14 # GNU General Public License for more details. |     14 # GNU General Public License for more details. | 
|     15 # |     15 # | 
|    237     for l in open(filename): |    237     for l in open(filename): | 
|    238         parser.feed(l) |    238         parser.feed(l) | 
|    239     for game in parseGamesFromDom(parser.dom): |    239     for game in parseGamesFromDom(parser.dom): | 
|    240         yield game |    240         yield game | 
|    241  |    241  | 
|    242 class FileSelector:     |    242 class FileSelector: | 
|    243     def scoreDownload(self, dl): |    243     def scoreDownload(self, dl): | 
|    244         if dl.dltype == "audio": |    244         if dl.dltype == "audio": | 
|         |    245             if not dl.attrs: # Empty set, so we simply take it. | 
|         |    246                 return 1 | 
|    245             if "FLAC" in dl.attrs: |    247             if "FLAC" in dl.attrs: | 
|    246                 return 1 |    248                 return 1 | 
|    247             if "OGG" in dl.attrs: |    249             if "OGG" in dl.attrs: | 
|    248                 return 1  |    250                 return 1 | 
|    249             if "MP3" in dl.attrs: |    251             if "MP3" in dl.attrs: | 
|    250                 return 1  |    252                 return 1 | 
|    251             if "website" in dl.attrs: |    253             if "website" in dl.attrs: | 
|    252                 return -1 |    254                 return -1 | 
|    253             raise Exception("Unknow audio type: %r" % (dl.attrs)) |    255             raise Exception("Unknown audio type: %r" % (dl.attrs)) | 
|    254         if dl.dltype in ("mac","windows"): |    256         if dl.dltype in ("mac","windows"): | 
|    255             return -1 |    257             return -1 | 
|    256         if dl.dltype == "linux": |    258         if dl.dltype == "linux": | 
|    257             score = 1 |    259             score = 1 | 
|    258             if "x64" in dl.attrs: |    260             if "x64" in dl.attrs: | 
|    259                 score += 2 |    261                 score += 2 | 
|    260             if "deb" in dl.attrs: |    262             if "deb" in dl.attrs: | 
|    261                 score += 1 |    263                 score += 1 | 
|         |    264             if "Stream" in dl.attrs: | 
|         |    265                 score -= 1 | 
|    262             return score |    266             return score | 
|    263         if dl.dltype == "android": |    267         if dl.dltype == "android": | 
|    264             return -1 |    268             return -1 | 
|    265         if dl.dltype == "ebook": |    269         if dl.dltype == "ebook": | 
|    266             if "MOBI" in dl.attrs: |    270             if "MOBI" in dl.attrs: | 
|    296             choosen = selectHighestScore(scores) |    300             choosen = selectHighestScore(scores) | 
|    297             for score, dl in scores: |    301             for score, dl in scores: | 
|    298                 print("[%s] %2d | %-20s | %-10s | %-25s | %s " % ( |    302                 print("[%s] %2d | %-20s | %-10s | %-25s | %s " % ( | 
|    299                         "*" if dl in choosen else " ", |    303                         "*" if dl in choosen else " ", | 
|    300                         score, |    304                         score, | 
|    301                         game.title,  |    305                         game.title, | 
|    302                         dls.id, |    306                         dls.id, | 
|    303                         ", ".join(sorted(dl.attrs)), |    307                         ", ".join(sorted(dl.attrs)), | 
|    304                         dl.torrent)) |    308                         dl.torrent)) | 
|    305                 if dl in choosen: |    309                 if dl in choosen: | 
|    306                     downloads.append(dl) |    310                     downloads.append(dl) | 
|    327             except: |    331             except: | 
|    328                 logging.exception("Error with download %r", dl) |    332                 logging.exception("Error with download %r", dl) | 
|    329         else: |    333         else: | 
|    330             logging.info("No torrent, url is %s", dl.web) |    334             logging.info("No torrent, url is %s", dl.web) | 
|    331             fn = os.path.basename(urllib.parse.urlsplit(dl.web).path) |    335             fn = os.path.basename(urllib.parse.urlsplit(dl.web).path) | 
|    332             urlfile.write("wget --progress=bar -c -O ../packages/%s \"%s\"\n" % (fn,dl.web)) |    336             urlfile.write("wget --progress=bar -c -O %s \"%s\"\n" % (fn,dl.web)) | 
|    333              |    337  | 
|    334  |    338  | 
|    335  |    339  | 
|    336 if __name__ == '__main__': |    340 if __name__ == '__main__': | 
|    337     import sys |    341     import sys | 
|    338     logging.getLogger().setLevel(logging.INFO) |    342     logging.getLogger().setLevel(logging.INFO) |