EchterAlsFake / PHUB

A lightweight API for Pornhub
https://phub.rtfd.io
GNU General Public License v3.0
76 stars 25 forks source link

List index out of range #9

Closed EchterAlsFake closed 1 year ago

EchterAlsFake commented 1 year ago

Hey,

I got the following error:

Traceback (most recent call last):
  File "/home/asuna/PycharmProjects/Porn_Fetch/Porn_Fetch.py", line 449, in start
    video = self.test_video(url)
            ^^^^^^^^^^^^^^^^^^^^
  File "/home/asuna/PycharmProjects/Porn_Fetch/Porn_Fetch.py", line 434, in test_video
    self.video = self.client.get(url)
                 ^^^^^^^^^^^^^^^^^^^^
  File "/home/asuna/PycharmProjects/Porn_Fetch/venv/lib/python3.11/site-packages/phub/core.py", line 328, in get
    return classes.Video(client = self, url = url, preload = preload)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/asuna/PycharmProjects/Porn_Fetch/venv/lib/python3.11/site-packages/phub/classes.py", line 185, in __init__
    self.refresh()
  File "/home/asuna/PycharmProjects/Porn_Fetch/venv/lib/python3.11/site-packages/phub/classes.py", line 206, in refresh
    self.data = parser.resolve(self)
                ^^^^^^^^^^^^^^^^^^^^
  File "/home/asuna/PycharmProjects/Porn_Fetch/venv/lib/python3.11/site-packages/phub/parser.py", line 80, in resolve
    script = video.page.split("flashvars_['nextVideo'];")[1].split('var nextVideoPlay')[0]
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^
IndexError: list index out of range

I tried with my UI and with your CLI script.

I used the V3.2.1 API version, but I haven't tried it with V4 as you said it would be unstable and not production ready.

Egsagon commented 1 year ago

Hey

Yeah v4 is absolutely not ready, there is so much work to be done, and i can't put time in a project of that scale right now.

About the issue, this is caused by a PH update. They have removed their old obfuscated M3U master url. PHUB already work around it, using mediaDefinitions urls. The real problem is, I have no idea why the parser was still trying to parse it, if it was/still is nescessary or not.

I'm in no state to commit something as of now, i'll fix that later this weekend. In the meantime, here is a monkeypatch to apply after importing phub.

import phub

def patch(video: phub.Video) -> dict:
    '''
    Monkey patch for phub.parser.resolve. 
    '''

    phub.utils.log('parser', 'Resolving page JS script...', level = 6)

    for _ in range(phub.parser.RENEW_MAX_ATTEMPTS):
        response = phub.consts.regexes.video_flashvar(video.page)

        if not len(response):
            phub.parser.renew(video)
            continue

        flash, ctx = response[0]
        break

    else:
        raise phub.errors.ParsingError('Max renew attempts exceeded.')

    # Load context
    return phub.parser.json.loads(ctx)

phub.parser.resolve = patch

# Then do whatever you want as normal
client = phub.Client()

video = client.get(key = '...')
video.download('test.mp4', 'best')

Tell me if it fixes the error. Have a great day (or night)

EchterAlsFake commented 1 year ago

Issue is fixed with the patch.

Thanks for the quick reply :)

Egsagon commented 1 year ago

Fixed and released with 3.2.2. Thanks!