()
| 54 | |
| 55 | |
| 56 | def aksearch(): |
| 57 | helper() |
| 58 | tmp_url = 'http://kickass.to/usearch/' |
| 59 | |
| 60 | query = input('Type query: ') |
| 61 | url = tmp_url + query + '/' |
| 62 | |
| 63 | try: |
| 64 | cont = requests.get(url) |
| 65 | except requests.exceptions.RequestException as e: |
| 66 | raise SystemExit('\n' + OutColors.LR + str(e)) |
| 67 | |
| 68 | # check if no torrents found |
| 69 | if not re.findall(r'Download torrent file', str(cont.content)): |
| 70 | print('Torrents found: 0') |
| 71 | aksearch() |
| 72 | else: |
| 73 | soup = BeautifulSoup(cont.content) |
| 74 | |
| 75 | # to use by age, seeders, and leechers |
| 76 | # sample: |
| 77 | # 700.46 MB |
| 78 | # 5 |
| 79 | # 2 years |
| 80 | # 1852 |
| 81 | # 130 |
| 82 | al = [s.get_text() for s in soup.find_all('td', {'class':'center'})] |
| 83 | |
| 84 | href = [a.get('href') for a in soup.find_all('a', {'title':'Download torrent file'})] |
| 85 | size = [t.get_text() for t in soup.find_all('td', {'class':'nobr'}) ] |
| 86 | title = [ti.get_text() for ti in soup.find_all('a', {'class':'cellMainLink'})] |
| 87 | age = al[2::5] |
| 88 | seeders = al[3::5] |
| 89 | leechers = al[4::5] |
| 90 | |
| 91 | # for table printing |
| 92 | table = [[OutColors.BW + str(i+1) + OutColors.DEFAULT if (i+1) % 2 == 0 else i+1, |
| 93 | OutColors.BW + title[i] + OutColors.DEFAULT if (i+1) % 2 == 0 else title[i], |
| 94 | OutColors.BW + size[i] + OutColors.DEFAULT if (i+1) % 2 == 0 else size[i], |
| 95 | OutColors.BW + age[i] + OutColors.DEFAULT if (i+1) % 2 == 0 else age[i], |
| 96 | OutColors.SEEDER + seeders[i] + OutColors.DEFAULT if (i+1) % 2 == 0 else OutColors.LG + seeders[i] + OutColors.DEFAULT, |
| 97 | OutColors.LEECHER + leechers[i] + OutColors.DEFAULT if (i+1) % 2 == 0 else OutColors.LR + leechers[i] + OutColors.DEFAULT] for i in range(len(href))] |
| 98 | print() |
| 99 | print(tabulate.tabulate(table, headers=['No', 'Title', 'Size', 'Age', 'Seeders', 'Leechers'])) |
| 100 | |
| 101 | # torrent selection |
| 102 | if len(href) == 1: |
| 103 | torrent = 1 |
| 104 | else: |
| 105 | print('\nSelect torrent: [ 1 - ' + str(len(href)) + ' ] or [ M ] to go back to main menu or [ Q ] to quit') |
| 106 | torrent = select_torrent() |
| 107 | if torrent == 'Q' or torrent == 'q': |
| 108 | sys.exit(0) |
| 109 | elif torrent == 'M' or torrent == 'm': |
| 110 | aksearch() |
| 111 | else: |
| 112 | if int(torrent) <= 0 or int(torrent) > len(href): |
| 113 | print('Use eyeglasses...') |
no test coverage detected