devilcius / whatapi

Module to manage redacted.ch as a web service
5 stars 2 forks source link

Keyerror when getting torrenturl #2

Closed bruut closed 12 years ago

bruut commented 12 years ago

Using your code in combination with headphones in cohena's what implementation. It authenticates nicely and finds the album I want but then it gives me the following error:

11-sep-2012 09:40:05 - INFO :: Thread-12 : Searching torrents for RJD2 Inversion
s of the Colossus since it was marked as wanted
authenticating...
11-sep-2012 09:40:24 - INFO :: Thread-12 : What.cd artist ID: 728
11-sep-2012 09:40:24 - INFO :: Thread-12 : Found 115 releases on what.cd for RJD
2
Exception in thread Thread-12:
Traceback (most recent call last):
  File "C:\Python27\lib\threading.py", line 552, in __bootstrap_inner
    self.run()
  File "C:\Python27\lib\threading.py", line 505, in run
    self.__target(*self.__args, **self.__kwargs)
  File "C:\Program Files (x86)\Headphones2\headphones\searcher.py", line 105, in
 searchforalbum
    searchTorrent(result['AlbumID'], new)
  File "C:\Program Files (x86)\Headphones2\headphones\searcher.py", line 857, in
 searchTorrent
    match_torrents.append(whatcd.getTorrent(release['id']))
  File "C:\Program Files (x86)\Headphones2\lib\whatapi.py", line 265, in getTorr
ent
    return Torrent(id, page, None, self)
  File "C:\Program Files (x86)\Headphones2\lib\whatapi.py", line 738, in __init_
_
    self.torrentinfo = self.getInfo()
  File "C:\Program Files (x86)\Headphones2\lib\whatapi.py", line 763, in getInfo

    torrentpage = BeautifulSoup(self._request("GET", "/"+self.getTorrentUrl(), "
", self.whatcd.headers).execute(True).body)
  File "C:\Program Files (x86)\Headphones2\lib\whatapi.py", line 756, in getTorr
entUrl
    return dict(headers)['location']
KeyError: 'location'

Any suggestions?

devilcius commented 12 years ago

That's likely because the torrent object has been instantiated with a wrong torrent id (maybe a group torrent id?).

torrent = whatcd.getTorrent(torrentid)

In any case, I've just sanitized the code to avoid the exception. I'll push it tonight.

bruut commented 12 years ago

Well that fixed that. Problem is, now I get zero results.

11-sep-2012 20:22:06 - INFO :: Thread-12 : Searching torrents for Analogik New S
eeland since it was marked as wanted
authenticating...
11-sep-2012 20:22:13 - INFO :: Thread-12 : What.cd artist ID: 69099
11-sep-2012 20:22:13 - INFO :: Thread-12 : Found 0 releases on what.cd for Analo
gik
11-sep-2012 20:22:13 - INFO :: Thread-12 : No results found from What.cd for Ana
logik New Seeland after filtering

(The album is listed on What, for the record)

devilcius commented 12 years ago

Download the latest whatapi version and check your code. Also delete your cookie, just in case. It's working for me:

    whatcd = whatapi.getWhatcdNetwork('devilcius', 'pass')
    artist = whatcd.getArtist("Analogik")
    print artist.getArtistTags()

result:

authenticating...
['electronic', 'jazz', 'balkan', 'world.music', 'downtempo', 'folk', 'experimental', 'broken.beat', 'trip.hop', 'swing', 'house', 'dub', 'tech.house', 'denmark', 'nu.jazz', 'alternative', 'tartelet', 'electro.swing', 'electro', 'chillosophy.music', 'ambient', 'idm', 'pop', 'funk', 'copenhagen', 'soul', 'indie.rock', 'minimal', 'electronica', 'indie', 'ethiopian', 'acoustic', 'easy.listening', 'danish', 'progressive.trance', 'mestizo', 'reggae', 'deep.house']
fatcat31 commented 12 years ago

artist.getArtistReleases() is still blank for that above example.

I don't know too much about this stuff, but I don't think there's a {'class':'torrent_table'} when doing the soup.fetch in artistInfo. It'll work for {'class':'torrent_table grouped release_table'} instead, but then the result is a list of torrent groups, rather than a list of torrents. Need to then be able to sort through the torrents within the torrent group, and get single torrents with non-group torrentIDs.

cohena commented 12 years ago

Now that I've resolved my authentication issues, I'm seeing the same behavior as fatcat. It does look like the problem is in that code he pointed out. I'm gonna throw things in the ol' debugger and see if I can work out what it needs to do there.

cohena commented 12 years ago

After swapping to {'class':'torrent_table grouped release_table'} in artist.getArtistReleases(), it definitely seems to get a proper list of releases / torrent groups. I'll just need to tweak things to get the actual torrent listings out of the list.

devilcius commented 12 years ago

That's it. Line 1247 should be replaced by

for releasetype in soup.fetch('table', {'class': re.compile(r'\btorrent_table\b')}):

I'll push a fixed version later on

bruut commented 12 years ago

It still does not find any releases, which it did do before (see log of first post). Besides, it now prints a logout url :s

12-sep-2012 09:16:14 - INFO :: Thread-12 : Searching torrents for Analogik New S
eeland since it was marked as wanted
authenticating...
User id: #idremoved#
logout.php?auth=#authkeyremoved#
12-sep-2012 09:16:23 - INFO :: Thread-12 : What.cd artist ID: 69099
12-sep-2012 09:16:23 - INFO :: Thread-12 : Found 0 releases on what.cd for Analo
gik
12-sep-2012 09:16:23 - INFO :: Thread-12 : No results found from What.cd for Ana
logik New Seeland after filtering
cohena commented 12 years ago

I'll have a commit ready in just a little bit that should allow it to get much further. Some restructuring and bug fixing was required.

devilcius commented 12 years ago

I assume is not related with whatapi. I've fixed and pushed the artistinfo fix though

bruut commented 12 years ago

It wasn't. Thanks. Headphones is working very well with the new what implementation.

Thanks for all your work