Skip to content

Instantly share code, notes, and snippets.

@st0le
Last active January 5, 2020 09:01
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save st0le/b6cb31272e1e03a7e1d479b2686d3e3e to your computer and use it in GitHub Desktop.
Save st0le/b6cb31272e1e03a7e1d479b2686d3e3e to your computer and use it in GitHub Desktop.
Downloads all public videos of a user
# 2019-23-11 - Added Powershell Script. See the other file.
# 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]
from re import sub
from json import load
from urllib.request import urlretrieve, urlopen
def safe_title(index, title):
only_chars = sub(r'[^\w]+', '_', title).strip("_")
return f"{index} - {only_chars[:30]}.mp4"
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):
try:
filename, url = safe_title(
index, item["description"]), item["downloadUrl"]
print(f"Downloading {filename} from {url}")
urlretrieve(url, filename)
except Exception as e:
print(f"Error downloading {filename} from {url}")
print(e)
if __name__ == "__main__":
get_playstv_videos("<playstv userid>")
# Copy and paste this in a Powershell window. Enter the userId at the prompt. Follow instruction below to get your userId
# 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]
function Safe-Title {
param (
$Description,
$EpochMilliseconds
)
$CreatedDate = (Get-Date "1970-01-01 00:00:00.000Z") + ([TimeSpan]::FromSeconds($EpochMilliseconds / 1000))
$Title = $Description -replace "[^\w]+", "_"
$Title = $Title.Substring(0, [System.Math]::Min(30, $Title.Length))
return (get-date $CreatedDate -uformat "%Y-%m-%d") + " - " + $Title + ".mp4"
}
$userId = Read-Host -Prompt "Enter UserID"
$lastId = ""
while ($null -ne $lastId) {
$page = Invoke-RestMethod "https://plays.tv/playsapi/feedsys/v1/userfeed/$userId/uploaded?limit=20&filter=&lastId=$lastId"
$videos = $page.items | Select-Object downloadUrl, @{Name = 'fileName'; Expression = { Safe-Title $_.description $_.created } }
$videos | ForEach-Object { Write-Host "Downloading $($_.fileName)"; Invoke-WebRequest -Uri $_.downloadUrl -OutFile $_.fileName; Write-Host "Downloaded $($_.fileName)" }
$lastId = $page.lastId
}
@0151CALC
Copy link

To add a suggestion though it would be great if the date the clip was uploaded was included in the title.

@ValendinX
Copy link

ValendinX commented Nov 22, 2019

Hi,
Sorry to be a bit of a noob but that text above means nothing to me. I need to try and download all of my plays.tv content. But I'm unsure of how to use the script above. I managed to get to #4 but then after that i'm unsure of what to do.

If you have your user id already, then you need to go to python's website and install 3.8. Then right click this .py file and "Edit in IDLE." Where it says {user_id} in line 17 you want to replace that with your id. Then click run at the top, then click run module and it'll start downloading all your videos to the folder your .py file is in.

I keep getting "NameError: Name is undefined" message. I'm pretty sure I have the correct user id, according to the steps above. Any solution?

EDIT: FIXED, I just had to remove the parentheses

@st0le
Copy link
Author

st0le commented Nov 23, 2019

Added a Powershell Script for people without Python. All windows users should be able to use it.

@clamspianos
Copy link

Added a Powershell Script for people without Python. All windows users should be able to use it.

Is there a way to specify the download location with the Powershell Script?

I've tried the python script but it fails on the 18th clip every time (out of 1000~), probably do to a naming issue.

@st0le
Copy link
Author

st0le commented Nov 26, 2019

Navigate to the directory using cd command before executing the powershell script

@st0le
Copy link
Author

st0le commented Nov 26, 2019

@clamspianos, could you post your user ID. I can try fixing the script

@clamspianos
Copy link

Navigate to the directory using cd command before executing the powershell script

Thanks for getting back to me, oof, I feel dumb about that.

Running the powershell is working so far, as it will continue to download even if one clip has and issue.

Thanks @st0le !

@jeremiahfallin
Copy link

jeremiahfallin commented Nov 29, 2019

Is there a way to also download videos of you that other people have uploaded?

@jeremiahfallin
Copy link

Also I think some video titles can still cause the script to error out? I was pulling videos for this user and one of them broke the script, maybe because it was too long?
6c768bd496efc8b16065dbf926d7fe99

@st0le
Copy link
Author

st0le commented Dec 2, 2019

@jeremiahfallin Try the updated script. It worked fine for me, Got 629 videos.

@jeremiahfallin
Copy link

jeremiahfallin commented Dec 2, 2019

For me as an example, I have 212 videos that I have uploaded and then 47 videos that other users have uploaded that I'm in. Is there an easy way to get the 47? The API url in the script only pulls videos uploaded by the person with the user id we use.
This is my id: 362ba04c2955a3820a9f4bf2abfb3ab0

image

I've been working on a script using selenium that scrolls the page and pulls the video IDs to download them but I haven't quite gotten the video names too.

@st0le
Copy link
Author

st0le commented Dec 2, 2019

Ah not sure. Sorry. The API I used didn't return the unlisted videos either.

@jeremiahfallin
Copy link

Unlisted shouldn't be returned unless you're logged in since they're private. I was talking about the Videos of you which are public.

@st0le
Copy link
Author

st0le commented Dec 3, 2019

I'm aware. I was trying to say the API I'm using in the script is limited.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment