tgorgdotcom / locast2plex

A very simple script to connect locast to Plex's live tv/dvr feature.
MIT License
234 stars 43 forks source link

locast2plex fails to start, generates error 'KeyError: '533' #20

Closed CTJohnK closed 4 years ago

CTJohnK commented 4 years ago

After the storms that rolled through our area (I'm in Connecticut) and our internet service has been restored, I noticed no new recordings have been captured these last couple of days. Digging in a bit and if I understand the error message, Locast is returning '533' as my DMA. When I log manually into their web site, it shows New York as my location which is normal.

Looking through some of the files provided, I see New York associated with code '501', but when I try updating all the '501' entries I can find with '533', the system never completes the start up process and simply hangs. Below are the messages with the original 0.4.2 files re-installed.

Do you have any suggestions?

c:\Python27>python main.py -u:xxx@gmail.com -p:yyy --debug --addy:127.0.0.1 --external_addy:192.168.100.100 Locast2Plex v0.4.2 DEBUG MODE ACTIVE UUID found. UUID set to: xxxxxxx... Logging into Locast using username xxx@gmail.com... Validating User Info... User Info obtained. User didDonate: True User donationExpire: 1597785373 Getting user location... User location obtained as 41.4824/-73.2231 Getting user's media market (DMA)... DMA found as 533 Getting list of stations based on DMA... Loading FCC Stations list... Traceback (most recent call last): File "main.py", line 324, in station_list = locast.get_stations() File "c:\Python27\LocastService.py", line 195, in get_stations fcc_market = dma_mapping[str(self.current_dma)] KeyError: '533'

CTJohnK commented 4 years ago

This looks like a similar issue to #13 "Will Not Start".

CTJohnK commented 4 years ago

I did a bit more digging and rather than changing the '501' to '533' in the .json files, I set "current_dma" in LocastService.py to equal 501 instead of 'None'. The script is running and currently Plex is refreshing the guide data. Hopefully that will solve the issue for now. I'll advise if everything is working after the refresh completes.

CTJohnK commented 4 years ago

That didn't work. When I try to watch a show I receive a playback error indicating "Could not tune channel. Please check your tuner or antenna."

alexmarsaudon commented 4 years ago

I have a similar issue (different KeyError): docker run -d --name=locast2plex -e username=CENSORED -e 'password=CENSORED' -e external_addy=10.10.150.50 -p 6077:6077 --restart unless-stopped tgorg/locast2plex Locast2Plex v0.4.2 Traceback (most recent call last): File "/app/main.py", line 324, in station_list = locast.get_stations() DEBUG MODE ACTIVE UUID found. UUID set to: lrtrvhsi... Logging into Locast using username [censored]... Validating User Info... User Info obtained. User didDonate: True User donationExpire: 1602950280 Getting user location... User location obtained as 37.751/-97.822 Getting user's media market (DMA)... DMA found as 678 Getting list of stations based on DMA... Loading FCC Stations list... File "/app/LocastService.py", line 195, in get_stations fcc_market = dma_mapping[str(self.current_dma)] KeyError: '678'

CTJohnK commented 4 years ago

I should have also listed the error received when trying to force the DMA and then watch a show (from the Raspberry Pi) -

Exception happened during processing of request from ('127.0.0.1', 44892) Traceback (most recent call last): File "/usr/lib/python2.7/SocketServer.py", line 293, in _handle_request_noblock self.process_request(request, client_address) File "/usr/lib/python2.7/SocketServer.py", line 321, in process_request self.finish_request(request, client_address) File "/usr/lib/python2.7/SocketServer.py", line 334, in finish_request self.RequestHandlerClass(request, client_address, self) File "/usr/lib/python2.7/SocketServer.py", line 655, in init self.handle() File "/usr/lib/python2.7/BaseHTTPServer.py", line 340, in handle self.handle_one_request() File "/usr/lib/python2.7/BaseHTTPServer.py", line 328, in handle_one_request method() File "/home/pi/locast2plex/main.py", line 85, in do_GET channelUri = self.local_locast.get_station_stream_uri(channelId) File "/home/pi/locast2plex/LocastService.py", line 407, in get_station_stream_uri print("Error when getting the video URL: " + videoUrlReqErr.message) TypeError: cannot concatenate 'str' and 'getset_descriptor' objects

tgorgdotcom commented 4 years ago

@CTJohnK I was looking into a few different issues related to this. It looks like my script identifies your location as in Connecticut correctly, and gets the DMA code for that market (533), even when it's not available for Locast currently. Changing the 501 to 533 would prevent a "KeyError", like you mentioned, but it probably won't return any channels, because there aren't any. I'm working on updating the code to better explain potential pitfalls in the future.

@alexmarsaudon Similar to CTJohnK's issue above, locast2plex detects your location to be a place that does not have Locast support currently.

CTJohnK commented 4 years ago

@tgorgdotcom Thank you for looking into this. As i noted, forcing current_dma to 501 does allows the script to load and I was able to reload the Guide (which displayed correctly), but unfortunately playback does not work.

If there is anything I can do to assist, please let me know.

Recap:

CTJohnK commented 4 years ago

@tgorgdotcom Had some time this evening so I did a bit more digging, not sure if any of this helps.

Looking in "api_information.txt" and running a couple of them I see: Using DMA by lat/long API: -- Using lat/long which Locast reports - https://api.locastnet.org/api/watch/dma/41.4824/-73.2231 returns DMA 533, New Haven -- Using Google maps lat/long for my town - https://api.locastnet.org/api/watch/dma/41.470340/-73.390683 returns 501, New York

Using station listing API: -- https://api.locastnet.org/api/watch/epg/533 returns [] -- https://api.locastnet.org/api/watch/epg/501 returns station listings [{"id":104,"dma":501,"stationId":"16689","name":"WCBSDT","callSign":"2.1 CBS","logoUrl":"https://static.locastnet.org/logo/NewYork/WCBS.png",.....]

Please note the station id of "104" which is CBS out of New York. When I use "current_dma = 501" in LocastService.py and try to watch CBS, The following error is throw -

127.0.0.1 - - [18/Aug/2020 20:29:47] "GET /lineup.json HTTP/1.0" 200 - 127.0.0.1 - - [18/Aug/2020 20:29:47] "GET /discover.json HTTP/1.0" 200 - 127.0.0.1 - - [18/Aug/2020 20:29:47] "GET /lineup_status.json HTTP/1.0" 200 - Getting station info for 104...

Exception happened during processing of request from ('127.0.0.1', 35940) Traceback (most recent call last): File "/usr/lib/python2.7/SocketServer.py", line 293, in _handle_request_noblock self.process_request(request, client_address) File "/usr/lib/python2.7/SocketServer.py", line 321, in process_request self.finish_request(request, client_address) File "/usr/lib/python2.7/SocketServer.py", line 334, in finish_request self.RequestHandlerClass(request, client_address, self) File "/usr/lib/python2.7/SocketServer.py", line 655, in init self.handle() File "/usr/lib/python2.7/BaseHTTPServer.py", line 340, in handle self.handle_one_request() File "/usr/lib/python2.7/BaseHTTPServer.py", line 328, in handle_one_request method() File "/home/pi/locast2plex/main.py", line 85, in do_GET channelUri = self.local_locast.get_station_stream_uri(channelId) File "/home/pi/locast2plex/LocastService.py", line 406, in get_station_stream_uri print("Error when getting the video URL: " + videoUrlReqErr.message) TypeError: cannot concatenate 'str' and 'getset_descriptor' objects

Looking at the script, that error is coming from 'get_station_stream_uri' which includes lat/long so I changed 'current_location = None' to 'current_location = 41.470340/-73.390683' to match my town to the 501 DMA noted earlier. Unfortunately, I receive the same error.

Based on seeing "TypeError: cannot concatenate 'str' and 'getset_descriptor' objects", it looks like the URL for 'get_station_stream_uri' is not being created properly, perhaps?

Again, hopefully this is helpful and let me know if there is anything I can do to help.

tgorgdotcom commented 4 years ago

Hmmm, I'm thinking it's my geoip service that I'm using. I'm going to check what Locast does to geolocate and maybe I can start using that instead. I'll keep you posted

CTJohnK commented 4 years ago

If I execute https://get.geojs.io/v1/ip/geo.json, it returns the following - {"organization_name":"CHARTER-20115","region":"Connecticut","accuracy":10,"asn":20115,"organization":"AS20115 CHARTER-20115","timezone":"America\/New_York","longitude":"-73.2231","country_code3":"USA","area_code":"0","ip":"75.xxx.xx.x","city":"Southbury","country":"United States","continent_code":"NA","country_code":"US","latitude":"41.4824"}

Which is correct to indicate I'm using Charter (Spectrum) and the service is coming out of Southbury, CT.

However, wouldn't setting 'current_location = 41.470340/-73.390683' bypass 'self.current_location' code?

tgorgdotcom commented 4 years ago

Yep, you're right, but it needs to be in Python's dict format. What might be easier is if you check lines 310-314 in main.py. Comment out 310, uncomment 311-314, and put in your coordinates.

I think I need to definitely rethink the whole geolocation thing. It was designed to prevent users from overriding their location (and to prevent any more legal issues for Locast -- as it could draw the ire of sports teams that have specific contracts for showing their games out of their local region). Not only is the geolocation service returning incorrect locations for some users, but the service seems unaccessible from the script for some users.

CTJohnK commented 4 years ago

@tgorgdotcom That seems to have done the trick. I did leave 'current_location' and 'current-dma' set in LocastService.py to my lat/long and dma respectively.

I was able to watch a few minutes of live streaming and have setup a recording for later this evening. I'll let you know how that worked out.

Thank you for your help!

As for the geolocation issue. When I first signed up for Locast, I kept getting an error indicating I had selected the wrong market (this was with my previous internet provider). After several emails with Locast, I was able to connect without issue. I presumed they had tied a lat/long to my account to override whatever was being sent back; I guess that was an incorrect presumption.

In any event, I have not had any issue with the geolocation not being available or returning data, just a questionable value returned. As a note, I'm running the script on a RaspberryPi and not using a Docker container.

Again, glad to help in any way I can.

tgorgdotcom commented 4 years ago

Ah, interesting! Thanks for pointing that out. I'll check if my account returns a lat/long as well. Maybe going forward we can use that instead (or at least override my geo location is needed).

CTJohnK commented 4 years ago

The recording worked last night.

I reached out to Locast this morning (email conversation below), and it would appear they do not tie a lat/long to the user. In my earlier case, perhaps they did something to re-map my ISP/IP address to show it in the NY market.

me - Subject: Travel - "I'll be doing some travel to WA, MA and CA over the coming months (unfortunately) and was wondering if i can use Locast to view the local TV stations in those areas (if available) or is my account 'locked' into the New York market?"

Locast - "Thank you for reaching out to us. Yes you will be able to use locast where our market covers. You can check availability here https://www.locast.org/dma . Keep in mind that you will not be able to watch broadcasting outside of the area you are visiting,"

Interesting note, the locast link they provided in the email took about 30-seconds to respond and it showed my DMA as 501 and a lat/long which is a couple of miles from my home. I'm not sure how they are determining the geo data, but can you piggyback on that link to return the lat/long from within the Python code?

tgorgdotcom commented 4 years ago

@CTJohnK Ah, okay. Yeah it's tough because I think they tie into the browser's geolocation API, and I think that method is more accurate than relying on geoIP alone. I haven't found an easy solution to do a similar geolocation yet, but I have an idea on how to override location that we can try that doesn't involve modifying code, and hopefully I'll resolve it in a few days.

CTJohnK commented 4 years ago

@tgorgdotcom Okay. Let me know if there is anything you'd like tested, I have a 'test' setup on Windows so I can make changes without impacting my 'production'.

CTJohnK commented 4 years ago

@tgorgdotcom I think we can call this 'solved', so I'm closing.

Thank you for your help