rpms/metacafe-dl/F-8 index.html, 1.1, 1.2 metacafe-dl, 1.1, 1.2 metacafe-dl.spec, 1.1, 1.2
Rafał Psota (rafalzaq)
fedora-extras-commits at redhat.com
Thu Jul 31 15:15:16 UTC 2008
Author: rafalzaq
Update of /cvs/extras/rpms/metacafe-dl/F-8
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv9969
Modified Files:
index.html metacafe-dl metacafe-dl.spec
Log Message:
update to 2008.07.23
Index: index.html
===================================================================
RCS file: /cvs/extras/rpms/metacafe-dl/F-8/index.html,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- index.html 20 Jan 2008 22:13:57 -0000 1.1
+++ index.html 31 Jul 2008 15:14:46 -0000 1.2
@@ -46,7 +46,7 @@
from metacafe.com, based on the code of
<a href="http://www.arrakis.es/~rggi3/youtube-dl/">youtube-dl</a>. Hence,
it has the same requirements and features, and its syntax is very similar.
-The latest version is <strong>2007.10.09</strong>. It's also licensed under
+The latest version is <strong>2008.07.23</strong>. It's also licensed under
the MIT License.</p>
<p>As with <em>youtube-dl</em>, I'll try to keep it updated if metacafe.com
@@ -131,11 +131,11 @@
Target As</em> or <em>Save Link As</em>, depending on the web browser you
are using.</p>
-<p><a href="metacafe-dl">2007.10.09</a></p>
+<p><a href="metacafe-dl">2008.07.23</a></p>
<ul>
- <li><strong>MD5</strong>: 69348e455f70b048b8db1263b35f16c2</li>
- <li><strong>SHA1</strong>: 766e17c0cee0d3416d7120b4fc7397ce87e74ea7</li>
- <li><strong>SHA256</strong>: 44da4e8f6dc1b250f354e8159199252782b2c847df9face30feb92e66a5a88ce</li>
+ <li><strong>MD5</strong>: 0dae19883b0e13286a1fa543751a242f</li>
+ <li><strong>SHA1</strong>: 70bba7248701728e2f69ddb2cf9dae13501167a5</li>
+ <li><strong>SHA256</strong>: d7826ab9506d73904f16a6e1110af7607e96ce20d311c5d2b3b746b18af64ee5</li>
</ul>
<p id="copyright">Copyright © 2006-2007 Ricardo Garcia Gonzalez</p>
Index: metacafe-dl
===================================================================
RCS file: /cvs/extras/rpms/metacafe-dl/F-8/metacafe-dl,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- metacafe-dl 20 Jan 2008 22:13:57 -0000 1.1
+++ metacafe-dl 31 Jul 2008 15:14:46 -0000 1.2
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
-# Copyright (c) 2006-2007 Ricardo Garcia Gonzalez
+# Copyright (c) 2006-2008 Ricardo Garcia Gonzalez
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
@@ -35,14 +35,18 @@
import urllib2
# Global constants
+const_1k = 1024
+const_initial_block_size = 10 * const_1k
+const_max_block_size = 4 * const_1k * const_1k
+const_epsilon = 0.0001
+const_timeout = 120
+
const_video_url_re = re.compile(r'(?:http://)?(?:www\.)?metacafe\.com/watch/([^/]+)/([^/]+/)?.*')
const_normalized_url_str = 'http://www.metacafe.com/watch/%s/'
const_disclaimer_url = 'http://www.metacafe.com/disclaimer'
const_age_post_data = r'allowAdultContent=1&submit=Continue+-+I%27m+over+18'
-const_video_mediaurl_re = re.compile(r'&mediaURL=([^&]+)&', re.M)
-const_1k = 1024
-const_initial_block_size = 10 * const_1k
-const_epsilon = 0.0001
+const_video_mediaurl_re = re.compile(r'"mediaURL":"(http.*?\.flv)"', re.M)
+const_video_gdakey_re = re.compile(r'"gdaKey":"(.*?)"', re.M)
# Print error message, followed by standard advice information, and then exit
def error_advice_exit(error_text):
@@ -60,20 +64,23 @@
sys.exit('\n')
# Wrapper to create custom requests with typical headers
-def request_create(url, data=None):
+def request_create(url, extra_headers, post_data):
retval = urllib2.Request(url)
- if data is not None:
- retval.add_data(data)
+ if post_data is not None:
+ retval.add_data(post_data)
# Try to mimic Firefox, at least a little bit
- retval.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0')
+ retval.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14')
retval.add_header('Accept-Charset', 'ISO-8859-1,utf-8;q=0.7,*;q=0.7')
retval.add_header('Accept', 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5')
retval.add_header('Accept-Language', 'en-us,en;q=0.5')
+ if extra_headers is not None:
+ for header in extra_headers:
+ retval.add_header(header[0], header[1])
return retval
# Perform a request, process headers and return response
-def perform_request(url, data=None):
- request = request_create(url, data)
+def perform_request(url, headers=None, data=None):
+ request = request_create(url, headers, data)
response = urllib2.urlopen(request)
return response
@@ -88,7 +95,7 @@
def download_step(return_data_flag, step_title, step_error, url, post_data=None):
try:
cond_print('%s... ' % step_title)
- data = perform_request(url, post_data).read()
+ data = perform_request(url, data=post_data).read()
cond_print('done.\n')
if return_data_flag:
return data
@@ -125,12 +132,12 @@
dif = after - before
if dif < const_epsilon:
return int(new_max)
- rate = bytes / dif
+ rate = bytes / dif / 2.0
if rate > new_max:
return int(new_max)
if rate < new_min:
return int(new_min)
- return int(rate)
+ return min(int(rate), const_max_block_size)
# Get optimum 1k exponent to represent a number of bytes
def optimum_k_exp(num_bytes):
@@ -146,12 +153,22 @@
exp = optimum_k_exp(num_bytes)
suffix = 'bkMGTPEZY'[exp]
if exp == 0:
- return '%s%s' % (num_bytes, suffix)
+ return '%s%s' % (long(round(num_bytes)), suffix)
converted = float(num_bytes) / float(const_1k**exp)
return '%.2f%s' % (converted, suffix)
except IndexError:
sys.exit('Error: internal error formatting number of bytes.')
+# Returns a long integer from a string representing a byte size
+def parse_bytes(bytestr):
+ regexp = re.compile(r'(?i)^(\d+(?:\.\d+)?)([kMGTPEZY]?)$')
+ matchobj = regexp.match(bytestr)
+ if matchobj is None:
+ return None
+ number = float(matchobj.group(1))
+ multiplier = 1024.0 ** 'bkmgtpezy'.index(matchobj.group(2).lower())
+ return long(round(number * multiplier))
+
# Calculate ETA and return it in string format as MM:SS
def calc_eta(start, now, total, current):
dif = now - start
@@ -159,22 +176,28 @@
return '--:--'
rate = float(current) / dif
eta = long((total - current) / rate)
- eta_mins = eta / 60
- eta_secs = eta % 60
+ (eta_mins, eta_secs) = divmod(eta, 60)
if eta_mins > 99:
return '--:--'
return '%02d:%02d' % (eta_mins, eta_secs)
-# Calculate speed and return it in string format
+# Calculate speed and return it in bytes per second, or None
def calc_speed(start, now, bytes):
dif = now - start
if bytes == 0 or dif < const_epsilon:
+ return None
+ return (float(bytes) / dif)
+
+# Convert speed to string
+def speed_to_str(bytespersec):
+ if bytespersec is None:
return 'N/A b'
- return format_bytes(float(bytes) / dif)
+ return format_bytes(bytespersec)
+
# Create the command line options parser and parse command line
cmdl_usage = 'usage: %prog [options] video_url'
-cmdl_version = '2007.10.09'
+cmdl_version = '2008.07.23'
cmdl_parser = optparse.OptionParser(usage=cmdl_usage, version=cmdl_version, conflict_handler='resolve')
cmdl_parser.add_option('-h', '--help', action='help', help='print this help text and exit')
cmdl_parser.add_option('-v', '--version', action='version', help='print program version and exit')
@@ -183,8 +206,12 @@
cmdl_parser.add_option('-s', '--simulate', action='store_true', dest='simulate', help='do not download video')
cmdl_parser.add_option('-t', '--title', action='store_true', dest='use_title', help='use title in file name')
cmdl_parser.add_option('-g', '--get-url', action='store_true', dest='get_url', help='print final video URL only')
+cmdl_parser.add_option('-r', '--rate-limit', action='store', dest='rate_limit', help='download rate limit (e.g. 50k or 44.6m)')
(cmdl_opts, cmdl_args) = cmdl_parser.parse_args()
+# Set socket timeout
+socket.setdefaulttimeout(const_timeout)
+
# Get video URL
if len(cmdl_args) != 1:
cmdl_parser.print_help()
@@ -209,6 +236,13 @@
if cmdl_opts.quiet and cmdl_opts.get_url:
sys.exit('Error: cannot be quiet and print final URL at the same time.')
+# Incorrect option formatting
+rate_limit = None
+if cmdl_opts.rate_limit is not None:
+ rate_limit = parse_bytes(cmdl_opts.rate_limit)
+ if rate_limit is None:
+ sys.exit('ERROR: invalid download rate limit specified.')
+
# Get output file name
if cmdl_opts.outfile is None:
if cmdl_opts.use_title:
@@ -245,12 +279,17 @@
# Retrieve real video URL
video_url_real = extract_step('Extracting real video URL', 'unable to extract real video URL', const_video_mediaurl_re, video_webpage)
+video_url_real = video_url_real.replace('\\', '')
+
+# Retrieve gdaKey parameter
+video_gdakey = extract_step('Extracting "gdaKey" parameter', 'unable to extract "gdaKey" parameter', const_video_gdakey_re, video_webpage)
+video_url_real = '%s?__gda__=%s' % (video_url_real, video_gdakey)
# Retrieve video data
try:
cond_print('Requesting video file... ')
video_data = perform_request(video_url_real)
- cond_print('done\n')
+ cond_print('done.\n')
cond_print('Video data found at %s\n' % video_data.geturl())
if cmdl_opts.get_url:
@@ -279,7 +318,8 @@
percent_str = '---.-'
eta_str = '--:--'
counter = format_bytes(byte_counter)
- speed_str = calc_speed(start_time, time.time(), byte_counter)
+ speed = calc_speed(start_time, time.time(), byte_counter)
+ speed_str = speed_to_str(speed)
cond_print('\rRetrieving video data: %5s%% (%8s of %s) at %8s/s ETA %s ' % (percent_str, counter, video_len_str, speed_str, eta_str))
before = time.time()
@@ -292,6 +332,14 @@
video_file.write(video_block)
block_size = new_block_size(before, after, dl_bytes)
+ if rate_limit is not None:
+ if block_size > rate_limit:
+ block_size = rate_limit / 2
+
+ speed = calc_speed(start_time, time.time(), byte_counter)
+ if speed is not None and speed > const_epsilon and speed > rate_limit:
+ time.sleep((byte_counter - rate_limit * (time.time() - start_time)) / rate_limit)
+
if video_len is not None and byte_counter != video_len:
error_advice_exit('server did not send the expected ammount of data')
Index: metacafe-dl.spec
===================================================================
RCS file: /cvs/extras/rpms/metacafe-dl/F-8/metacafe-dl.spec,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- metacafe-dl.spec 20 Jan 2008 22:13:57 -0000 1.1
+++ metacafe-dl.spec 31 Jul 2008 15:14:46 -0000 1.2
@@ -1,5 +1,5 @@
Name: metacafe-dl
-Version: 2007.10.09
+Version: 2008.07.23
Release: 1%{?dist}
Summary: Command-line program to download videos from metacafe.com
Summary(pl): Tekstowy program do pobierania filmów z metacafe.com
@@ -50,6 +50,8 @@
%changelog
+* Thu Jul 31 2008 RafaÅ Psota <rafalzaq at gmail.com> 2008.07.23-1
+- update to 2008.07.23
* Sat Jan 19 2008 RafaÅ Psota <rafalzaq at gmail.com> 2007.10.09-1
- fixed version and description tags
- removed COPYING file
More information about the fedora-extras-commits
mailing list