54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
#!/usr/bin/python3
|
|
|
|
from utils import *
|
|
from download_page import download
|
|
|
|
# portable code to get filename
|
|
import os
|
|
platform = os.path.basename(__file__)
|
|
if platform.endswith(".py"):
|
|
platform = platform[:(-3)]
|
|
|
|
channel_url_start = "https://vimeo.com/user"
|
|
channel_url_end = "/videos/rss"
|
|
|
|
def extract_from_url (url, verbosity):
|
|
# useful function for stripping ID out of URL
|
|
def get_id (url, prefix):
|
|
if prefix in url:
|
|
ident = url[url.index(prefix) + len(prefix):]
|
|
for symbol in ["/","?", "&"]:
|
|
if symbol in ident:
|
|
ident = ident[:ident.index(symbol)]
|
|
return ident
|
|
else:
|
|
return None
|
|
|
|
username = get_id (url, "vimeo.com/user")
|
|
if username != None:
|
|
return channel_url_start + username + channel_url_end
|
|
|
|
def extract_from_page (page, verbosity):
|
|
# We can get the username from a few places. We'll include multiple
|
|
# in case Vimeo makes breaking changes.
|
|
username = search (page, '"creator_id":', ",")
|
|
if username is None:
|
|
username = search (page, '"owner":{"id":', ',"display_name":"')
|
|
if username is None:
|
|
username = search (page, '"item":{"@id":"https://vimeo.com/user', '","name":')
|
|
|
|
if not username is None:
|
|
return channel_url_start + username + channel_url_end
|
|
|
|
def extract (url, page=None, network=False, verbosity=3, args={}):
|
|
feed = extract_from_url (url, verbosity)
|
|
if not feed is None:
|
|
return feed
|
|
else:
|
|
notify ("Unable to get feed from URL alone", verbosity, platform)
|
|
if network == True:
|
|
page = download (platform, url, args, verbosity)
|
|
feed = extract_from_page (page, verbosity)
|
|
if not feed is None:
|
|
return feed
|