jperla / stvp-videopodcast

Python scripts for generating a video podcast from the Fair Use of Stanford Technology Ventures Programs videos

This URL has Read+Write access

Joseph Perla @ amazon (author)
Sat Apr 05 12:22:21 -0700 2008
stvp-videopodcast / generate_feed.py
100644 67 lines (55 sloc) 2.171 kb
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import os
import datetime
import PyRSS2Gen
 
def get_videos():
    import shelve
    import random
    s = shelve.open('shelf.videos')
    ids = s.keys()
    #only get the ones that have been transcoded for iphone (mp4)
    ids = [id for id in ids if os.path.exists('/mnt/stvp/transcoded/%s.mp4' % id)]
    random.shuffle(ids)
    return [s[id] for id in ids]
 
 
 
def make_item(video):
    url = 'http://static.ivycall.com/stvp/transcoded/%s.mp4' % video['id']
    filesize = os.stat('/mnt/stvp/transcoded/%s.mp4' % video['id'])[6]
    item = PyRSS2Gen.RSSItem(
        title = '%s: %s' % (video['who'], video['title']),
        link = 'http://edcorner.stanford.edu/authorMaterialInfo.html?mid=%s' % video['id'],
        enclosure = PyRSS2Gen.Enclosure(url, filesize, 'video/mp4'),
        description = video['description'],
        guid = PyRSS2Gen.Guid('http://edcorner.stanford.edu/%s' % video['id']),
        pubDate = datetime.datetime.strptime(video['date'], '%Y-%m-%d'))
    return item
 
def make_rss(videos):
    rss = PyRSS2Gen.RSS2(
        title = 'Entrepreneurial Thought Leaders Videos (by Ivy Call)',
        link = 'http://www.ivycall.com/stvp/',
        description = '''Stanford Technology Ventures Program brings the world the Entrepreneurial Thought Leaders Series. The Entrepreneurial Thought Leaders lecture series takes place every Wednesday during the academic quarters.''',
        lastBuildDate = datetime.datetime.now(),
        items = [make_item(video) for video in videos])
    return rss
 
def sort_by_date_then_id(videos):
    videos = list(videos)
    def date_then_id(video, other):
        d1 = video['date']
        d2 = other['date']
        if d1 > d2:
            return -1
        elif d2 > d1:
            return 1
        else:
            i1 = video['id']
            i2 = other['id']
            if i1 > i2:
                return -1
            elif i2 > i1:
                return 1
            else:
                raise Exception('sorting same file?')
    videos.sort(date_then_id)
    return videos
 
videos = get_videos()
videos = sort_by_date_then_id(videos)
 
 
rss = make_rss(videos)
 
rss.write_xml(open('stvp.xml', 'w'))