Script para descargar música y álbumes completos de GoEar desde Windows (PowerShell)
ACTUALIZACIÓN (19/02/2010): El Script ha sido modificado y vuelve a funcionar perfectamente ;)
Hace unos días publicaba un pequeño script Bash para descargar música de GoEar. Hoy os traigo un porte de ese mismo script a PowerShell, que vendría a ser el Bash de Windows pero no se parecen en nada :P
De paso le he metido esteroides al script, así que si lo invocáis “script UrlDeGoEar” se descargará el fichero exactamente igual que su versión de Bash. Sin embargo, si lo invocáis “script palabras clave de lo que queráis” realizará una búsqueda en GoEar y se bajará el mp3 si encuentra alguna coincidencia :D
Además, si le pasáis una url de gracenote, como esta: http://www.gracenote.com/search/album_details.php?tui_id=00c6abba5df653cd encontrará las canciones, las buscará en GoEar y se las bajará :D
function IsURL([string]$data) { return ($data.startswith("http")) }
function CreateSearchUrl([string]$data) { return "http://www.goear.com/search.php?q=$data".Replace(' ','+') }
function PrintBanner()
{
Write-Host "GoEar Downloader for PowerShell - v0.1"
Write-Host "Pablo Carballude - 20/01/2009"
Write-Host ""
}
function DownloadFileFromURL([string]$url)
{
$fileid = $url.Split('/')[4]
echo "Looking for the mp3..."
$xmlurl = "http://www.goear.com/localtrackhost.php?f=$fileid"
$webclient = new-object net.webclient
$webclient.headers.Add("Content-Type", "text/xml; charset=utf-8")
$webclient.DownloadString($xmlurl) > temp.txt
$chunks = (get-content temp.txt | select-string ".mp3").ToString().Trim().Split("=")
$mp3url = $chunks[3].Split("`"")[1]
$artist = $chunks[5].Split("`"")[1]
$title = $chunks[6].Split("`"")[1]
echo "Starting the download of $title..."
[void][reflection.assembly]::LoadWithPartialName("microsoft.visualbasic")
(New-Object Microsoft.VisualBasic.Devices.Network).DownloadFile($mp3url, $artist+"-"+$title+".mp3", '', '', $true, 500,$true, 'DoNothing')
echo "File downloaded :)"
}
function ProcessFileLine([string]$line)
{
$data = $line.Split('=`"', [StringSplitOptions]::RemoveEmptyEntries)[3]
echo "http://www.goear.com/$data"
DownloadFileFromURL("http://www.goear.com/$data")
}
function LookForFile([string]$data)
{
echo "Searching on GoEar..."
$url = CreateSearchURL($data)
(new-object net.webclient).DownloadString($url) > temp.txt
$text = get-content temp.txt | select-string "href=`"listen"
foreach($line in ([string]$text).Split("<")){
if($line.startswith("a title")){
ProcessFileLine($line)
rm temp.txt
return
}
}
echo "Sorry, I can't find the file :("
rm temp.txt
}
function DownloadFilesListedOnGracenoteWeb([string]$url)
{
$webclient = new-object net.webclient
$webclient.headers.Add("Content-Type", "text/xml; charset=utf-8")
$text = $webclient.DownloadString($url)
$text > temp.txt
$artist = get-content temp.txt | select-string "<h1 id=`"title`">"
$artist = $artist.ToString().Trim().substring(15).Split("<")[0]
$text = get-content temp.txt | select-string "class=`"track_name`""
foreach($line in ([string]$text).Split("<")){
if($line.startswith("div class=")){
echo ""
$title = $line.substring(23)
echo "Detected song $title"
$tmp = $title + " " + $artist
LookForFile($tmp)
}
}
echo "All done :)"
}
PrintBanner
if ($args[0].contains("http://www.goear.com")) { DownloadFileFromURL($args[0])}
else { if ($args[0].contains("http://www.gracenote.com")) { DownloadFilesListedOnGracenoteWeb($args[0]) }
else { LookForFile($args) } }
# This was the old path
# $xmlurl = "http://www.goear.com/files/xmlfiles/"+$fileid[0]+"/secm"+$fileid+".xml"


TABLA - FUENTES - FONTS
Disculpen las Molestias

No hay comentarios:
Publicar un comentario