|
1 | 1 | #! /usr/bin/python
|
2 | 2 |
|
| 3 | +from __future__ import print_function |
3 | 4 | from PIL import Image
|
4 | 5 | from PIL import ImageFont
|
5 | 6 | from PIL import ImageDraw
|
|
28 | 29 | # FIXME. Do something
|
29 | 30 | sys.exit(1)
|
30 | 31 |
|
31 |
| -print "Checking if we have the schedule..." |
| 32 | +print("Checking if we have the schedule...") |
32 | 33 | if os.path.isfile(os.path.basename(penta_url)):
|
33 | 34 | penta = os.path.basename(penta_url)
|
34 | 35 | else:
|
35 |
| - print "Getting the schedule..." |
| 36 | + print("Getting the schedule...") |
36 | 37 | penta = wget.download(penta_url)
|
37 | 38 |
|
38 |
| -print "Parsing the schedule file..." |
| 39 | +print("Parsing the schedule file...") |
39 | 40 | pentaparse = ET.parse(penta).getroot()
|
40 | 41 | # FIXME Either keep the downloaded penta xml file and make sure it doesn't get downloaded again, or throw it out and always get a fresh one.
|
41 | 42 |
|
42 |
| -print "Finding the talk to process..." |
| 43 | +print("Finding the talk to process...") |
43 | 44 | talk = pentaparse.find(".//event[@id='"+data['event_id']+"']")
|
44 | 45 |
|
45 |
| -print "Creating relevant file names for this talk..." |
| 46 | +print("Creating relevant file names for this talk...") |
46 | 47 | title = talk.find('title').text
|
47 | 48 | track = talk.find('track').text
|
48 | 49 | slug_track = slugify(track)
|
|
60 | 61 | postrolltsname = postrollbasename+ '.ts'
|
61 | 62 | finalcut = outdir+ videobasename+ '.mp4'
|
62 | 63 |
|
63 |
| -print "Creating tmpdir" |
| 64 | +print("Creating tmpdir") |
64 | 65 | try:
|
65 |
| - os.makedirs(tmpdir, 0755) |
| 66 | + os.makedirs(tmpdir, 0o755) |
66 | 67 | except:
|
67 | 68 | pass
|
68 | 69 |
|
69 |
| -print "Creating outdir..." |
| 70 | +print("Creating outdir...") |
70 | 71 | try:
|
71 |
| - os.makedirs(outdir, 0755) |
| 72 | + os.makedirs(outdir, 0o755) |
72 | 73 | except:
|
73 | 74 | pass
|
74 | 75 |
|
75 |
| -print "Getting list of speakers for this talk..." |
| 76 | +print("Getting list of speakers for this talk...") |
76 | 77 | persons = [p.text for p in talk.find('persons')]
|
77 | 78 | personsline = ''
|
78 | 79 | for p in persons:
|
79 | 80 | personsline += p + ' '
|
80 | 81 |
|
81 |
| -print "Grabbing the part of the video we need..." |
| 82 | +print("Grabbing the part of the video we need...") |
82 | 83 | url = data['url'] + "?start=" + data['start'] + "&end=" + data['end']
|
83 | 84 | filename = wget.download(url,out=nakedvideomp4name)
|
84 | 85 |
|
85 |
| -print "Creating custom preroll image from talk metadata..." |
| 86 | +print("Creating custom preroll image from talk metadata...") |
86 | 87 | img = Image.open("preroll.jpg")
|
87 | 88 | draw = ImageDraw.Draw(img)
|
88 | 89 | font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf", 64)
|
89 | 90 | draw.text((0, 0),title,(0,0,0),font=font)
|
90 | 91 | draw.text((0, 100),personsline,(0,0,0),font=font)
|
91 | 92 | img.save(prerollimgname)
|
92 | 93 |
|
93 |
| -print "Processing preroll and postroll images into video..." |
| 94 | +print("Processing preroll and postroll images into video...") |
94 | 95 | subprocess.check_call(['ffmpeg', '-y', '-loop', '1' , '-i', prerollimgname, '-c:v', 'libx264', '-r', '25', '-frames:v', '125', prerolltsname])
|
95 | 96 | subprocess.check_call(['ffmpeg', '-y', '-loop', '1' , '-i', "postroll.jpg", '-c:v', 'libx264', '-r', '25', '-frames:v', '125', postrolltsname])
|
96 | 97 |
|
97 |
| -print "Concatenating preroll, video and postroll..." |
| 98 | +print("Concatenating preroll, video and postroll...") |
98 | 99 | subprocess.check_call(['ffmpeg', '-y', '-i', nakedvideomp4name, '-c', 'copy', nakedvideotsname])
|
99 | 100 | concatcommand = 'ffmpeg -y -f mpegts -i "concat:'+prerolltsname+ '|'+ nakedvideotsname+ '|'+ postrolltsname+'" -c copy -bsf:a aac_adtstoasc '+ finalcut
|
100 | 101 | subprocess.check_call(concatcommand, shell=True)
|
101 | 102 |
|
102 |
| -print "Cleaning up temporary directory..." |
| 103 | +print("Cleaning up temporary directory...") |
103 | 104 | shutil.rmtree(tmpdir)
|
0 commit comments