예제 #1
0
    def getcontents(self):
        items = []
        try:
            for name in os.listdir(self.dir):
                try:
                    path = os.path.join(self.dir, name)
                    extension = os.path.splitext(path)[1]
                    if os.path.isdir(path) and os.access(
                            path, os.R_OK | os.X_OK):
                        newitem = filesystemdir(self.songdbid, self.basedir,
                                                path)
                        items.append(newitem)
                    elif extension in metadata.getextensions() and os.access(
                            path, os.R_OK):
                        song = hub.request(
                            requests.autoregisterer_queryregistersong(
                                self.songdbid, path))
                        if song:
                            items.append(song)
                except (IOError, OSError):
                    pass
        except OSError:
            return None

        def cmpitem(x, y):
            if isinstance(x, filesystemdir):
                if isinstance(y, filesystemdir):
                    # sort directories alphabetically
                    return cmp(x.getname(), y.getname())
                else:
                    # sort directories first
                    return -1
            else:
                if isinstance(y, filesystemdir):
                    # sort directories first
                    return 1
                else:
                    # sort songs as usual in db
                    return (x.disknumber and y.disknumber
                            and cmp(x.disknumber, y.disknumber)
                            or x.tracknumber and y.tracknumber
                            and cmp(x.tracknumber, y.tracknumber)
                            or cmp(x.title, y.title))

        items.sort(key=cmp_to_key(cmpitem))
        return items
예제 #2
0
 def loadplaylisthandler(self, name, key):
     if key == ord("\n"):
         if name[-4:] != ".m3u":
             name = name + ".m3u"
         try:
             path = os.path.join(config.general.playlistdir, name)
             file = open(path, "r", encoding="utf-8")
             self._clear()
             for line in file:
                 if not line.startswith("#"):
                     song = hub.request(requests.autoregisterer_queryregistersong(self.songdbid,
                                                                                  line.strip()))
                     if song:
                         self.append(playlistitem(song))
             file.close()
         except (IOError, OSError):
             pass
         self._updateplaystarttimes()
         self.notifyplaylistchanged()
예제 #3
0
def ManagePytone(operation, media, programma):
    "Manage pytone to do operation on media"

    unixsocketfile = os.path.expanduser("~/.pytone/pytonectl")
    networklocation = unixsocketfile
    print(networklocation)

    try:
        channel = network.clientchannel(networklocation)

    except Exception as e:

        print("Error: cannot connect to PyTone server: %s" % e)
        sys.exit(2)

    channel.start()

    root, ext = os.path.splitext(media)

    if (ext == ".m3u"):
        medias = []
        f = open(media, "r")
        for line in f.readlines():
            medias.append(line[:-1])
        f.close()

    else:
        medias = (media, )

    for mediasplit in medias:
        print("invio ->", mediasplit)
        if operation == "queueMedia":
            song = channel.request(\
                requests.autoregisterer_queryregistersong("main", mediasplit))
            channel.notify(events.playlistaddsongtop(song))

    channel.quit()

    print("scrivo in django")
    print(programma)
    ar_emitted(programma)
    print("scritto in django")
예제 #4
0
 def loadplaylisthandler(self, name, key):
     if key == ord("\n"):
         if name[-4:] != ".m3u":
             name = name + ".m3u"
         try:
             path = os.path.join(config.general.playlistdir, name)
             file = open(path, "r", encoding="utf-8")
             self._clear()
             for line in file:
                 if not line.startswith("#"):
                     song = hub.request(
                         requests.autoregisterer_queryregistersong(
                             self.songdbid, line.strip()))
                     if song:
                         self.append(playlistitem(song))
             file.close()
         except (IOError, OSError):
             pass
         self._updateplaystarttimes()
         self.notifyplaylistchanged()
예제 #5
0
파일: item.py 프로젝트: indera/PyTone
 def getcontents(self):
     items = []
     try:
         for name in os.listdir(self.dir):
             try:
                 path = os.path.join(self.dir, name)
                 extension = os.path.splitext(path)[1]
                 if os.path.isdir(path) and os.access(path, os.R_OK|os.X_OK):
                     newitem = filesystemdir(self.songdbid, self.basedir, path)
                     items.append(newitem)
                 elif extension in metadata.getextensions() and os.access(path, os.R_OK):
                     song = hub.request(requests.autoregisterer_queryregistersong(self.songdbid, path))
                     if song:
                         items.append(song)
             except (IOError, OSError): pass
     except OSError:
         return None
     def cmpitem(x, y):
         if isinstance(x, filesystemdir):
             if isinstance(y, filesystemdir):
                 # sort directories alphabetically
                 return cmp(x.getname(), y.getname())
             else:
                 # sort directories first
                 return -1
         else:
             if isinstance(y, filesystemdir):
                 # sort directories first
                 return 1
             else:
                 # sort songs as usual in db
                 return ( x.disknumber and y.disknumber and cmp(x.disknumber, y.disknumber) or
                          x.tracknumber and y.tracknumber and cmp(x.tracknumber, y.tracknumber) or
                          cmp(x.title, y.title) )
     items.sort(cmp=cmpitem)
     return items
예제 #6
0
    if (ext == ".m3u"):
        medias = []
        f = open(media, "r")
        for line in f.readlines():
            medias.append(line[:-1])
        f.close()

    else:
        medias = (media, )

    for mediasplit in medias:
        print "invio ->", mediasplit
        if operation == "queueMedia":
            song = channel.request(\
                requests.autoregisterer_queryregistersong("main", mediasplit))
            channel.notify(events.playlistaddsongtop(song))

    channel.quit()

    print "scrivo in django"
    print programma
    ar_emitted(programma)
    print "scritto in django"


def secondi(delta):
    secondi = delta.seconds
    # correggo i viaggi che si fa seconds
    if delta.days < 0:
        secondi = secondi + (3600 * 24 * delta.days)
예제 #7
0
        usage()
        sys.exit(2)
else:
    if args[0]=="playerratecurrentsong" and len(args)==2:
        try:
            rating = int(args[1])
            if not 1<=rating<=5:
                raise
        except:
            usage()
            sys.exit(2)
        channel.notify(events.playerratecurrentsong("main", rating))
    if args[0]=="playerseekrelative" and len(args)==2:
        try:
            seconds = float(args[1])
        except:
            usage()
            sys.exit(2)
        channel.notify(events.playerseekrelative("main", seconds))
    elif args[0]=="playlistaddsongs":
        songs = [channel.request(requests.autoregisterer_queryregistersong("main", path)) for path in args[1:]]
        channel.notify(events.playlistaddsongs(songs))
    elif args[0]=="playlistaddsongtop" and len(args)==2:
        song = channel.request(requests.autoregisterer_queryregistersong("main", (args[1])))
        channel.notify(events.playlistaddsongtop(song))
    else:
        usage()
        sys.exit(2)

channel.quit()
예제 #8
0
            rating = int(args[1])
            if not 1 <= rating <= 5:
                raise
        except:
            usage()
            sys.exit(2)
        channel.notify(events.playerratecurrentsong("main", rating))
    if args[0] == "playerseekrelative" and len(args) == 2:
        try:
            seconds = float(args[1])
        except:
            usage()
            sys.exit(2)
        channel.notify(events.playerseekrelative("main", seconds))
    elif args[0] == "playlistaddsongs":
        songs = [
            channel.request(
                requests.autoregisterer_queryregistersong("main", path))
            for path in args[1:]
        ]
        channel.notify(events.playlistaddsongs(songs))
    elif args[0] == "playlistaddsongtop" and len(args) == 2:
        song = channel.request(
            requests.autoregisterer_queryregistersong("main", (args[1])))
        channel.notify(events.playlistaddsongtop(song))
    else:
        usage()
        sys.exit(2)

channel.quit()
예제 #9
0
    if (ext == ".m3u"):
        medias=[]
        f = open(media, "r")
        for line in f.readlines():
            medias.append(line[:-1])
        f.close()

    else:
        medias=(media,)

    for mediasplit in medias:
        print "invio ->",mediasplit
        if operation == "queueMedia":
            song = channel.request(\
                requests.autoregisterer_queryregistersong("main", mediasplit))
            channel.notify(events.playlistaddsongtop(song))

    channel.quit()


    print "scrivo in django"
    print programma
    ar_emitted(programma)
    print "scritto in django"


def secondi(delta):
    secondi=delta.seconds
    # correggo i viaggi che si fa seconds
    if delta.days < 0 :