最近在coursera里面学习课程。
安装了android的版本,下载了很多视频,就不想在pc机器上下载了。
因此,就想把手机中中下载的视频抓取到mac上。
但是在sdcard目录下找不到 coursera的目录,通过logcat,发现课件视频都存在于
/data/data/org.coursera.android/files/courkitDownloadedVideos/
如果是root了的手机,啥也别说了。adb pull出来
但是我的手机是非root的。
google后。发现可以adb backup -noapk org.coursera.android 导出backup.ab 参考:How to access data/data folder in Android device?
然后使用android-backup-extractor 去解开ab文件。就可以得到了视频文件了。参考:[GUIDE] How to extract, create or edit android adb backups https://github.com/nelenkov/android-backup-extractor
美中不足的是这些文件的命名是使用的数字命名,所以写了一个dirty and quick 的python脚本。
凑活着用了
import sqlite3
import os
import shutil
import optparse
def rename_coursera(dbdir,filedir,destdir):
if not ( os.path.exists(filedir) ):
print filedir+" is not exist"
return
if not ( os.path.exists(destdir) ):
print filedir+" is not exist"
return
conn = sqlite3.connect(dbdir+'/download-manager-db')
itemconn = sqlite3.connect(dbdir+'/courkit-db')
ic = itemconn.cursor()
c = conn.cursor()
c.execute("SELECT REMOTE_URL,LOCAL_PATH FROM DB_DOWNLOAD WHERE PROGRESS >=96")
res = c.fetchall()
for line in res:
url = line[0]
#sqlstr =
#print sqlstr
ic.execute("SELECT TITLE,NORMAL_X264 FROM DB_ITEM WHERE NORMAL_X264 LIKE ? OR VIDEO540P LIKE ?", [url,url])
item = ic.fetchall()
basename = os.path.basename(line[1])
oldfile = os.path.join(filedir,basename)
if(os.path.exists(oldfile)) and (item.__len__() > 0):
filename = (item[0][0]+".mp4").replace(":","_").replace("/","_")
newfile = os.path.join(destdir,filename)
try:
shutil.move(oldfile,newfile)
print "move %s to %s succeed" %(oldfile,newfile)
except :
print "Error:mv %s %s" %(oldfile,newfile)
else:
print "----do not find title of %s url %s" %(oldfile,url)
def main():
parser=optparse.OptionParser(description="rename all coursera download file by db",prog="rename_coursera",version="0.1",usage="%prog [directory]")
parser.add_option("-b", "--dbdir",
dest="db dir",
help="dir contain db")
parser.add_option("-o", "--olddir",
dest="oldfile dir",
help="dir contain old file")
parser.add_option("-n", "--newdir",
dest="oldfile dir",
help="dir to move to")
(options,arguments)=parser.parse_args()
if len(arguments)==3:
dbdir=arguments[0]
olddir = arguments[1]
newdir = arguments[2]
print "rename %s %s %s" %(dbdir,olddir,newdir)
rename_coursera(dbdir,olddir,newdir)
else:
parser.print_help()
if __name__=="__main__":
main()