Skip to content

Instantly share code, notes, and snippets.

@squaresmile
Created October 18, 2019 19:41
Show Gist options
  • Save squaresmile/5a4411a446794287be45e9afa7dca7f2 to your computer and use it in GitHub Desktop.
Save squaresmile/5a4411a446794287be45e9afa7dca7f2 to your computer and use it in GitHub Desktop.
import os
from urllib.parse import quote_plus
from urllib.request import urlopen, Request
PREPEND = "/home/user/rtorrent/downloads/My Music/Anime/"
ORIGINAL_PLAYLIST_LOCATION = PREPEND
PLEX_TOKEN = "plextoken"
SECTION_ID = "30"
SERVER_URL = "localhost:32400"
url = "http://{}/playlists/upload?sectionID={}&path={}&X-Plex-Token={}"
files = os.listdir(ORIGINAL_PLAYLIST_LOCATION)
files = [f for f in files if f.endswith("m3u8") or f.endswith("m3u")]
for file in files:
with open(
os.path.join(ORIGINAL_PLAYLIST_LOCATION, file), "r", encoding="utf-8-sig"
) as f:
lines = f.readlines()
lines = [PREPEND + l.replace("\\", "/") for l in lines]
output_file = file.replace("m3u8", "m3u")
with open(output_file, "w", encoding="utf-8") as f:
f.writelines(lines[1:])
script_path = os.path.dirname(os.path.realpath(__file__))
full_output_path = os.path.join(script_path, output_file)
url_encoded_path = quote_plus(full_output_path)
full_url = url.format(SERVER_URL, SECTION_ID, url_encoded_path, PLEX_TOKEN)
print(full_url)
urlopen(Request(full_url, method="POST"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment