Skip to content

Instantly share code, notes, and snippets.

@shuaiscott
Last active December 29, 2015 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shuaiscott/d60ece82868dce31d10b to your computer and use it in GitHub Desktop.
Save shuaiscott/d60ece82868dce31d10b to your computer and use it in GitHub Desktop.
Dashing Sonarr Upcoming Episodes Widget

Install with: dashing install d60ece82868dce31d10b

Put this in your dashboard.erb

<li data-row="1" data-col="1" data-sizex="2" data-sizey="1">
  <div data-id="sonarr" data-view="Sonarr" data-title="Upcoming Episodes"></div>
</li>

Change the following Sonarr information inside sonarr.rb:

  • API Key
  • Hostname
  • Port
  • Extra Sonarr Path
class Dashing.Sonarr extends Dashing.Widget
<h1 class="title" data-bind="title"></h1>
<ul>
<li data-foreach-show="shows">
<span class="show-line">
<span class="show-title" data-bind="show.show"></span>
<span class="episode" data-bind="show.title"></span>
</span>
<span class="date" data-bind="show.date"></span>
<span class="number" data-bind="show.number"></span>
</li>
</ul>
<p class="updated-at" data-bind="updatedAtMessage"></p>
require 'net/http'
require 'json'
require 'date'
require 'time'
# Fill your sonarr info here
apikey = 'SONARR_API_KEY'
hostname = 'SONARR_HOSTNAME'
port = 'SONARR_PORT'
extra_path = '/'
# Set the number of episodes displayed
limit = 7
SCHEDULER.every '6h', :first_in => 0 do |job|
searchStart = Date.today.to_time.utc.iso8601
searchEnd = (Date.today.to_time.utc+(30*24*60*60)).iso8601
http = Net::HTTP.new('#{hostname}',port)
response = http.request(Net::HTTP::Get.new("#{extra_path}api/calendar?apikey=#{apikey}&start=#{searchStart}&end=#{searchEnd}"))
episodes = JSON.parse(response.body)
shows = []
if episodes
episodes.each do|tmpEpisode|
episode = Hash.new
seasonNum = ""
episodeNum = ""
episode["show"] = tmpEpisode["series"]["title"]
episode["title"] = tmpEpisode["title"]
airDate = Time.parse(tmpEpisode["airDate"])
episode["date"] = airDate.strftime("%m/%d")
if tmpEpisode["seasonNumber"].to_s.length > 1
seasonNum = tmpEpisode["seasonNumber"].to_s
else
seasonNum = "0"+tmpEpisode["seasonNumber"].to_s
end
if tmpEpisode["episodeNumber"].to_s.length > 1
episodeNum = tmpEpisode["episodeNumber"].to_s
else
episodeNum = "0"+tmpEpisode["episodeNumber"].to_s
end
episode["number"] = ['S', seasonNum, 'E', episodeNum].join()
shows<<episode
end
end
send_event('sonarr', { shows: shows.take(limit) })
end
// ----------------------------------------------------------------------------
// Sass declarations
// ----------------------------------------------------------------------------
$background-color: #3b8dd0;
$title-color: rgba(255, 255, 255, 0.7);
$title-show-color: rgba(255, 255, 255, 1);
$title-episode-color: rgba(255, 255, 255, 0.8);;
$episode-color: rgba(255, 255, 255, 0.7);
// ----------------------------------------------------------------------------
// Widget-betaseries styles
// ----------------------------------------------------------------------------
.widget-sonarr {
background-color: $background-color;
vertical-align: top;
.title {
color: $title-color;
}
ul {
margin: 0 15px;
text-align: left;
color: $title-show-color;
}
.show-line {
display: inline-block;
width: 400px;
overflow: hidden;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.title-show {
color: $title-show-color;
}
.episode {
&:before{
content: " - ";
}
font-size: 0.7em;
color: $title-episode-color;
}
.number, .date {
float: right;
margin-left: 12px;
font-weight: 600;
color: $episode-color;
}
.date {
box-sizing: border-box;
color: #FFF;
font-size: 0.8em;
border: 2px #FFF solid;
border-radius: 20px;
padding: 0 .5em;
}
.updated-at {
color: rgba(0, 0, 0, 0.3);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment