Skip to content

Instantly share code, notes, and snippets.

@intijk
Created September 18, 2012 15:06
Show Gist options
  • Save intijk/3743633 to your computer and use it in GitHub Desktop.
Save intijk/3743633 to your computer and use it in GitHub Desktop.
Grab the music file from your chrome cache.
#!/usr/bin/env python2
#encoding=utf8
#first, you should go some online music website, like xiami, to listen music until the cache download finish. #Then run this command, input the artist name and song name.
import pyid3lib
import glob
import os
#cacheDir= os.environ['HOME'] + '/.cache/google-chrome/Default/Cache/'
cacheDir= os.environ['HOME'] + '/.cache/chromium/Default/Cache/'
#make a list sort by time inversely
fl = sorted(glob.glob(cacheDir + 'f*'), key=lambda f:os.stat(f).st_mtime, reverse=True)
mf=''
for f in fl:
#find the first one whose size > 1MB
if os.stat(f).st_size > 1024*1024:
mf=f
break;
artistName=raw_input("Please input artist's name:")
songName=raw_input("Please input song's name:")
targetDir=os.environ['HOME'] + "/music/" + artistName;
targetFile=targetDir + "/" + songName + ".mp3"
print targetDir
print targetFile
os.system("mkdir -p " + targetDir)
os.system("cp " + f + " " + targetFile)
#add Tag
cmd="mid3v2 " + targetFile + " -a " + artistName
os.system("mid3v2 " + targetFile + " -a " + artistName)
os.system("mid3v2 " + targetFile + " -t " + songName)
os.system("mid3v2 " + targetFile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment