python-ox/ox/web/filmsdivision.py

40 lines
1.4 KiB
Python
Raw Permalink Normal View History

2012-08-21 07:55:16 +00:00
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
import re
import string
import subprocess
import ox
import os
2012-08-21 07:55:16 +00:00
def get_ids():
result = []
for i in string.ascii_uppercase:
2012-08-21 07:55:16 +00:00
url = "http://www.filmsdivision.org/search.php?title=%s" % i
data = ox.cache.read_url(url)
2024-09-11 21:52:01 +00:00
links = re.compile(r'view_video.php\?movId=(.*?)[\'"]', re.DOTALL).findall(data)
2012-08-21 07:55:16 +00:00
result += links
return list(set(result))
def get_data(id):
result = {}
url = "http://www.filmsdivision.org/view_video.php?movId=%s" % id
data = ox.cache.read_url(url)
result['title'] = re.compile('<td.*?class="vdoheadtxt".*?>(.*?)</td>').findall(data)[0]
2024-09-11 21:52:01 +00:00
result['year'] = re.compile(r'Release: (\d{4})').findall(data)[0]
result['duration'] = int(re.compile(r'Duration: (\d+)mins').findall(data)[0]) * 60
result['producer'] = re.compile(r'Producer: (.*?)\t').findall(data)[0].strip()
2012-08-21 07:55:16 +00:00
if 'Director:' in data:
2024-09-11 21:52:01 +00:00
result['director'] = re.compile(r'Director: (.*?)\t').findall(data)[0].strip()
2012-08-21 07:55:16 +00:00
else:
result['director'] = "Unknown Director"
2024-09-11 21:52:01 +00:00
result['url'] = re.compile(r'value="(.*?.wmv)"').findall(data)[0]
2012-08-21 07:55:16 +00:00
return result
def download_video(url, filename):
dirname = os.path.dirname(filename)
if not os.path.exists(dirname):
os.makedirs(dirname)
2024-09-11 21:52:01 +00:00
p = subprocess.Popen(['gst-launch', 'mmssrc', 'location=%s' % url, '!', 'filesink', 'location=' % filename])
2012-08-21 07:55:16 +00:00
p.wait()
return p.returncode == 0