Skip to content

Commit

Permalink
Merge pull request #27 from erdnaxeli/fixes/dns
Browse files Browse the repository at this point in the history
fix(sponsorblock): Catch DNS issue
  • Loading branch information
erdnaxeli authored Oct 1, 2021
2 parents 755d940 + 2f4072c commit 243e756
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# v0

## v0.1.1

* do not crash on issue with DNS [#20](https://github.com/erdnaxeli/castblock/issues/20)

## v0.1.0

Initial version, the changelog was not maintained yet :)
4 changes: 2 additions & 2 deletions shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: castblock
version: 0.1.0
version: 0.1.1

authors:
- Alexandre Morignot <[email protected]>
Expand All @@ -17,6 +17,6 @@ development_dependencies:
ameba:
github: crystal-ameba/ameba

crystal: 1.0.0
crystal: ">= 1.0.0, < 1.2"

license: MIT
7 changes: 6 additions & 1 deletion src/blocker.cr
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ class Castblock::Blocker
private def handle_media(device : Chromecast::Device, media : Chromecast::Media) : Nil
Log.debug &.emit("Youtube video playing", id: media.media.content_id, current_time: media.current_time)

segments = @sponsorblock.get_segments(media.media.content_id)
begin
segments = @sponsorblock.get_segments(media.media.content_id)
rescue Sponsorblock::Error
return
end

if segments.nil?
Log.debug &.emit("Unknown video", id: media.media.content_id)
return
Expand Down
12 changes: 10 additions & 2 deletions src/sponsorblock.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ require "http"
require "uri"

class Castblock::Sponsorblock
class CategoryError < Exception
class Error < Exception
end

class CategoryError < Error
end

Log = Castblock::Log.for(self)
Expand Down Expand Up @@ -61,7 +64,12 @@ class Castblock::Sponsorblock
end

private def get(path : String, retries = 3) : HTTP::Client::Response
response = @client.get(path)
begin
response = @client.get(path)
rescue ex : Socket::Addrinfo::Error
Log.warn &.emit("DNS error", error: ex.to_s)
raise Error.new(cause: ex)
end

if response.status.server_error?
3.times do
Expand Down

0 comments on commit 243e756

Please sign in to comment.