Skip to content

Instantly share code, notes, and snippets.

@fredkilbourn
Last active September 8, 2019 01:47
Show Gist options
  • Save fredkilbourn/8ebb3e96a29d870dddabcd169468366c to your computer and use it in GitHub Desktop.
Save fredkilbourn/8ebb3e96a29d870dddabcd169468366c to your computer and use it in GitHub Desktop.
Plex Live TV Channels HD Only
javascript:
{
/* can be pasted in console or as a bookmark */
/* metadata */
const channels = [];
var count_enabled = 0;
var count_guide_channel_missing = 0;
var count_guide_missing_channels_matched_alternate = 0;
/* iterate all channels */
document.querySelectorAll( "div.DeviceChannelMapping-channelMapping-2Z4xxm" ).forEach( currentValue =>
{
/* scrape channel elements */
const channel_enabled = currentValue.querySelector( "input" );
const channel_number = currentValue.querySelector("label.DeviceChannelMapping-deviceIdentifier-3-v5l4").innerText;
const channel_name_device = currentValue.querySelector("div.DeviceChannelMapping-channelName-2knCVI").innerText;
var channel_name_guide = currentValue.querySelector( "select.SelectInput-select-3zFgU3" );
const hd = currentValue.querySelector("span.EPGChannelResolution-resolution-rYFHtf") !== null;
/* click to disable channel if enabled and not hd, count enabled channels */
if( channel_enabled !== null && channel_enabled.checked )
{
if( hd === false )
channel_enabled.click();
else
count_enabled++;
}
/* skip metadata gathering if not hd, since we skipped / don't care */
if( hd === false )
return;
/* count channels with found guide channel */
if( channel_name_guide !== null && channel_name_guide.value !== "" )
channel_name_guide = channel_name_guide.selectedOptions[0].label;
else
{
channel_name_guide = false;
count_guide_channel_missing++;
}
/* if channel name is not found in guide, see if the channel is found previously */
var missing_channel_found = null;
if( channel_name_guide === false )
{
if( ( missing_channel_found = channels.find( element => element['Device Channel Name'] === channel_name_device ) ) !== undefined )
{
missing_channel_found = missing_channel_found['Channel Number'];
count_guide_missing_channels_matched_alternate++;
}
else
missing_channel_found = false;
}
/* save metadata */
channels.push(
{
"Channel Number": channel_number,
"Device Channel Name": channel_name_device,
"Guide Channel Name": channel_name_guide,
"Missing Channel Found": missing_channel_found,
"HD": hd
} );
} );
/* print metadata */
console.table( channels );
console.table(
{
"Enabled channels": count_enabled,
"Guide channels missing": count_guide_channel_missing,
"Missing guide channels matched alternate": count_guide_missing_channels_matched_alternate
} );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment