Created
October 18, 2019 19:41
-
-
Save squaresmile/5a4411a446794287be45e9afa7dca7f2 to your computer and use it in GitHub Desktop.
This file contains 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
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