Skip to content

Conversation

@choppylion
Copy link
Contributor

@choppylion choppylion commented Nov 18, 2017

If song is not available due to requests of the copyright holder it has following tag:
<div class="audio_item audio_item_disabled"></div> so we can't extract any info from it and audio.select('.ai_artist') will return empty list. After that we'll get IndexError: list index out of range.

So I think it'll be good to check if tag is not containing class named 'audio_item_disabled'.
But how can we tell user about this by API?

@python273
Copy link
Owner

IndexError: list index out of range.

Can you show traceback?

@choppylion
Copy link
Contributor Author

Sure. But don't pay attention on line numbers, because I've changed code a little bit.

Traceback (most recent call last):
  File "C:\Program Files\JetBrains\PyCharm 2017.1.2\helpers\pydev\pydevd.py", line 1585, in <module>
    globals = debugger.run(setup['file'], None, None, is_module)
  File "C:\Program Files\JetBrains\PyCharm 2017.1.2\helpers\pydev\pydevd.py", line 1015, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "C:\Program Files\JetBrains\PyCharm 2017.1.2\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "C:/Work/vktotg/vktolocal.py", line 188, in <module>
    main()
  File "C:/Work/vktotg/vktolocal.py", line 178, in main
    process(session)
  File "C:/Work/vktotg/vktolocal.py", line 133, in process
    track_list = get_track_list(vk_session)
  File "C:/Work/vktotg/vktolocal.py", line 119, in get_track_list
    chunk = vk_audio.get(owner_id=user_id, offset=offset)
  File "C:\Tools\Python35\lib\site-packages\vk_api\audio.py", line 52, in get
    return scrap_data(response.text)
  File "C:\Tools\Python35\lib\site-packages\vk_api\audio.py", line 146, in scrap_data
    artist = audio.select('.ai_artist')[0].text
IndexError: list index out of range

@choppylion
Copy link
Contributor Author

choppylion commented Nov 19, 2017

I have a proposal how to get info of disabled track.
We can get track ID of previous available track, find this track on DOM of desktop version and get its following sibling, that'll have all this data excepting link to track. So we can at least tell user what tracks are unavailable to download.

After some research, I got that we cannot get desktop DOM with specified offset.

vk_api/audio.py Outdated
'id': audio['id'],
'url': link
})
if 'audio_item_disabled' not in audio["class"]:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's make

if 'audio_item_disabled' in audio['class']:
    continue

ai_artist = audio.select('.ai_artist')
...

vk_api/audio.py Outdated
if 'audio_item_disabled' in audio["class"]:
# TODO: implement getting data of unavailable track
continue
else:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can delete else

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to make any more changes under else. I'm gonna just replace lines 132-133 by implemented code in future.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else block is not needed, until it's not implemented

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deal

@python273
Copy link
Owner

Can you squash commits?

choppylion added 2 commits November 19, 2017 18:51
(+) Preparing for impl of fetching unavailable data

(~) Deleting else
@python273 python273 merged commit cde005c into python273:master Nov 24, 2017
@python273
Copy link
Owner

Looks like GitHub has ability to squash PR's commits. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants