Created
September 1, 2020 04:27
-
-
Save nwithan8/6e5a961ed9c1703e974b5b63df2022e6 to your computer and use it in GitHub Desktop.
Add items from a dizqueTV channel to a Plex playlist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # RUN THIS FIRST: | |
| # pip install plexapi dizqueTV | |
| from typing import List | |
| import plexapi | |
| from dizqueTV import API | |
| from plexapi.server import PlexServer | |
| # COMPLETE THESE SETTINGS | |
| DIZQUETV_URL = "http://localhost:8000" | |
| DIZQUETV_CHANNEL_NUMBER = 1 | |
| # Plex playlist will have the same name as the dizqueTV channel | |
| PLEX_URL = "http://localhost:32400" | |
| PLEX_TOKEN = "thisisaplextoken" | |
| class Plex: | |
| def __init__(self, url, token): | |
| self.url = url | |
| self.token = token | |
| self.server = PlexServer(url, token) | |
| def get_playlists(self): | |
| return self.server.playlists() | |
| def get_playlist(self, playlist_name: str): | |
| for playlist in self.get_playlists(): | |
| if playlist.title == playlist_name: | |
| return playlist | |
| return None | |
| def create_new_playlist(self, playlist_name, items: List[plexapi.media.Media]): | |
| self.server.createPlaylist(title=playlist_name, items=items) | |
| def reset_playlist(self, playlist_name, items: List[plexapi.media.Media]): | |
| playlist = self.get_playlist(playlist_name=playlist_name) | |
| if playlist: | |
| playlist.delete() | |
| self.create_new_playlist(playlist_name=playlist_name, items=items) | |
| def get_plex_item(self, item, section_name=None): | |
| if section_name: | |
| results = self.server.library.section(section_name).search(title=item.title) | |
| else: | |
| results = self.server.library.search(title=item.title) | |
| for media in results: | |
| if int(media.ratingKey) == int(item.ratingKey): | |
| return media | |
| return None | |
| dtv = API(url=DIZQUETV_URL) | |
| plex = Plex(url=PLEX_URL, token=PLEX_TOKEN) | |
| channel = dtv.get_channel(channel_number=DIZQUETV_CHANNEL_NUMBER) | |
| to_add = [] | |
| for program in channel.programs: | |
| plex_item = plex.get_plex_item(item=program) | |
| if plex_item: | |
| print(f"Adding {plex_item.title}...") | |
| to_add.append(plex_item) | |
| plex.reset_playlist(playlist_name=channel.name, items=to_add) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment