def __init__(self):

        #Mac and hostname are used to identify our client.
        self.mac = hex(getmac())[2:-1]
        self.mac = ':'.join([self.mac[x:x + 2] for x in range(0, 10, 2)])

        hostname = gethostname()

        #Pre-filled protobuff instances.
        #These are used to fill in new instances.
        #Named scheme is '[protocol name]_filled'

        self.upload_auth_filled = metadata_pb2.UploadAuth()
        self.upload_auth_filled.address = self.mac
        self.upload_auth_filled.hostname = hostname

        self.client_state_filled = metadata_pb2.ClientState()
        self.client_state_filled.address = self.mac

        self.upload_auth_response_filled = metadata_pb2.UploadAuthResponse()

        self.client_state_response_filled = metadata_pb2.ClientStateResponse()

        self.metadata_request_filled = metadata_pb2.MetadataRequest()
        self.metadata_request_filled.address = self.mac

        self.metadata_response_filled = metadata_pb2.MetadataResponse()

        #Service name mapped to url.
        self.pb_services = {
            "upload_auth": 'upauth',
            "client_state": 'clientstate',
            "metadata": 'metadata?version=1'
        }
示例#2
0
    if "date" in audio: track.year = int(audio["date"][0].split("-")[0])
    if "bpm" in audio: track.beatsPerMinute = int(audio["bpm"][0])

    if "tracknumber" in audio:
        tracknumber = audio["tracknumber"][0].split("/")
        track.track = int(tracknumber[0])
        if len(tracknumber) == 2:
            track.totalTracks = int(tracknumber[1])

    if "discnumber" in audio:
        discnumber = audio["discnumber"][0].split("/")
        track.disc = int(discnumber[0])
        if len(discnumber) == 2:
            track.totalDiscs = int(discnumber[1])

metadataresp = metadata_pb2.MetadataResponse()
metadataresp.ParseFromString(protopost("metadata?version=1", metadata))
if options.verbose: print metadataresp

import time
import json
jumper = httplib.HTTPConnection('uploadsj.clients.google.com')

for song in metadataresp.response.uploads:
    filename = filemap[song.id]
    audio = MP3(filename, ID3=EasyID3)
    print os.path.basename(filename)
    if options.verbose: print song
    #Only ServerId is necessary to upload the file
    #At time of writing, the other attributes seem to be ignored
    inlined = {