Skip to content

Instantly share code, notes, and snippets.

@camillebaldock
Last active October 24, 2015 20:31
Show Gist options
  • Save camillebaldock/b3df4f58efe938d05912 to your computer and use it in GitHub Desktop.
Save camillebaldock/b3df4f58efe938d05912 to your computer and use it in GitHub Desktop.
Dashing Plex widgets from local scheduled job

Description

A Dashing widget for displaying the number of unplayed films, home videos and TV shows on a Plex media server.

See a live demo here.

Usage

Due to the fact that I didn't want to expose my Plex server to outside my network, I decided to run the script on a personal machine at home and push the data to my Dashing application.

Setup the following environment variables:

  • SERVER_HOST
  • AUTH_TOKEN: the auth token of your Dashing application

Dependencies

plex-ruby

Add it to your Dashing application's Gemfile:

gem 'plex-ruby'

and run bundle install.

require 'plex-ruby'
require 'json'
server = Plex::Server.new(ENV["SERVER_HOST"], 32400)
sections = server.library.sections
tv_shows_section = sections.find{|section| section.title == "TV Shows" }
tv_shows = tv_shows_section.all
unwatched_tv_shows = 0
tv_shows.each do |tv_show|
unwatched_tv_shows += tv_show.leaf_count.to_i - tv_show.viewed_leaf_count.to_i
end
films_section = sections.find{|section| section.title == "Movies" }
unwatched_films = films_section.unwatched.count
videos_section = sections.find{|section| section.title == "Home Videos" }
unwatched_videos = videos_section.unwatched.count
auth_token=ENV["AUTH_TOKEN"]
json_headers = {"Content-Type" => "application/json",
"Accept" => "application/json"}
p "#{unwatched_tv_shows} TV shows"
p "#{unwatched_films} movies"
p "#{unwatched_videos} videos"
params = {'auth_token' => auth_token, 'current' => unwatched_tv_shows}
uri = URI.parse('http://dashboard.camillebaldock.com/widgets/tv')
http = Net::HTTP.new(uri.host, uri.port)
response = http.post(uri.path, params.to_json, json_headers)
params = {'auth_token' => auth_token, 'current' => unwatched_films}
uri = URI.parse('http://dashboard.camillebaldock.com/widgets/films')
http = Net::HTTP.new(uri.host, uri.port)
response = http.post(uri.path, params.to_json, json_headers)
params = {'auth_token' => auth_token, 'current' => unwatched_videos}
uri = URI.parse('http://dashboard.camillebaldock.com/widgets/videos')
http = Net::HTTP.new(uri.host, uri.port)
response = http.post(uri.path, params.to_json, json_headers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment