You are not logged in.
Hey,
I wrote a little python script and I thought some might like it. It could be improved a lot, but I'm no master python and that's what I managed to create in the meanwhile...
Right now it has 3 functions:
./autotube.py search "beatles let it be"
that would download that video clip from you tube
./autotube.py lastfm-recent
that would search for and download the videos from the the last 10 songs recorded in your last.fm account
./autotube.py lastfm-top
that would search for and download your top 50
mostly the idea is to use it with a plugin to your player, and pass it the now playing title. it will work in the background, filling your hdd with your favorite videos...
the lastfm engine assume your account is the same as the system account you're running, and the saving location is at ~/music/videos (you need to create that).
it doesn't do any conversion or such, but that should be a no problem to add that function.
it takes the first youtube result, which is not always what you'd like but that funny too.
comments / suggestions / anything is very welcome!
it's here under the gpl v.3 oh, and it needs youtube-dl !
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys, urllib, os
from xml.dom import minidom
# set your download location
video_dir = os.environ["HOME"]+"/music/videos"
print "AutoTube 0.5.1 \n"
os.chdir(video_dir)
def get_code(url):
try:
remoteSocket = urllib.urlopen(url)
code = remoteSocket.read()
remoteSocket.close()
return code
except IOError:
return "Couldn't download " + url
def search_and_download(searchTerms):
if os.path.exists(searchTerms + ".flv"):
return "You already have " + searchTerms + ".flv"
print "searching for " + searchTerms
searchFile = open("tmpyoutube", "w")
print "Connecting to YouTube..."
searchFile.write(get_code("http://gdata.youtube.com/feeds/api/videos?vq=" + urllib.quote(searchTerms)))
searchFile.close()
print "Parsing..."
searchDOM = minidom.parse("tmpyoutube")
os.remove("tmpyoutube")
try:
videoID = searchDOM.getElementsByTagName('entry')[0].getElementsByTagName('id')[0].firstChild.data.split('/')[-1]
print videoID
youtubedl = os.system("/usr/bin/youtube-dl 'http://www.youtube.com/watch?v=" + videoID + "'")
os.rename(videoID+".flv", searchTerms+".flv")
return "Downloaded " + searchTerms + ".flv"
except:
return "Search for "+ searchTerms + " found nothing..."
if sys.argv[1] == 'search':
searchTerms = sys.argv[2]
search_and_download(searchTerms)
if sys.argv[1] == 'lastfm-recent':
recentFile = open("tmplastfm", "w")
print "Connecting to last.fm..."
recentFile.write(get_code('http://ws.audioscrobbler.com/2.0/user/'+os.getlogin()+'/recenttracks.rss'))
recentFile.close()
lastDOM = minidom.parse("tmplastfm")
os.remove("tmplastfm")
songs = []
for title in lastDOM.getElementsByTagName('item'):
songs.append(title.getElementsByTagName('title')[0].firstChild.data.replace(u'\u2013 ', ''))
print 'Your recent songs are:'
for song in songs:
print "- " + song.replace(u'\u2013', '-')
print
print "Now starting to download..."
for song in songs:
print search_and_download(song.replace(u'\u2013 ', ''))
print "Done downloading your recent lastfm songs."
if sys.argv[1] == 'lastfm-top':
topFile = open("tmplastfm", "w")
print "Connecting to last.fm..."
topFile.write(get_code('http://ws.audioscrobbler.com/1.0/user/'+os.getlogin()+'/toptracks.txt'))
topFile.close()
topFile = open("tmplastfm")
songs = []
for line in topFile:
songs.append(line.split(',')[-1][:-1])
topFile.close()
os.remove("tmplastfm")
print 'Your top songs are:'
for song in songs:
print "- " + song
print
print "Now starting to download..."
for song in songs:
print search_and_download(song.replace('– ', ''))
print "Done downloading your top lastfm songs."
Yo'av
Last edited by bjesus (2008-12-02 18:00:08)
Offline
May I suggest you to contribute this to ScriptWiki? It would be nice to have all scripts in one place.
Thanks for your work!
Have you Syued today?
Free music for free people! | Earthlings
"Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away." -- A. de Saint-Exupery
Offline
Offline
I hope you don't mind, but I retagged this as Multimedia and Network so people searching by purpose can find it more easily.
archlinux - please read this and this — twice — then ask questions.
--
http://rsontech.net | http://github.com/rson
Offline