wouterdebie / locast2tuner

Locast to Emby/Plex/Channels server
https://wouterdebie.github.io/locast2tuner/
MIT License
52 stars 8 forks source link

How to handle valid Zip Code that becomes invalid to Locast.org? #62

Closed sumocomputers closed 3 years ago

sumocomputers commented 3 years ago

I had a situation where I had been using a valid Los Angeles Zip Code (90009), then at some point it seems Locast.org didn't see that as a valid Zip Code, returning this:

'204 No Content' for https://api.locastnet.org/api/watch/dma/zip/90009

So upon reboot of my machine, locast2tuner failed to start up correctly. I even have it running in a Docker container with --restart always so of course it just kept stopping and trying to restart.

I realize we can't control what Locast.org does, but one thing that could be cool is to have an option for "backup" Zip codes. Not the same as multiple zip codes multiplexed. But like pairs. So I could say use 90009 as my primary, but if locast2tuner fails for some reason, try again with my secondary or backup Zip of 90210, rather than bomb out. Just a thought.

I also wondered if you could point me in the right direction on how to be alerted that there is a problem, now that I am using Docker. I know in a previous thread some monitoring tools were mentioned, but was looking for the most simple way to alert me that Docker is having some sort of issue with the locast2tuner app or container.

Thanks,

Chris

wouterdebie commented 3 years ago

Interesting use case.. We could do the pairs, or provide an array of zip codes. However, a HTTP 204 doesn't necessarily mean that the zip code became invalid. Another way would be to define zip code ranges and trying to find a correct one.

sumocomputers commented 3 years ago

I guess “invalid” was a poor choice of words, but for whatever reason Locast.org returned something that caused locast2tuner to quit.

I like the Zip code range idea.

Not sure if Locast.org provides a list of cities and/or associated zip codes that is supports through their API, but that could also be a cool option: locast2tuner queries Locast.org periodically and for people who only care about a particular city/market, but don’t care about specific zip codes could let locast2tuner decide which zip to use. I know this complicates thing, but thought I would throw it out there.

Right now the way I make sure that my wife never misses Jeopardy?

I run multiple instances of locast2tuner with different zip codes in Docker containers, and then multiple instances of Plex pointing to the different containers. So far it has saved me a couple times, but is also a more complicated setup and a little more cumbersome to manage and update.

wouterdebie commented 3 years ago

When I started implementing, l looked for exactly that. Locast doesn't expose their zipcode mapping unfortunately. The best interface would really be to just tell locast2tuner for what city/dma you'd like to run it, but that doesn't seem possible right now..

wouterdebie commented 3 years ago

@sumocomputers just to be clear, did the error you posted show at runtime? Because this function should only be called ones at startup where locast2tuner maps a zipcode to geo coordinates.

sumocomputers commented 3 years ago

Yes I have observed this happening only at runtime, and when using a zip code like 90009, locast2tuner will exit/quit.

wouterdebie commented 3 years ago

do you happen to have the log?

sumocomputers commented 3 years ago

Sure, it is easy to reproduce. I ran this with verbose = 3 Let me know if I need to do something to get more detailed logs.

Jun 11 12:11:02.942 INFO locast2tuner 0.1.42 on Darwin 20.5.0 starting..
Jun 11 12:11:02.943 INFO UUID: redacted
Jun 11 12:11:02.943 INFO Logging in with redacted
Jun 11 12:11:02.946 DEBG starting new connection: https://api.locastnet.org/
Jun 11 12:11:02.978 TRCE registering event source with poller: token=Token(1), interests=READABLE | WRITABLE
Jun 11 12:11:03.413 TRCE signal: Want
Jun 11 12:11:03.413 TRCE signal found waiting giver, notifying
Jun 11 12:11:03.413 TRCE poll_want: taker wants!
Jun 11 12:11:03.550 TRCE signal: Want
Jun 11 12:11:03.550 TRCE signal: Want
Jun 11 12:11:03.550 DEBG response '200 OK' for https://api.locastnet.org/api/user/login
Jun 11 12:11:03.550 INFO Login succeeded!
Jun 11 12:11:03.550 DEBG starting new connection: https://api.locastnet.org/
Jun 11 12:11:03.550 TRCE deregistering event source from poller
Jun 11 12:11:03.551 TRCE signal: Closed
Jun 11 12:11:03.552 TRCE registering event source with poller: token=Token(redacted), interests=READABLE | WRITABLE
Jun 11 12:11:03.949 TRCE signal: Want
Jun 11 12:11:03.949 TRCE signal found waiting giver, notifying
Jun 11 12:11:03.949 TRCE poll_want: taker wants!
Jun 11 12:11:04.062 TRCE signal: Want
Jun 11 12:11:04.062 TRCE signal: Want
Jun 11 12:11:04.062 DEBG response '200 OK' for https://api.locastnet.org/api/user/me
Jun 11 12:11:04.063 DEBG starting new connection: https://api.locastnet.org/
Jun 11 12:11:04.063 TRCE deregistering event source from poller
Jun 11 12:11:04.063 TRCE signal: Closed
Jun 11 12:11:04.064 TRCE registering event source with poller: token=Token(redacted), interests=READABLE | WRITABLE
Jun 11 12:11:04.478 TRCE signal: Want
Jun 11 12:11:04.478 TRCE signal found waiting giver, notifying
Jun 11 12:11:04.478 TRCE poll_want: taker wants!
Jun 11 12:11:04.573 DEBG response '200 OK' for https://api.locastnet.org/api/dma
Jun 11 12:11:04.573 TRCE signal: Want
Jun 11 12:11:04.573 TRCE signal found waiting giver, notifying
Jun 11 12:11:04.573 TRCE signal: Want
Jun 11 12:11:04.573 TRCE poll_want: taker wants!
Jun 11 12:11:04.573 TRCE deregistering event source from poller
Jun 11 12:11:04.573 TRCE signal: Closed
Jun 11 12:11:04.573 INFO Using cached FCC facilities at /Users/mediamacmini/.locast2tuner/facilities
Jun 11 12:11:04.583 DEBG starting new connection: https://api.locastnet.org/
Jun 11 12:11:04.584 TRCE registering event source with poller: token=Token(redacted), interests=READABLE | WRITABLE
Jun 11 12:11:05.025 TRCE signal: Want
Jun 11 12:11:05.025 TRCE signal found waiting giver, notifying
Jun 11 12:11:05.025 TRCE poll_want: taker wants!
Jun 11 12:11:05.131 TRCE signal: Want
Jun 11 12:11:05.131 thread 'mainTRCE' panicked at 'called `Result::unwrap()` on an `Err` value: reqwest::Error { kind: Decode, source: Error("EOF while parsing a value", line: 1, column: 0) } ', signal: Wantsrc/service/mod.rs:
362:10
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Jun 11 12:11:05.131 DEBG response '204 No Content' for https://api.locastnet.org/api/watch/dma/zip/90009
Abort trap: 6
wouterdebie commented 3 years ago

Thanks for this! I was wondering what the behavior was when locast invalidated the zip code. Did it stop streaming?

On Fri, Jun 11, 2021, 14:14 sumocomputers @.***> wrote:

Sure, it is easy to reproduce. I ran this with verbose = 3 Let me know if I need to do something to get more detailed logs.

Jun 11 12:11:02.942 INFO locast2tuner 0.1.42 on Darwin 20.5.0 starting.. Jun 11 12:11:02.943 INFO UUID: redacted Jun 11 12:11:02.943 INFO Logging in with redacted Jun 11 12:11:02.946 DEBG starting new connection: https://api.locastnet.org/ Jun 11 12:11:02.978 TRCE registering event source with poller: token=Token(1), interests=READABLE | WRITABLE Jun 11 12:11:03.413 TRCE signal: Want Jun 11 12:11:03.413 TRCE signal found waiting giver, notifying Jun 11 12:11:03.413 TRCE poll_want: taker wants! Jun 11 12:11:03.550 TRCE signal: Want Jun 11 12:11:03.550 TRCE signal: Want Jun 11 12:11:03.550 DEBG response '200 OK' for https://api.locastnet.org/api/user/login Jun 11 12:11:03.550 INFO Login succeeded! Jun 11 12:11:03.550 DEBG starting new connection: https://api.locastnet.org/ Jun 11 12:11:03.550 TRCE deregistering event source from poller Jun 11 12:11:03.551 TRCE signal: Closed Jun 11 12:11:03.552 TRCE registering event source with poller: token=Token(redacted), interests=READABLE | WRITABLE Jun 11 12:11:03.949 TRCE signal: Want Jun 11 12:11:03.949 TRCE signal found waiting giver, notifying Jun 11 12:11:03.949 TRCE poll_want: taker wants! Jun 11 12:11:04.062 TRCE signal: Want Jun 11 12:11:04.062 TRCE signal: Want Jun 11 12:11:04.062 DEBG response '200 OK' for https://api.locastnet.org/api/user/me Jun 11 12:11:04.063 DEBG starting new connection: https://api.locastnet.org/ Jun 11 12:11:04.063 TRCE deregistering event source from poller Jun 11 12:11:04.063 TRCE signal: Closed Jun 11 12:11:04.064 TRCE registering event source with poller: token=Token(redacted), interests=READABLE | WRITABLE Jun 11 12:11:04.478 TRCE signal: Want Jun 11 12:11:04.478 TRCE signal found waiting giver, notifying Jun 11 12:11:04.478 TRCE poll_want: taker wants! Jun 11 12:11:04.573 DEBG response '200 OK' for https://api.locastnet.org/api/dma Jun 11 12:11:04.573 TRCE signal: Want Jun 11 12:11:04.573 TRCE signal found waiting giver, notifying Jun 11 12:11:04.573 TRCE signal: Want Jun 11 12:11:04.573 TRCE poll_want: taker wants! Jun 11 12:11:04.573 TRCE deregistering event source from poller Jun 11 12:11:04.573 TRCE signal: Closed Jun 11 12:11:04.573 INFO Using cached FCC facilities at /Users/mediamacmini/.locast2tuner/facilities Jun 11 12:11:04.583 DEBG starting new connection: https://api.locastnet.org/ Jun 11 12:11:04.584 TRCE registering event source with poller: token=Token(redacted), interests=READABLE | WRITABLE Jun 11 12:11:05.025 TRCE signal: Want Jun 11 12:11:05.025 TRCE signal found waiting giver, notifying Jun 11 12:11:05.025 TRCE poll_want: taker wants! Jun 11 12:11:05.131 TRCE signal: Want Jun 11 12:11:05.131 thread 'mainTRCE' panicked at 'called Result::unwrap() on an Err value: reqwest::Error { kind: Decode, source: Error("EOF while parsing a value", line: 1, column: 0) } ', signal: Wantsrc/service/mod.rs: 362:10 note: run with RUST_BACKTRACE=1 environment variable to display a backtrace Jun 11 12:11:05.131 DEBG response '204 No Content' for https://api.locastnet.org/api/watch/dma/zip/90009 Abort trap: 6

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/wouterdebie/locast2tuner/issues/62#issuecomment-859787478, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABKABQSNL4FAK2QLN34ITTTSJOAJANCNFSM46POYPRQ .

sumocomputers commented 3 years ago

All I know I had to reboot my Mac mini, and it didn’t record anything that night.

So after digging in, I found it was the zip code issue.

So not sure what happens on the client side, like Plex.

okc commented 3 years ago

90009 is a Post Office at Los Angeles International Airport. It appears to be only valid for PO Boxes. So it doesn't have a geographic delivery area. Not sure how Locast uses ZIP codes but just pick another. HTTP 204 is No Data - valid but nothing returned.

wouterdebie commented 3 years ago

I tend to use 90210 for LA :)

sumocomputers commented 3 years ago

90009 is a Post Office at Los Angeles International Airport. It appears to be only valid for PO Boxes. So it doesn't have a geographic delivery area. Not sure how Locast uses ZIP codes but just pick another. HTTP 204 is No Data - valid but nothing returned.

My point was that 90009 was a working zip code at one point (as far as Locast was concerned), but then that changed, and that caused locast2tuner to quit. There is no reason why Locast might return a 204 for another zip code in the future, and @wouterdebie has already marked this issue for "enhancement".

For now I have backups in the form of multiple Docker containers running 3 different zip codes, as well as 2 Plex instances, so now the chances of missing Jeopardy are greatly reduced...

extrapc commented 3 years ago

Was wondering if you could have an option for the DMA #'s instead of zipcode since those don't change?

wouterdebie commented 3 years ago

Unfortunately it's not an option, since eventually you need to supply the latitude and longitude of your location to locast, which in turn we get from a zip code. There's nothing that returns a lat/long from a dma.

On Wed, Aug 4, 2021, 21:17 extrapc @.***> wrote:

Was wondering if you could have an option for the DMA #'s instead of zipcode since those don't change?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/wouterdebie/locast2tuner/issues/62#issuecomment-893110591, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABKABQ5MOC3CLLK6T4SOQDT3HYB7ANCNFSM46POYPRQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email .

wouterdebie commented 3 years ago

Alright, I think I've fixed this issue in 0.3.0. I've added override_cities, which takes a list of cities. What it does is that it uses https://github.com/wouterdebie/zip_codes_plus to get a list of "standard" zip codes (no PO box, etc) for a city and then picks the first valid one (where the locast response isn't a 204 as in the first post of this thread and the zip code is active).

I've also added random_zipcode so locast2tuner will pick a random valid zip code from the list.

Please give this a try and see what you think!