Exemplo n.º 1
0
import sys, urllib2

sys.path.append('c:/projects')
from pylib.vk import VKCredentialsCollection, VKCrawler

#/2888410/85201601/ffbfec985195431bc5f28690315c06e20da8a24954e66cb035e9ee8f77005c/fb814a2abe/
credentials = VKCredentialsCollection(credentials=[{'api_id': '2888410', 'viewer_id': '85201601', 'secret': 'fb814a2abe', 'sid': 'ffbfec985195431bc5f28690315c06e20da8a24954e66cb035e9ee8f77005c'}])
crawler = VKCrawler(credentials)

folder = ""

def clean_str(s):
    return s.strip().lower()

def clean_filename(s):
    return s.replace('/', '').replace('\\', '').replace('"', "'").replace(":", "-").replace('|', '-').replace('*', '').replace('?', '')

def make_file_name(audio):
    return folder + clean_filename(unicode(audio['artist']))+ ' - ' + clean_filename(unicode(audio['title'])) + ".mp3"

print "folder to save in:"
folder = raw_input()
print "audio to grab:"
song_name = raw_input().lower()
print "okee-dokee, fetching ur music"
options = []
for audio in crawler.get_audio('85201601'):
    if len(song_name) == 0 or clean_str(audio['artist']).find(song_name) > -1 or clean_str(audio['title']).find(song_name) > -1:
        options.append(audio)
print "possible options:"
for index, option in enumerate(options):
Exemplo n.º 2
0
        cache[int(str(file["TSRC"]))] = folder + f
    except KeyError:
        pass
print "tagged!"

credentials = VKCredentialsCollection(
    credentials=[
        {
            "api_id": "2888416",
            "viewer_id": "85201601",
            "secret": "fee76f3fb9",
            "sid": "03a7cb69570208eea0427eaaafda3c231f058192fe8f92a6f794eac08b1a2b",
        }
    ]
)
crawler = VKCrawler(credentials)
audios = [audio for audio in crawler.get_audio("85201601")]
for audio in audios:
    if not audio["aid"] in cache:
        print 'downloading "%s"' % audio["title"]
        url = audio["url"]
        f = urllib2.urlopen(url)
        data = f.read()
        file_name = make_file_name(audio)
        save_file = open(file_name, "wb")
        save_file.write(data)
        save_file = MP3(file_name)
        save_file["TSRC"] = TSRC(encoding=3, text=[str(audio["aid"])])
        save_file.save()
    else:
        new_name = make_file_name(audio)