-
Notifications
You must be signed in to change notification settings - Fork 73
/
puppetconf_to_youtube.py
executable file
·46 lines (39 loc) · 1.21 KB
/
puppetconf_to_youtube.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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()