Can anyone point me in the right direction? AttributeError: 'NoneType' object has no attribute

plugin-dev

#1

I have some basic code that is not working and getting the following error:

AttributeError: 'NoneType' object has no attribute 'group'

I looked at the logs and this is what I'm getting:

2017-09-01 08:09:48,361 (1ae0) : DEBUG (runtime:88) - Sending packed state data (1090 bytes)
2017-09-01 08:09:48,361 (1ae0) : DEBUG (runtime:924) - Response: [500] 662 bytes
2017-09-01 08:09:59,963 (232c) : DEBUG (runtime:717) - Handling request GET /video/sportsarefree/createvideoclipobject?thumb=http%3A%2F%2Fi.imgur.com%2FagxSEPd.png&include_container=1&title=hbo2
2017-09-01 08:09:59,966 (232c) : DEBUG (runtime:49) - Received packed state data (1056 bytes)
2017-09-01 08:09:59,967 (232c) : DEBUG (runtime:814) - Found route matching /video/sportsarefree/createvideoclipobject
2017-09-01 08:09:59,973 (232c) : DEBUG (runtime:88) - Sending packed state data (1090 bytes)
2017-09-01 08:09:59,973 (232c) : DEBUG (runtime:924) - Response: [200] MediaContainer, 1575 bytes
2017-09-01 08:09:59,984 (14e8) : DEBUG (runtime:717) - Handling request GET /video/sportsarefree/createvideoclipobject?thumb=http%3A%2F%2Fi.imgur.com%2FcieuPb6.png&include_container=1&title=hbo
2017-09-01 08:09:59,986 (14e8) : DEBUG (runtime:49) - Received packed state data (1056 bytes)
2017-09-01 08:09:59,986 (14e8) : DEBUG (runtime:814) - Found route matching /video/sportsarefree/createvideoclipobject
2017-09-01 08:09:59,990 (14e8) : DEBUG (runtime:88) - Sending packed state data (1090 bytes)
2017-09-01 08:09:59,990 (14e8) : DEBUG (runtime:924) - Response: [200] MediaContainer, 1571 bytes
2017-09-01 08:10:01,005 (2668) : DEBUG (runtime:717) - Handling request GET /video/sportsarefree/createvideoclipobject?thumb=http%3A%2F%2Fi.imgur.com%2FcieuPb6.png&include_container=1&title=hbo
2017-09-01 08:10:01,009 (2668) : DEBUG (runtime:814) - Found route matching /video/sportsarefree/createvideoclipobject
2017-09-01 08:10:01,010 (19e0) : DEBUG (runtime:717) - Handling request GET /video/sportsarefree/createvideoclipobject?thumb=http%3A%2F%2Fi.imgur.com%2FcieuPb6.png&include_container=1&title=hbo
2017-09-01 08:10:01,016 (19e0) : DEBUG (runtime:49) - Received packed state data (1056 bytes)
2017-09-01 08:10:01,016 (2240) : DEBUG (runtime:717) - Handling request GET /video/sportsarefree/createvideoclipobject?thumb=http%3A%2F%2Fi.imgur.com%2FcieuPb6.png&include_container=1&title=hbo&includeBandwidths=1
2017-09-01 08:10:01,023 (19e0) : DEBUG (runtime:814) - Found route matching /video/sportsarefree/createvideoclipobject
2017-09-01 08:10:01,025 (2240) : DEBUG (runtime:814) - Found route matching /video/sportsarefree/createvideoclipobject
2017-09-01 08:10:01,028 (2668) : DEBUG (runtime:88) - Sending packed state data (114 bytes)
2017-09-01 08:10:01,030 (2668) : DEBUG (runtime:924) - Response: [200] MediaContainer, 1571 bytes
2017-09-01 08:10:01,040 (2240) : DEBUG (runtime:88) - Sending packed state data (114 bytes)
2017-09-01 08:10:01,042 (2240) : DEBUG (runtime:924) - Response: [200] MediaContainer, 1571 bytes
2017-09-01 08:10:01,042 (19e0) : DEBUG (runtime:88) - Sending packed state data (1090 bytes)
2017-09-01 08:10:01,043 (19e0) : DEBUG (runtime:924) - Response: [200] MediaContainer, 1571 bytes
2017-09-01 08:10:01,049 (1ae4) : DEBUG (runtime:717) - Handling request GET /video/sportsarefree/playvideo.m3u8?id=hbo&indirect=1&mediaInfo=%7B%22audio_channels%22%3A%202%2C%20%22protocol%22%3A%20%22hls%22%2C%20%22optimized_for_streaming%22%3A%20true%2C%20%22video_frame_rate%22%3A%20null%2C%20%22duration%22%3A%20null%2C%20%22height%22%3A%20720%2C%20%22width%22%3A%201280%2C%20%22container%22%3A%20%22mpegts%22%2C%20%22audio_codec%22%3A%20%22aac%22%2C%20%22aspect_ratio%22%3A%20null%2C%20%22video_codec%22%3A%20%22h264%22%2C%20%22video_resolution%22%3A%20%22720%22%2C%20%22bitrate%22%3A%20null%7D
2017-09-01 08:10:01,052 (1ae4) : DEBUG (runtime:814) - Found route matching /video/sportsarefree/playvideo.m3u8
2017-09-01 08:10:01,108 (1ae4) : DEBUG (networking:166) - Requesting 'http://sportsarefree.xyz/hbo'
2017-09-01 08:10:01,581 (1ae4) : CRITICAL (core:574) - Exception (most recent call last):
File "C:\Program Files (x86)\Plex\Plex Media Server\Resources\Plug-ins-b1d4aa012\Framework.bundle\Contents\Resources\Versions\2\Python\Framework\components\runtime.py", line 843, in handle_request
result = f(**d)
File "C:\Users\me\AppData\Local\Plex Media Server\Plug-ins\sportsarefree.bundle\Contents\Code_init_.py", line 155, in PlayVideo
source = RE_SOURCE.search(page).group(1)
AttributeError: 'NoneType' object has no attribute 'group'

The source code can be found here:

github.com/piplongrun/sportsarefree.bundle


#2

@BDuhbz

The message means you're trying to access a method or property that does not exist. It says attribute 'group', which you can spot in your code, source = RE_SOURCE.search(page).group(1), meaning there's no method named 'group' in the return value from RE_SOURCE.search(page) and 'NoneType' is a type of that return value. Apparently, the value of page variable doesn't match the pattern in RE_SOURCE so it returns nil. If this code used to work before, then there's a chance that there has been some change to the web page and the content cannot be parsed properly anymore.


#3

thank you.

I got that I'm just trying to find out how I can get the new attributes from the site so that this code can work again.


#4

Let's see what can we find on the page URL from your log file. The failing regular expression is 'source: prefix\+"([^"]+)"' and I'll try to find something similar there:

    player = new Clappr.Player({
        source: prefix+qqnn,
        ...

So it seems like where there used to be a literal value, there is a variable now and it's being set in a series of badly readable JavaScript code above (not copying the code here because it's very long). The guys have obviously been trying hard to prevent people from watching content from their website without the use of a browser. So unfortunately, it won't suffice to just fix the regex. It may be possible to spend some time at decoding their JavaScript and figuring out how to bypass it, but they may do a few more subtle changes in time and it'll stop working again, so it may be easier just to execute the JavaScript code from Python so that the obfuscated parts sort themselves out and you just get the clean URL in the end. But it is not a simple drop-in edit in the channel code. If you're not the author, try opening an issue at Github, the channel's been last updated just a week ago and chances are the author will fix it.

Some example code from a different channel running portion of JavaScript from the web page can be found here.


#5

Thank you for clearing that up. The web page has definitely changed but should be static moving forward. I'm trying to teach myself how to do this so I'm a bit of a newb.


#6

No problem. To be honest, I wouldn't consider a site where you have deal with JavaScript in order to get media URL (let alone obfuscated one like in this case) a good example for beginners, but it's still not too hard. If you run into troubles, just post here and I or somebody else will try to help.