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
}
@Juice805
Copy link

Thanks! Works perfectly.

@Juice805
Copy link

use downloadUrl instead of src to get the highest quality video instead

@st0le
Copy link
Author

st0le commented Nov 21, 2019

Thanks. Updated

@beng934
Copy link

beng934 commented Nov 21, 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.

@ajamesc97
Copy link

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.

@cainxxx
Copy link

cainxxx commented Nov 21, 2019

Getting this error:
Traceback (most recent call last):
File "F:\PlaysTV_DL\PlaysTV_Vid_downloader.py", line 28, in
get_playstv_videos("66873cea679baca707373b36baf8cad6")
File "F:\PlaysTV_DL\PlaysTV_Vid_downloader.py", line 24, in get_playstv_videos
urlretrieve(item["downloadUrl"], safe_title(index,item["description"]))
File "C:\Users\Cain\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 257, in urlretrieve
tfp = open(filename, 'wb')
OSError: [Errno 22] Invalid argument: '37 - Full_vid_on_youtube_Fight_with_some_guys_that_can_t_win_without_taking_out_2_jets_when_6_players_are_on_We_lost_2_Shilkas_they_lost_3_gunships_and_a_M1A2_TUSK_xplosive_BelleGunnes_Kozmo_02_Oldfuchs_Thee_Rathex_Full_video_here_as_plays_fails_large_uploads_https_youtu_be_qkW1MvJSY4o.mp4'

I already deleted some videos giving the error but since I have 1600 vids I expect them to show up frequently, I tried searching for the error but I'm pretty noob at pythin or coding in general, any ideas?

@cainxxx
Copy link

cainxxx commented Nov 21, 2019

But THANK YOU so very much for this script! this is a real LIFESAVER!

@Valdemarr
Copy link

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.

You are a saint!

@Valdemarr
Copy link

Thank you SO much for this st0le! You're a great dude.

@st0le
Copy link
Author

st0le commented Nov 21, 2019

I will try to get a short webapp running during the weekend for the non-technical people out there. :)

@Juice805
Copy link

Juice805 commented Nov 21, 2019

Getting this error:
Traceback (most recent call last):
File "F:\PlaysTV_DL\PlaysTV_Vid_downloader.py", line 28, in
get_playstv_videos("66873cea679baca707373b36baf8cad6")
File "F:\PlaysTV_DL\PlaysTV_Vid_downloader.py", line 24, in get_playstv_videos
urlretrieve(item["downloadUrl"], safe_title(index,item["description"]))
File "C:\Users\Cain\AppData\Local\Programs\Python\Python38\lib\urllib\request.py", line 257, in urlretrieve
tfp = open(filename, 'wb')
OSError: [Errno 22] Invalid argument: '37 - Full_vid_on_youtube_Fight_with_some_guys_that_can_t_win_without_taking_out_2_jets_when_6_players_are_on_We_lost_2_Shilkas_they_lost_3_gunships_and_a_M1A2_TUSK_xplosive_BelleGunnes_Kozmo_02_Oldfuchs_Thee_Rathex_Full_video_here_as_plays_fails_large_uploads_https_youtu_be_qkW1MvJSY4o.mp4'

I already deleted some videos giving the error but since I have 1600 vids I expect them to show up frequently, I tried searching for the error but I'm pretty noob at pythin or coding in general, any ideas?

@cainxxx my fork may help you get past your error: https://gist.github.com/Juice805/5603e03e0162de61217af59354c25376

Just be sure to check the output and manually download the files that have errors

@st0le
Copy link
Author

st0le commented Nov 21, 2019

@cainxxx It looks like your Video title is too long or contains invalid characters. I will try and address the issue in the evening. Please check back later. Thanks

For a quick fix. Just make the video title short.

@cainxxx
Copy link

cainxxx commented Nov 21, 2019

Thank you to all of you guys that took time to work on these scripts, you are all lifesavers <3

@0151CALC
Copy link

Nice script man works really well.

@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