einstein95 / crunchy-xml-decoder

GNU General Public License v2.0
35 stars 14 forks source link

Getting an AttributeError when retrieving the player revision #52

Closed Kamekameha closed 8 years ago

Kamekameha commented 8 years ago

Apparently now when the content is region-blocked Crunchyroll doesn't provide the player URL anymore. In consequence the regular expression that retrieves the player revision returns an None object and so it fails miserably when invoking its group() method.

Traceback (most recent call last):
  File "%USERPROFILE%\Documents\GitHub\crunchy-xml-decoder\crunchy-xml-decoder.py", line 352, in <module>
    ultimate.ultimate(page_url, seasonnum, epnum)
  File "crunchy-xml-decoder\ultimate.py", line 202, in ultimate
    player_revision = altfuncs.playerrev(page_url)
  File "crunchy-xml-decoder\altfuncs.py", line 46, in playerrev
    player_revision = re.search(revision_regex, gethtml(url)).group("revision")
AttributeError: 'NoneType' object has no attribute 'group'
alzamer2 commented 8 years ago

There is 2 option in setting 1 force proxy in usa 2 use localized setting based on the primary subtitle language

Did you try any of those?

Kamekameha commented 8 years ago

I get the error regardless of the settings of those two options, so yeah. This has more something to do with the region availability and, in fact, the problem is not that it isn't downloading, is that we should handle that error and raise whatever that fits.

For example, a quick workaround (change those in the relevant lines as you see fit):

def playerrev(url):
    global player_revision 

    revision_regex = r"swfobject.embedSWF\(\"(?:.+)'(?P<revision>[\d.]+)'(?:.+)\)"
    try:
        match = re.search(revision_regex, gethtml(url))
        player_revision = match.group("revision") if match is not None else sys.exit('Couldn\'t find player revision. Content might be region-blocked.')
    except IndexError:
        try:
            url += '?skip_wall=1'  # perv
            match = re.search(revision_regex, gethtml(url))
            player_revision = match.group("revision") if match is not None else sys.exit('Couldn\'t find player revision. Content might be region-blocked.')
        except IndexError:
            open('debug.html', 'w').write(html.encode('utf-8'))
            sys.exit('Sorry, but it looks like something went wrong with accessing the Crunchyroll page. Please make an issue on GitHub and attach debug.html which should be in the folder.')
    return player_revision

Note the changes on the match and player_revision variables.

Since we're talking about Crunchyroll's player, I also encountered that either we don't need the player at all or RTMPDump is just trolling us. When running each download I get the following:

Downloading video...
RTMPDump v2.5 GIT-2012-03-31 (Handshake 10 support by Xeebo)
(c) 2010 Andrej Stepanchuk, Howard Chu, The Flvstreamer Team; license: GPL
ERROR: RTMP_HashSWF: swfurl http://static.ak.crunchyroll.com/flash/9.0.115/ChromelessPlayerApp.swf not found
Connecting ...
WARNING: HandShake: Type mismatch: client sent 6, server answered 10
INFO: Connected...
Starting download at: 0.000 kB
INFO: Metadata:
INFO:   duration              1498.59
INFO:   moovPosition          32.00
INFO:   width                 1920.00
INFO:   height                1080.00
INFO:   videocodecid          avc1
INFO:   audiocodecid          mp4a
INFO:   avcprofile            100.00
INFO:   avclevel              40.00
INFO:   aacaot                2.00
INFO:   videoframerate        23.98
INFO:   audiosamplerate       44100.00
INFO:   audiochannels         2.00
INFO: trackinfo:
INFO:   length                17964000.00
INFO:   timescale             11988.00
INFO:   language              und
INFO: sampledescription:
INFO:   sampletype            avc1
INFO:   length                66087936.00
INFO:   timescale             44100.00
INFO:   language              und
INFO: sampledescription:
INFO:   sampletype            mp4a
14745.884 kB / 43.25 sec (2.8%)

More specifically, ERROR: RTMP_HashSWF: swfurl http://static.ak.crunchyroll.com/flash/9.0.115/ChromelessPlayerApp.swf not found. As you can see even when getting an error after not finding the player the content still downloads without any actual problem.

Kamekameha commented 8 years ago

A note, just checked and removed the player parameter in RTMPdump and it looks like it works seamlessly. I don't know if it was required before Crunchyroll made those few changes, but apparently we don't need to look up for the player revision and for the player itself anymore.