-
-
Save Juice805/5603e03e0162de61217af59354c25376 to your computer and use it in GitHub Desktop.
Downloads all public videos of a user
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
#! /usr/bin/python3 | |
# download all PlaysTv videos of a user | |
# To find the user id, navigate to the your profile while logged in (IMPORTANT!) | |
# View source of the page, In the <html> tag there's data-conf attribute. | |
# The json in there will have the user id under [login_user.id] | |
user_id = "<playstv user guid>" | |
# Replace the <playstv user guid> above with your ID | |
from re import sub | |
from json import load | |
from urllib.request import urlretrieve, urlopen | |
import time | |
try: | |
from mutagen.mp4 import MP4 | |
except ImportError: | |
print("mutagen not installed. Ignoring metadata.") | |
MP4 = None | |
def is_windows(): | |
import platform | |
return platform.system() == 'Windows' | |
if is_windows(): | |
try: | |
from win32_setctime import setctime | |
except ImportError: | |
print("win32-setctime is not installed. Not setting creation time.") | |
setctime = None | |
def set_creation_time(filename, ms_epoch): | |
created = ms_epoch / 1000 | |
if is_windows(): | |
if setctime: | |
setctime(filename, created) | |
else: | |
import os | |
stamp = time.strftime('%m/%d/%Y %H:%M:%S', time.localtime(created)) | |
command = 'SetFile -d \"' + stamp + '\" \"' + filename + '\"' | |
os.system(command) | |
def update_metadata(filename, title, game): | |
if MP4: | |
mp4 = MP4(filename) | |
mp4["\xa9nam"] = title | |
mp4["desc"] = game | |
mp4.save() | |
def safe_title(index, title): | |
only_chars = sub(r'[^\w]+', '_', title).strip("_") | |
return f"{index} - {only_chars}.mp4"[:255] | |
def get_playstv_videos(user_id): | |
last_id = "" | |
items = [] | |
while last_id != None: | |
batch = load(urlopen(f"https://plays.tv/playsapi/feedsys/v1/userfeed/{user_id}/uploaded?limit=200&filter=&lastId={last_id}")) | |
items.extend(batch["items"]) | |
last_id = batch["lastId"] | |
print(len(items)) | |
for index,item in enumerate(items, start=1): | |
description = item["description"] | |
filename = safe_title(index,description) | |
if "gameTitle" in item: | |
game = item["gameTitle"] | |
else: | |
game = "" | |
if "downloadUrl" in item: | |
url = item["downloadUrl"] | |
else: | |
url = item["src"] | |
print(filename, url) | |
try: | |
urlretrieve(url, filename) | |
except Exception as e: | |
print("Failed to download.") | |
print(e) | |
continue | |
try: | |
set_creation_time(filename, item["created"]) | |
update_metadata(filename, description, game) | |
except Exception as e: | |
print("Failed to update metadata.") | |
print(e) | |
continue | |
if __name__ == "__main__": | |
get_playstv_videos(user_id) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you know of a way to download videos that other people have uploaded with you in them? They don't show up through that API call but are available on your profile.
I'm not sure where I would find plays.tv API endpoints. Their developer page doesn't have any listed as far as I can tell unless you have a registered app with them.