Skip to content

Instantly share code, notes, and snippets.

@simon987
Created October 16, 2018 00:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simon987/0756c378ca2dfb0003931e26ff7fe270 to your computer and use it in GitHub Desktop.
Save simon987/0756c378ca2dfb0003931e26ff7fe270 to your computer and use it in GitHub Desktop.
Script to rip all videos from https://floatplane.rip/
#!/usr/bin/env python3
# Rip floatplane.rip
# by terorie :P
import sys
import requests
import lxml.html
from clint.textui import progress
session = requests.Session()
if len(sys.argv) != 2:
print("Usage: ./linusriptips.py <site>")
exit(1)
main_r = session.get(sys.argv[1])
if main_r.status_code != 200:
print("Failed getting", sys.argv[1])
exit(1)
main_doc = lxml.html.fromstring(main_r.text)
cards = main_doc.find_class('card mb-4 box-shadow')
for card in cards:
card_onclick = card.get('onclick')
if not card_onclick.startswith("location.href='"):
continue
if not card_onclick.endswith("'"):
continue
video_link = card_onclick[15:len(card_onclick)-1]
if not video_link.startswith("https://floatplane.rip/video/"):
continue
name = video_link[29:] + "_1080.mp4"
print("Found video:", name)
video_r = session.get(video_link)
if video_r.status_code != 200:
print("Failed getting", video_link)
continue
video_doc = lxml.html.fromstring(video_r.text)
metas = video_doc.cssselect("meta")
src = None
for meta in metas:
prop = meta.get('property')
if prop != "og:video":
continue
src = meta.get("content")
if src is None:
print("Failed extracting video URL from", video_link)
continue
src_r = session.get(src, stream=True)
with open(name, 'wb') as f:
print("Downloading", name)
total_length = int(src_r.headers.get('content-length'))
for chunk in progress.bar(src_r.iter_content(chunk_size=1024), expected_size=(total_length/1024) + 1):
if chunk:
f.write(chunk)
f.flush()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment