Skip to content

Instantly share code, notes, and snippets.

@maddox
Last active January 6, 2023 21:00
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 maddox/8066a08d1fc2d433823113d527a1d531 to your computer and use it in GitHub Desktop.
Save maddox/8066a08d1fc2d433823113d527a1d531 to your computer and use it in GitHub Desktop.
Process YouTube videos in Channels to get Thumbnail

This is a script to process YouTube videos on Channels DVR Server to apply a nicer thumbnail.

This assumes the YouTube ID and/or the published date is in the EpisodeTitle of the video. IE, Name of Video_(2023-01-06)_[akZxhhcwkR4]. This should be the case if the filename is Name of Video_(2023-01-06)_[akZxhhcwkR4].EXT in order to derive the video title from the filename when importing.

Published Date is optional.

When running this script, it will process every video in the video group. It will:

  1. Pull the YouTube id from the title
  2. Use it to generate the thumbnail url
  3. Pull the published date from the title
  4. Use the new thumbnail url for the video
  5. Update the Original Date of the video to use the published date
  6. Update the EpisodeTitle to remove the YouTube ID and Original Date
require 'httparty'
require 'json'
server_url = 'http://YOUR_IP:8089'
video_group = 'VIDEO_GROUP_ID'
source_files = HTTParty.get("#{server_url}/dvr/groups/#{video_group}/files")
source_files.each do |file|
file_id = file['ID']
title = file['Airing']['EpisodeTitle']
yt_match = title.match(/(_\((\d\d\d\d-\d\d-\d\d)\))?_?\[(.*)\]/)
if yt_match
yt_date = yt_match[2]
yt_id = yt_match[3]
yt_thumbnail_url = "https://i3.ytimg.com/vi/#{yt_id}/maxresdefault.jpg"
new_title = title.gsub(yt_match[0], '')
package = {Thumbnail: yt_thumbnail_url, Airing: {EpisodeTitle: new_title}}
if yt_date
package[:Airing][:OriginalDate] = yt_date
end
HTTParty.put("#{server_url}/dvr/files/#{file_id}", :body => package.to_json)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment