Skip to content

Commit

Permalink
Initial Version
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaiede committed Feb 4, 2020
0 parents commit 79de42f
Show file tree
Hide file tree
Showing 10 changed files with 371 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.DS_Store

89 changes: 89 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Contributing

When contributing to this repository, please first discuss the change you wish to make via issue,
email, or any other method with the owners of this repository before making a change.

Please note we have a code of conduct, please follow it in all your interactions with the project.

## Pull Request Process

1. Update the README.md with details of changes to the interface, this includes new environment
variables, exposed ports, useful file locations and container parameters.
2. Update any examples that are affected by your changes, and include new examples as appropriate.
3. You may merge the Pull Request in once you have the sign-off of two other developers, or if you
do not have permission to do that, you may request the second reviewer to merge it for you.

## Code of Conduct

### Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
nationality, personal appearance, race, religion, or sexual identity and
orientation.

### Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

### Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

### Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

### Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at [INSERT EMAIL ADDRESS]. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

### Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at [http://contributor-covenant.org/version/1/4][version]

[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Adam Thayer

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
186 changes: 186 additions & 0 deletions PlaylistHost.bundle/Contents/Code/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
# -*- coding: utf-8 -*-
#
# This is a stripped down, modified

import json
import os
from lxml import etree
from random import shuffle

NAME = 'Playlists'
PREFIX = '/music/playlisthost'
PLUGIN_DIR = 'com.plexapp.plugins.playlisthost'
LIBRARY_PLAYLISTS = '/playlists'
URL_MUSIC_PLAYLIST = 'http://com.plexapp.plugins.playlisthost/track'
ART = 'art-default.png'
ICON = 'icon-default.png'

# File version
CURRENT_VERSION_ALL = "1"
CURRENT_VERSION_SINGLE = "2"

# Preferences
PREFS__PLEXIP = 'plexip'
PREFS__PLEXPORT = 'plexport'

# Client / User information
CLIENT_UNKNOWN = 'Unknown'
CLIENT_USER_LIST = 'client_user_list'
DICT_KEY_CLIENT_LIST = CLIENT_USER_LIST

# Plex XML Parsing
PMS_XPATH_PLAYLIST = '//Playlist'
PMS_XPATH_TRACK = '//Track'

# XML Attribute names
ATTR_TITLE = 'title'
ATTR_KEY = 'key'
ATTR_THUMB = 'thumb'

ATTR_COMPOSITE = 'composite'
ATTR_LEAF_COUNT = 'leafCount'
ATTR_DURATION = 'duration'
ATTR_SUMMARY = 'summary'

ATTR_PARENT_TITLE = 'parentTitle'
ATTR_GRANDPARENT_TITLE = 'grandparentTitle'
ATTR_RATINGKEY = 'ratingKey'
ATTR_AUDIOCODEC = 'audioCodec'
ATTR_AUDIOCHANNELS = 'audioChannels'
ATTR_CONTAINER = 'container'
ATTR_PARTKEY = 'partkey'
ATTR_BITRATE = 'bitrate'

# String Resources
TEXT_MAIN_MENU = "TEXT_MAIN_MENU"

####################################################################################################
def Start():
Plugin.AddPrefixHandler(PREFIX, MainMenu, NAME)
Plugin.AddViewGroup('List', viewMode='List', mediaType='items')
#Plugin.AddViewGroup('InfoList', viewMode='InfoList', mediaType='items')
#Plugin.AddViewGroup('Maintenance', viewMode='List', mediaType='items')

ObjectContainer.title1 = L(TEXT_MAIN_MENU)
ObjectContainer.view_group = 'List'
ObjectContainer.art = R(ART)
ObjectContainer.thumb = R(ICON)

DirectoryObject.thumb = R(ICON)
DirectoryObject.art = R(ART)

Log.Debug('Plugin Started With: %s' % (NAME))
Log.Debug('Using Server: %s' % (GetPlexUrl()))

####################################################################################################
#@handler(PREFIX, NAME)
def MainMenu():
Log.Debug('Main Menu')
oc = ObjectContainer(no_cache = True)
oc.title1 = L(TEXT_MAIN_MENU)

playlists = FetchPlaylists()
for playlist in playlists:
oc.add(CreatePlaylistObject(playlist))

return oc

#@route(PREFIX +'/playlist')
def PlaylistMenu(title, key):
Log.Debug('Playlist Menu')
oc = ObjectContainer(no_cache = True)
oc.title1 = title

tracks = FetchTracks(key)
for track in tracks:
oc.add(CreateTrackObject(track))

return oc

####################################################################################################
# Generating PopupDirectoryObject from Playlist XML

def CreatePlaylistObject(playlist):
title = playlist.get(ATTR_TITLE)
key = playlist.get(ATTR_KEY)

callbackObject = Callback(PlaylistMenu, title=title, key=key)

directoryObject = PopupDirectoryObject(key=callbackObject, title=title)
directoryObject.duration = playlist.get(ATTR_DURATION)
directoryObject.summary = playlist.get(ATTR_SUMMARY)
if playlist.get(ATTR_COMPOSITE) != None:
directoryObject.thumb = playlist.get(ATTR_COMPOSITE)
directoryObject.thumb = R(ICON)

return directoryObject

####################################################################################################
# Conversion of Track XML to TrackObject

def CreateTrackObject(track):
# Track Basics
title = track.get(ATTR_TITLE)
key = track.get(ATTR_KEY)
ratingKey = track.get(ATTR_RATINGKEY)

trackObject = TrackObject(title=title, key=key, rating_key=ratingKey)
trackObject.artist = track.get(ATTR_GRANDPARENT_TITLE)
trackObject.album = track.get(ATTR_PARENT_TITLE)
if track.get(ATTR_THUMB) != None:
trackObject.thumb = track.get(ATTR_THUMB)

# Media Object
partKey = track.get(ATTR_PARTKEY)
mediaObject = MediaObject(parts=[PartObject(key=partKey)])
mediaObject.duration = trackObject.duration
mediaObject.bitrate = attributeAsInt(track.get(ATTR_BITRATE))
mediaObject.audio_channels = attributeAsInt(track.get(ATTR_AUDIOCHANNELS))
if track.get(ATTR_AUDIOCODEC) != None:
mediaObject.audio_codec = track.get(ATTR_AUDIOCODEC)
if track.get(ATTR_CONTAINER) != None:
mediaObject.container = track.get(ATTR_CONTAINER)
trackObject.add(mediaObject)

return trackObject

def attributeAsInt(attr_value, def_value = 0):
if attr_value != None:
try:
if attr_value.isdigit():
return int(attr_value)
except Exception:
pass
return def_value

####################################################################################################
# PLEX Helpers

def GetPlexUrl(suffix=None):
plexUrl = 'http://%s:%s' %(Prefs[PREFS__PLEXIP], Prefs[PREFS__PLEXPORT])
if suffix is not None:
plexUrl += suffix

Log.Debug('Requesting Plex URL: %s' % (plexUrl))
return plexUrl

def FetchPlaylists():
Log.Debug('Fetching Playlists')

playlistUrl = GetPlexUrl(LIBRARY_PLAYLISTS)
el = XML.ElementFromURL(playlistUrl)
Log.Debug(el)
playlist_xpath = '%s[@playlistType="audio"]' % PMS_XPATH_PLAYLIST
playlistXml = el.xpath(playlist_xpath)

return playlistXml

def FetchTracks(playlistKey):
Log.Debug('Fetching Tracks')

playlistUrl = GetPlexUrl(playlistKey)
el = XML.ElementFromURL(playlistUrl)
playlist_xpath = '%s[@type="track"]' % PMS_XPATH_TRACK
trackXml = el.xpath(playlist_xpath)

return trackXml
14 changes: 14 additions & 0 deletions PlaylistHost.bundle/Contents/DefaultPrefs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"id": "plexip",
"label": "Plex IP",
"type": "text",
"default": "localhost"
},
{
"id": "plexport",
"label": "Plex port",
"type": "text",
"default": "32400"
}
]
16 changes: 16 additions & 0 deletions PlaylistHost.bundle/Contents/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleIdentifier</key>
<string>com.plexapp.plugins.playlisthost</string>
<key>PlexClientPlatforms</key>
<string>*</string>
<key>PlexFrameworkVersion</key>
<string>2</string>
<key>PlexPluginClass</key>
<string>Content</string>
<key>PlexPluginCodePolicy</key>
<string>Elevated</string>
</dict>
</plist>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions PlaylistHost.bundle/Contents/Strings/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"MAIN_MENU" : "Playlists"
}
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# PLEX Playlist Hosting Channel

This was built to work around a limitation of PLEX where it doesn't make Music playlists available to UPnP clients. This makes it difficult to use with systems like HEOS and other UPnP clients, which is sad because PLEX does a lot of things right with how it exposes music to these clients otherwise.

It creates a new channel that simply passes along everything it finds in the server's Playlists. It will filter playlists to just audio playlists, giving a clean list.

### Installation

Copy the PlaylistHost.bundle to the Plex Media Server plugins folder for your installation.

See this link for further details: https://support.plex.tv/articles/201187656-how-do-i-manually-install-a-plugin/

## Configuration

Right now there's just two settings:

* IP Address of the Plex Server
* Port of the Plex Server

These are both set to sane defaults which should work in most cases.

## Contributing

Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.

### TODO

* Allow HTTPS connections to PLEX, if possible.
* Allow Renaming of channel to something other than "Playlists", if possible.
* Provide non-placeholder images for resources.

## Authors

* **Adam Thayer** - *Initial work* - [Kaiede](https://github.com/Kaiede)

See also the list of [contributors](https://github.com/Kaiede/PlaylistHost/contributors) who participated in this project.

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details

0 comments on commit 79de42f

Please sign in to comment.