Merge pull request #8 from soimort/master

merge
This commit is contained in:
zhuhuotui 2013-05-09 05:46:43 -07:00
commit f7fb645b07
5 changed files with 56 additions and 9 deletions

View File

@ -235,7 +235,7 @@ def url_save(url, filepath, bar, refer = None, is_part = False, faker = False):
if bar:
bar.update_received(len(buffer))
assert received == os.path.getsize(temp_filepath), '%s == %s == %s' % (received, os.path.getsize(temp_filepath))
assert received == os.path.getsize(temp_filepath), '%s == %s == %s' % (received, os.path.getsize(temp_filepath), temp_filepath)
if os.access(filepath, os.W_OK):
os.remove(filepath) # on Windows rename could fail if destination filepath exists
@ -444,8 +444,8 @@ def download_urls(urls, title, ext, total_size, output_dir = '.', refer = None,
except:
from .processor.ffmpeg import has_ffmpeg_installed
if has_ffmpeg_installed():
from .processor.ffmpeg import ffmpeg_concat_mp4_to_mpg
ffmpeg_concat_mp4_to_mpg(parts, os.path.join(output_dir, title + '.mp4'))
from .processor.ffmpeg import ffmpeg_concat_mp4_to_mp4
ffmpeg_concat_mp4_to_mp4(parts, os.path.join(output_dir, title + '.mp4'))
for part in parts:
os.remove(part)
else:

View File

@ -7,9 +7,9 @@ from ..common import *
def mixcloud_download(url, output_dir = '.', merge = True, info_only = False):
html = get_html(url)
title = r1(r'<meta property="og:title" content="([^"]*)"', html)
url = r1("data-preview-url=\"([^\"]+)\"", html)
preview_url = r1("data-preview-url=\"([^\"]+)\"", html)
url = re.sub(r'previews', r'cloudcasts/originals', url)
url = re.sub(r'previews', r'cloudcasts/originals', preview_url)
for i in range(10, 30):
url = re.sub(r'stream[^.]*', r'stream' + str(i), url)
@ -19,6 +19,20 @@ def mixcloud_download(url, output_dir = '.', merge = True, info_only = False):
except:
continue
try:
type
except:
url = re.sub('cloudcasts/originals', r'cloudcasts/m4a/64', url)
url = re.sub('.mp3', '.m4a', url)
for i in range(10, 30):
url = re.sub(r'stream[^.]*', r'stream' + str(i), url)
try:
type, ext, size = url_info(url)
break
except:
continue
print_info(site_info, title, type, size)
if not info_only:
download_urls([url], title, ext, size, output_dir, merge = merge)

View File

@ -22,12 +22,17 @@ def tudou_download_by_iid(iid, title, output_dir = '.', merge = True, info_only
#url_save(url, filepath, bar):
download_urls([url], title, ext, total_size = None, output_dir = output_dir, merge = merge)
def tudou_download_by_id(id, title, output_dir = '.', merge = True):
def tudou_download_by_id(id, title, output_dir = '.', merge = True, info_only = False):
html = get_html('http://www.tudou.com/programs/view/%s/' % id)
iid = r1(r'iid\s*=\s*(\S+)', html)
tudou_download_by_iid(iid, title, output_dir = output_dir, merge = merge)
iid = r1(r'iid\s*[:=]\s*(\S+)', html)
tudou_download_by_iid(iid, title, output_dir = output_dir, merge = merge, info_only = info_only)
def tudou_download(url, output_dir = '.', merge = True, info_only = False):
# Embedded player
id = r1(r'http://www.tudou.com/v/([^/]+)/', url)
if id:
return tudou_download_by_id(id, title="", info_only=info_only)
html = get_decoded_html(url)
title = r1(r'kw\s*[:=]\s*[\'\"]([^\']+?)[\'\"]', html)

View File

@ -96,3 +96,31 @@ def ffmpeg_concat_flv_to_mp4(files, output = 'output.mp4'):
return True
else:
raise
def ffmpeg_concat_mp4_to_mp4(files, output = 'output.mp4'):
for file in files:
if os.path.isfile(file):
params = [FFMPEG, '-i']
params.append(file)
params += ['-c', 'copy', '-f', 'mpegts', '-bsf:v', 'h264_mp4toannexb']
params.append(file + '.ts')
subprocess.call(params)
params = [FFMPEG, '-i']
params.append('concat:')
for file in files:
f = file + '.ts'
if os.path.isfile(f):
params[-1] += f + '|'
if FFMPEG == 'avconv':
params += ['-c', 'copy', output]
else:
params += ['-c', 'copy', '-absf', 'aac_adtstoasc', output]
if subprocess.call(params) == 0:
for file in files:
os.remove(file + '.ts')
return True
else:
raise

View File

@ -19,7 +19,7 @@ class YouGetTests(unittest.TestCase):
def test_jpopsuki(self):
test_urls([
"http://jpopsuki.tv/video/Dragon-Ash---Run-to-the-Sun/8ad7aec604badd0b0798cd999b63ae17",
#"http://jpopsuki.tv/video/Dragon-Ash---Run-to-the-Sun/8ad7aec604badd0b0798cd999b63ae17",
])
def test_mixcloud(self):