Browse Source

public

public
main
Tim 2 years ago
parent
commit
e245546f72
  1. 2
      .gitignore
  2. 44
      README.md
  3. 18
      patreon-vimeo.sh
  4. 65
      patreon.py
  5. 1
      requirements.txt

2
.gitignore vendored

@ -0,0 +1,2 @@
env
geckodriver.log

44
README.md

@ -1 +1,43 @@
Patreon - Vimeo Downloader
# Patreon - Vimeo Archiver
Uses python and selenium to load patreon. Login using your credentials. Then checks for vimeo videos with the episode name.
I originally created this because I have terrible internet on my portable devices, and wanted a way to watch the videos that did not require the patreon application as I had zero devices that were supported.
So just archive the vidoes and then sync to your portable device
Warranty: There is no warranty!
License: If you use this code you are required to donate your monthly patreon costs to a local food/soup kitchen. Once per month.
IE. If you are currently paying $10/month to 5 patreon for a total of $50. You are required to donate $50 per month of usage.
## Usage
### Setup
Edit patreon.py with your:
- username
- password
- specific episode naming
- firefox/chrome location
Install youtube-dl
### Environment
```
# initialise a virtual env
virtualenv env
pip3 install -r requirements.txt
```
### Run it!
```
python3 patreon.py
# It will output the ID of the video(s). Now download that ID via youtube-dl with the correct settings
youtube-dl $id
```
Checkout the included wrapper script for how you would meld the two together
`./patreon-vimeo.sh`

18
patreon-vimeo.sh

@ -0,0 +1,18 @@
#!/bin/bash
function ytdlPatreon {
youtube-dl -f 'bestvideo[height=720]+bestaudio[ext=m4a]'\
https://player.vimeo.com/video/$1 \
--referer https://www.patreon.com/ \
--download-archive $HOME/.cache/youtube-dl.log
}
if ! [ -z $1 ]; then
id=$1
else
# activate our patreon amazingness
source ./env/bin/activate
id=$(python3 patreon.py)
fi
ytdlPatreon "$id"

65
patreon.py

@ -0,0 +1,65 @@
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.firefox.options import Options
from sys import exit
from sys import stderr
import re
def eprint(*args, **kwargs):
print(*args, file=stderr, **kwargs)
URL = 'https://www.patreon.com/'
username = ''
password = ''
EPISODE = ''
options = Options()
options.headless = True
driver = webdriver.Firefox(options=options, firefox_binary="/opt/firefox/firefox")
driver.set_window_size(1024, 768)
driver.get(URL + 'login')
driver.find_element_by_css_selector('#email').send_keys(username)
driver.find_element_by_css_selector('#password').send_keys(password)
driver.find_element_by_xpath('//button[@type="submit"]').click()
# driver.implicitly_wait(15) # seconds
# wait for page to load
try:
WebDriverWait(driver, 30).until(
EC.presence_of_element_located((By.PARTIAL_LINK_TEXT, EPISODE))
)
except Exception as e:
eprint("Failed to find a {} episode. E: {}".format(EPISODE, e))
eprint("Current URL: {}".format(driver.current_url))
driver.close()
driver.quit()
exit(1)
# grab the links
videos = driver.find_elements_by_partial_link_text(EPISODE)
# print the urls
for url in ([a.get_attribute("href") for a in videos]):
driver.get(url)
WebDriverWait(driver, 30).until(
EC.presence_of_element_located((By.XPATH, "//button"))
)
driver.find_element_by_xpath('//button[@title="Start playback"]').click()
WebDriverWait(driver, 30).until(
EC.presence_of_element_located((By.XPATH, "//iframe"))
)
element = driver.find_element_by_xpath('//iframe')
main_url = element.get_attribute("src")
video_id = re.search('https%3A%2F%2Fplayer.vimeo.com%2Fvideo%2F([0-9]+)%3F', main_url)
# print(main_url)
print(video_id.group(1))
break
driver.close()
driver.quit()

1
requirements.txt

@ -0,0 +1 @@
selenium
Loading…
Cancel
Save