Created
August 10, 2008 13:33
-
-
Save qingfeng/4745 to your computer and use it in GitHub Desktop.
Download youku flv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
from glob import glob | |
for fname in glob('*.flv'): | |
print fname | |
mp4fname=fname.replace(".flv","") | |
cmd='~/Desktop/ffmpeg -i %s -ar 22050 %s.mp4'%(fname,mp4fname) | |
os.system(cmd) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
for r in open('down.log'): | |
print r | |
print r.strip().split(' ') | |
url,mp4fname=r.strip().split(' ') | |
downfname=os.path.basename(url) | |
cmd='curl -o %s-#1.flv %s'%(mp4fname,url) | |
os.system(cmd) | |
#cmd2='~/Desktop/ffmpeg -i %s -ar 22050 %s.mp4'%(downfname,mp4fname) | |
#os.system(cmd2) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
""" | |
youku.py | |
Created by QingFeng on 2008-05-19. | |
Copyright (c) 2008 QingFeng. All rights reserved. | |
""" | |
import urllib2 | |
import re | |
import os | |
def runregx(url,regx): | |
"""get tuple by regx from html""" | |
html=urllib2.urlopen(url).read() | |
c=re.compile(regx) | |
return c.findall(html) | |
class Youku(object): | |
"""Youku video""" | |
def __init__(self, url): | |
super(Youku, self).__init__() | |
self.url = url | |
def getVideoId(self): | |
videoId_regex=r'var videoId="(.*)";' | |
video_Id=runregx(self.url,videoId_regex) | |
if len(video_Id)==0: | |
raise "Error video_Id" | |
return video_Id[0] | |
videoId=property(getVideoId) | |
def getFid(self): | |
""" | |
http://v.youku.com/v_playlist/cd00f438639o9p1.html -> f438639o9p1 | |
""" | |
return os.path.basename(self.url).replace("cd00","").replace(".html","") | |
fid=property(getFid) | |
def getFname(self,vid,fid): | |
url='http://v.youku.com/v/playlistsummary/vid/%s/url/%s?__rt=1&__ro=video_show_summary'%(vid,fid) | |
fname_regex=r'''<a title=".*" href="javascript:sendVideoLink\('.*','(.*)'\);" charset=".*">.*</a>''' | |
fname=runregx(url,fname_regex) | |
if len(fname)==0: | |
raise "Error fname" | |
return fname[0] | |
fname=property(getFname) | |
def getFlv(self): | |
vid=self.getVideoId() | |
#print "video_Id",vid | |
fid=self.getFid() | |
#print "fid",fid | |
fname=self.getFname(vid,fid) | |
#print "fname",fname | |
fname=fname.replace('0200010700','020001070[0-6]') | |
return "http://60.217.252.21/%s.flv"%fname | |
downurl=property(getFlv) | |
def getXunYiCao(): | |
"""薰衣草的全部下载地址""" | |
url='http://www.youku.com/playlist_show/id_438639.html' | |
regex=r'<li><h1><a href="(.*)" alt=".*" title=".*" target="video">(.*)</a> <span class="num">.*</span></h1></li>' | |
for vurl,vname in runregx(url,regex): | |
yk=Youku(vurl) | |
print yk.downurl,vname | |
import unittest | |
class YoukuTests(unittest.TestCase): | |
def setUp(self): | |
self.youku=Youku('http://v.youku.com/v_playlist/cd00f438639o9p1.html') | |
def test_getVideoId(self): | |
self.assertEqual(self.youku.videoId,'1572871') | |
def test_getFid(self): | |
self.assertEqual(self.youku.fid,'f438639o9p1') | |
def test_getFlv(self): | |
self.assertEqual(self.youku.downurl,'http://60.217.252.21/020001070[0-6]4794EB7E011D00789A3FBC3DF8BD-ADA1-D18E-2A7A-D6898634D690.flv') | |
def test_XunYiCao(self): | |
getXunYiCao() | |
if __name__ == '__main__': | |
unittest.main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment