-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env python | ||
""" | ||
Script to generate a YouTube playlist from a puppet videos page | ||
""" | ||
|
||
import sys | ||
import requests | ||
|
||
try: | ||
from lxml import etree, html | ||
except ImportError: | ||
try: | ||
# normal cElementTree install | ||
import cElementTree as etree | ||
except ImportError: | ||
try: | ||
# normal ElementTree install | ||
import elementtree.ElementTree as etree | ||
except ImportError: | ||
raise SystemExit("Failed to import ElementTree from any known place") | ||
|
||
|
||
VIDEO_PAGE = 'https://puppetlabs.com/puppetconf-2015-videos-and-presentations' | ||
|
||
def main(): | ||
r = requests.get(VIDEO_PAGE) | ||
tree = html.fromstring(r.text) | ||
links = [] | ||
for item in tree.iterlinks(): | ||
element, attrib, link, pos = item | ||
if not link.startswith('https://puppetlabs.com/presentations/'): | ||
continue | ||
links.append(link) | ||
print("# Found %d links" % len(links)) | ||
for link in links: | ||
do_link(link) | ||
|
||
def do_link(link): | ||
r = requests.get(link) | ||
tree = html.fromstring(r.text) | ||
for item in tree.xpath('//iframe'): | ||
if 'src' in item.attrib and 'youtube.com' in item.attrib['src']: | ||
print(item.attrib['src']) | ||
|
||
if __name__ == "__main__": | ||
main() |