diff options
| author | Omar Roth <omarroth@hotmail.com> | 2018-03-14 18:06:21 -0500 |
|---|---|---|
| committer | Omar Roth <omarroth@hotmail.com> | 2018-03-14 18:06:21 -0500 |
| commit | e8013c6d5cacc2e57e37bf4692d6a3e1f5526eb8 (patch) | |
| tree | 6a7482858b5483d7816783ad08598d223050d637 | |
| parent | c8a798e13c65f9740d9473207c9edbba1b0afe3a (diff) | |
| download | invidious-e8013c6d5cacc2e57e37bf4692d6a3e1f5526eb8.tar.gz invidious-e8013c6d5cacc2e57e37bf4692d6a3e1f5526eb8.tar.bz2 invidious-e8013c6d5cacc2e57e37bf4692d6a3e1f5526eb8.zip | |
Use try instead of ternary
| -rw-r--r-- | src/helpers.cr | 6 | ||||
| -rw-r--r-- | src/invidious.cr | 7 |
2 files changed, 8 insertions, 5 deletions
diff --git a/src/helpers.cr b/src/helpers.cr index 1bd74147..fa4e6449 100644 --- a/src/helpers.cr +++ b/src/helpers.cr @@ -131,10 +131,12 @@ def fetch_video(id, client) views = info["view_count"].to_i64 likes = html.xpath_node(%q(//button[@title="I like this"]/span)) - likes = likes ? likes.content.delete(",").to_i : 0 + likes = likes.try &.content.delete(",").try &.to_i + likes ||= 0 dislikes = html.xpath_node(%q(//button[@title="I dislike this"]/span)) - dislikes = dislikes ? dislikes.content.delete(",").to_i : 0 + dislikes = dislikes.try &.content.delete(",").try &.to_i + dislikes ||= 0 description = html.xpath_node(%q(//p[@id="eow-description"])) description = description ? description.to_xml : "" diff --git a/src/invidious.cr b/src/invidious.cr index 2a1df33b..8549cd45 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -187,8 +187,8 @@ get "/watch" do |env| fmt_stream = [] of HTTP::Params video.info["url_encoded_fmt_stream_map"].split(",") do |string| if !string.empty? - fmt_stream << HTTP::Params.parse(string) - end + fmt_stream << HTTP::Params.parse(string) + end end adaptive_fmts = [] of HTTP::Params @@ -271,7 +271,8 @@ get "/search" do |env| next end - page = env.params.query["page"]? && env.params.query["page"].to_i? ? env.params.query["page"].to_i : 1 + page = env.params.query["page"]?.try &.to_i + page ||= 1 client = get_client(youtube_pool) |
