コード例 #1
0
ファイル: display.py プロジェクト: sensini42/flvdown
 def findEpOnDisk(self):
     """ return episodes from disk """
     from os import listdir as oslistdir
     from operator import attrgetter
     from util.episodetv import episodeTV
     listep = set()
     
     for dirname in oslistdir('.'):
         try:
             filesInDir = oslistdir(dirname)
         except:
             continue
             # print dirname, "pas un dossier"
         for fileEpi in filesInDir:
             try:
                 tv_name = '_'.join(fileEpi.split('_')[:-1])
                 season_epi = fileEpi.split('_')[-1].split('.')[0]
                 idepi = season_epi[-2:]
                 idseason = season_epi[:-2]
                 epitv = episodeTV(tv_name, idseason, idepi)
                 listep.add(epitv)
             except:
                 print "problem with", fileEpi, "not an epi?"
             
             
     listep = sorted(listep, key=attrgetter('tvshow_', 'strSeason', 'strEpisode'))
     return listep
コード例 #2
0
ファイル: files.py プロジェクト: weweyes/inpanel
def listfile(directory):
    '''only list files of directory'''
    d = abspath(directory)
    if not exists(d) or not isdir(d):
        return None
    items = sorted(oslistdir(d))
    return items if len(items) > 0 else []
コード例 #3
0
 def list_playlist_songs(self):
     files = oslistdir(self.playlist_path)
     song_files = []
     for file in files:
         file_is_song_type = ('.mp3' in file or '.MP3' in file) or ('.wav' in file or '.WAV' in file)
         if file_is_song_type:
             song_files.append(file)
     return song_files
コード例 #4
0
ファイル: episodetv.py プロジェクト: sensini42/flvdown
 def getSrtName(self):
     """ return the name of the srt file (once downloaded) """
     tvfiles = oslistdir(self.tvshow_)
     srtFile = ""
     for _file in tvfiles:
         if _file == self.getBaseName() + '.srt':
             srtFile = self.tvshow_ + "/" + _file
             break
     return srtFile
コード例 #5
0
ファイル: main.py プロジェクト: Aurite/museomix-pimp-my-room
    def load_data(self, *args):
        root = join(dirname(__file__), 'data', 'resources')
        choices = {}

        for d in listdir(root):
            choices[d] = {}
            for f in oslistdir(join(root, d)):
                choices[d][f] = join(root, d, f)

        self.choices = choices
コード例 #6
0
ファイル: episodetv.py プロジェクト: sensini42/flvdown
 def getVideoName(self):
     """ return the name of the video file (once downloaded) """
     tvfiles = oslistdir(self.tvshow_)
     videoFile = ""
     for _file in tvfiles:
         if (_file.startswith(self.getBaseName()) and \
           not _file.endswith('.srt')):
             videoFile = self.tvshow_ + "/" + _file
             break
     return videoFile
コード例 #7
0
ファイル: files.py プロジェクト: weweyes/inpanel
def listdir(path, showdotfiles=False, onlydir=None):
    path = abspath(path)
    if not exists(path) or not isdir(path):
        return False
    items = sorted(oslistdir(path))
    if not showdotfiles:
        items = [item for item in items if not item.startswith('.')]
    for i, item in enumerate(items):
        items[i] = getitem(join(path, item))
    # let folders list before files
    rt = []
    for i in xrange(len(items) - 1, -1, -1):
        if items[i]['isdir'] or items[i]['islnk'] and not items[i][
                'link_broken'] and items[i]['link_isdir']:
            rt.insert(0, items.pop(i))
    # check if only list directories
    if not onlydir:
        rt.extend(items)
    return rt
コード例 #8
0
def dircache_listdir(path):
    res = global_cache.get(path)
    if res is None:
        res = oslistdir(path)
        global_cache[path] = res
    return res
コード例 #9
0
def detect_face(frameCount):
    lastx = None
    lasty = None
    lastw = None
    lasth = None
    lastlabel = None
    # grab global references to the video stream, output frame, and lock
    global vs, outputFrame, lock, face_cascade, recognizer, persons, gameproc, VIDEO_FRAME_WIDTH
    face_was_just_detected = False
    count = 0
    count_since_detection = 0
    newid = len(persons)
    # simple version for working with CWD
    trainSampleN = len([fnm for fnm in oslistdir('.') if ospath.isfile(fnm)])
    do_Move("v")  # turn of serial debuggin (faster reaction )
    while True:
        frame = vs.read()
        frame = imutils.resize(frame, width=VIDEO_FRAME_WIDTH)
        # here do not detect if face was just detected, only draw the same rectangle over frames
        # do this only if time from detection framcount has passed
        if (face_was_just_detected):
            # dont send any signals to arduino if face was detected just moment ago (defined by frameCount)
            if count_since_detection > frameCount:
                face_was_just_detected = False
            else:
                count_since_detection += 1
                cv2.rectangle(frame, (lastx, lasty),
                              (lastx + lastw, lasty + lasth), (30, 100, 30), 5)
                cv2.putText(frame, lastlabel, (lastx, lasty + lasth),
                            cv2.FONT_HERSHEY_SIMPLEX, 0.35, (255, 255, 255), 1)

        else:  # try to detect face and if detected - send to arduino
            gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
            faces = face_cascade.detectMultiScale(gray, 1.3)
            for (x, y, w, h) in faces:
                # this mechanism blocks detecting more than one face simultaneously
                lastx = x
                lasty = y
                lastw = w
                lasth = h
                # predict who is on the picture
                id, confusion = recognizer.predict(gray[y:y + h, x:x + w])
                if (confusion > 120):
                    id = 0

                confusion = "U{0:.0f}".format(confusion)
                name = persons[id]
                label = str(name + "\n" + str(confusion))
                logD(label)
                lastlabel = label
                count_since_detection = 0
                face_was_just_detected = True
                cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 5)
                cv2.putText(frame, label, (x, y + h), cv2.FONT_HERSHEY_SIMPLEX,
                            0.35, (255, 255, 255), 1)

                xx = int(x + (x + h)) / 2
                yy = int(y + (y + w)) / 2
                arr = {x: xx, y: yy}
                logD(arr)
                do_Move("d={0:.0f}".format(xx))
                if gameproc == None:
                    hello(id)
                    # moveTowardFace(xx)
                    # TODO comment this out and see if affects stutter. May need polling for a process
                    # hello(id)
                    if id > 0:
                        beHappy()
                        hello(id)
                        trainSampleN = saveimage(id, trainSampleN,
                                                 gray[y:y + h, x:x + w])
                        playGame(id)
                    else:  # dont know the person
                        trainSampleN = saveimage(newid, trainSampleN,
                                                 gray[y:y + h, x:x + w])
                        beSad()
                        printsay("sorry, i dont know you yet")

                else:  # game has started at least once
                    logD(gameproc.poll())
                    # moveTowardFace(xx)
                    if gameproc.poll(
                    ) == 0:  # if game finished and returned 0 (okay)
                        if id > 0:  # and he recognized person
                            # moveTowardFace(xx)
                            hello(id)
                            playGame(id)
                        else:  # if game finished and returned 0, but he didnt recognized person
                            # moveTowardFace(xx)
                            hello(id)
                            printsay(
                                "sorry, human but i dont recognize you, and i do not play with strangers."
                            )
                    elif gameproc.poll() == None:  # if game goes on
                        do_Move()

                        # or there was an error in game
                        # TODO refactor if statements

            # timestamp = datetime.datetime.now()
            # cv2.putText(frame, timestamp.strftime(
            #     "%A %d %B %Y %I:%M:%S%p"), (10, frame.shape[0] - 10),
            #     cv2.FONT_HERSHEY_SIMPLEX, 0.35, (0, 0, 255), 1)
            # acquire the lock, set the output frame, and release the
            # lock
            # TODO good idea to extract movement module to make duncan be happy whenever he guesses correctly
        with lock:
            outputFrame = frame.copy()
コード例 #10
0
ファイル: main.py プロジェクト: Aurite/museomix-pimp-my-room
def listdir(d):
    return (x for x in oslistdir(d) if isdir(join(d, x)))
コード例 #11
0
 def list_playlist_songs2(self):
     files = oslistdir(self.playlist_path)
     song_files = filter(lambda x: ('.mp3' in x or '.MP3' in x) or ('.wav' in x or '.WAV' in x), files)
     return [x for x in song_files]
コード例 #12
0
def browse_folder(dirname,parentfolderID=None,recursive=True,updatepics=False,addpics=True,delpics=True,rescan=False,updatefunc=None,dateadded = strftime("%Y-%m-%d %H:%M:%S")):
    """Browse the root folder 'dirname'
    - 'recursive' : the scan is recursive. all the subfolders of 'dirname' are traversed for pics
    - 'updatepics' : enable to modify a picture entry if metas changed
    - 'rescan' : force the scan wheter pictures are already inside DB or not
    - 'addpics' :
    - 'delpics' :
    - 'dateadded' : the date when the pictures are scanned (useful for subfolders calls to keep the same date as the main root folder)
    - 'updatefunc' is a function called to show the progress of the scan. The parameters are : pourcentage(int),[ line1(str),line2(str),line3(str) ] )
    """
    global compte,comptenew,cptscanned,cptdelete,cptchanged,cptroots,iroots
    cpt=0
    #on liste les fichiers jpg du dossier
    listfolderfiles=[]
    sys_enc = sys.getfilesystemencoding()
    dirname = smart_unicode(dirname)

    #print "In browse_folder"

    #######
    # Pre STEP: cleanup keywords in database
    #######
    MPDB.DB_cleanup_keywords()

    #######
    # STEP 0 : dirname should not be one of those which are excluded from scan !
    #######
    # TODO : if the path was already scanned before, we need to remove previously added pictures AND subfolders
    if dirname in Exclude_folders:
        #print "dirname in Exclude_folders"
        cptdelete = cptdelete + MPDB.RemovePath(dirname)
        return
    #######
    # STEP 1 : list all files in directory
    #######

    # This conversion is important for windows to get filenames in utf-8 encoding!
    if type(dirname).__name__ == "str":
        dirname = unicode(dirname, 'utf-8')
    try:
        dirname = smart_unicode(dirname)
        try:
            listdir = oslistdir(dirname)
        except:
            listdir = oslistdir(dirname.encode('utf-8'))
        # pretty stupid, but is a must.
        for index in range(len(listdir)):
            listdir[index] = smart_unicode(listdir[index])

    except:
        print_exc()
        MPDB.log( "Error while trying to get directory content" )
        listdir=[]



    #######
    # STEP 2 : Keep only the files with extension...
    #######
    for f in listdir:
        if splitext(f)[1].upper() in listext:
            listfolderfiles.append(f)


    #on récupère la liste des fichiers entrées en BDD pour le dossier en cours
    listDBdir = MPDB.DB_listdir(dirname)# --> une requête pour tout le dossier

    #######
    # STEP 3 : If folder contains pictures, create folder in database
    #######
    #on ajoute dans la table des chemins le chemin en cours
    PFid = MPDB.DB_folder_insert(basename(dirname) or osdirname(dirname).split(separator)[-1],
                            dirname,
                            parentfolderID,
                            listfolderfiles and "1" or "0"#i
                            )
    if listfolderfiles:#si le dossier contient des fichiers jpg...
        #######
        # STEP 4 : browse all pictures
        #######
        #puis on parcours toutes les images du dossier en cours
        for picfile in listfolderfiles:#... on parcours tous les jpg du dossier
            extension = splitext(picfile)[1].upper()
            if extension in vidsext and Addon.getSetting("usevids") == "false":#si une video mais qu'on ne prend pas les vidéos
                if picfile in listDBdir:
                    listDBdir.pop(listDBdir.index(picfile))
                continue #alors on ne fait rien et on reprend la boucle

            if file_is_accessible(dirname, picfile):
                cptscanned = cptscanned+1
                cpt = cpt + 1
            else:
                MPDB.DB_del_pic(dirname,picfile)
                cptdelete=cptdelete+1

            ###if updatefunc and updatefunc.iscanceled(): return#dialog progress has been canceled
            #on enlève l'image traitée de listdir
            if len(listdir) > 0:
                listdir.pop(listdir.index(picfile))
                #print "Pop "
                #print smart_unicode(picfile).encode('utf-8')
            if not rescan: #si pas de rescan
                #les images ne sont pas à scanner de force
                if picfile in listDBdir: #si l'image est déjà en base
                    #l'image est déjà en base de donnée
                    if updatepics: #si le paramètre est configuré pour mettre à jour les metas d'une photo
                        #Il faut mettre à jour les images...
                        if extension in vidsext:
                            print "Video"
                            DoScan = True
                            update = True
                            straction = __language__(30242)#Updating
                            if file_is_accessible(dirname, picfile):
                                cptchanged = cptchanged + 1
                        elif not (MPDB.fileSHA(join(dirname,picfile))==MPDB.getFileSha(dirname,picfile)): #si l'image a changé depuis qu'elle est en base
                            print "No Video"
                            #Scan les metas et ajoute l'image avec un paramètre de mise à jour = true
                            DoScan = True
                            update = True
                            straction = __language__(30242)#Updating
                            if file_is_accessible(dirname, picfile):
                                cptchanged = cptchanged + 1                        
                        else:
                            DoScan = False
                            straction = __language__(30243)#"Passing"
                            #mais l'image n'a pas changée. Donc on passe
                    else:
                        DoScan = False
                        straction = __language__(30243)#"Passing"
                        #mais on ne met pas à jour les photos. Donc on passe
                else:
                    DoScan = True
                    update = False
                    straction = __language__(30244)#"Adding"
                    if file_is_accessible(dirname, picfile):
                        comptenew = comptenew + 1
                    #l'image n'est pas dans la base. On l'ajoute maintenant avec paramètre de mise à jour = false
            else:
                DoScan = True
                update = True
                straction = __language__(30245)#"Rescan"
                #on rescan les photos donc on ajoute l'image avec paramètre de mise à jour = true


            if updatefunc and totalfiles!=0 and cptroots!=0:
                updatefunc.update(int(100*float(cptscanned)/float(totalfiles)),#cptscanned-(cptscanned/100)*100,
                                  #cptscanned/100,
                                  int(100*float(iroots)/float(cptroots)),
                                  __language__(30000)+"[%s] (%0.2f%%)"%(straction,100*float(cptscanned)/float(totalfiles)),#"MyPicture Database [%s] (%0.2f%%)"
                                  picfile)
            if DoScan and file_is_accessible(dirname, picfile):
                try:
                    modifiedtime = str(stat(join(dirname,picfile)).st_mtime)
                except:
                    modifiedtime = str(stat(join(dirname.encode('utf-8'),picfile.encode('utf-8'))).st_mtime)

                picentry = { "idFolder":PFid,
                             "strPath":dirname,
                             "strFilename":picfile,
                             "UseIt":1,
                             "sha": extension in picsext and str(MPDB.fileSHA(join(dirname,picfile))) or extension in vidsext and "1" ,
                             #"DateAdded":dateadded,
                             "DateAdded":strftime("%Y-%m-%d %H:%M:%S"),
                             "mtime":modifiedtime,
                             "ftype": extension in picsext and "picture" or extension in vidsext and "video" or ""}




                # get the meta tags
                try:
                    if not extension in vidsext:
                        picentry.update(get_metas(dirname,picfile))
                    # insert picture into table files
                    try:
                        MPDB.DB_file_insert(dirname,picfile,picentry,update)
                    except MPDB.MyPictureDB:
                        pass
                except:
                    print_exc()




            if picfile in listDBdir:
                listDBdir.pop(listDBdir.index(picfile))

        #Now if the database contain some more pictures assign for this folder, we need to delete them if 'update' setting is true
        if listDBdir :#and updatepics: #à l'issu si listdir contient encore des fichiers, c'est qu'ils sont en base mais que le fichier n'existe plus physiquement.
            for f in listDBdir: #on parcours les images en DB orphelines
                cptdelete=cptdelete+1
                if updatefunc and totalfiles!=0 and cptroots!=0:
                    updatefunc.update(int(100*float(cptscanned)/float(totalfiles)),#cptscanned-(cptscanned/100)*100,
                                      #cptscanned/100,
                                      int(100*float(iroots)/float(cptroots)),
                                      __language__(30000)+"["+__language__(30246)+"]",#MyPicture Database [Removing]
                                      f)
                MPDB.DB_del_pic(dirname,f)
                MPDB.log( "\t%s has been deleted from database because the file does not exists in this folder. "%f)#f.decode(sys_enc))
            MPDB.log("")


    else:
        MPDB.log( "This folder does not contain any picture :")
        MPDB.log( dirname )
        MPDB.log( "" )

    if cpt:
        MPDB.log( "%s new pictures found in %s"%(str(cpt),dirname) )
        #unicode(info.data[k].encode("utf8").__str__(),"utf8")
        compte=compte+cpt
        cpt=0
    if recursive: #gestion de la recursivité. On rappel cette même fonction pour chaque dossier rencontré
        MPDB.log( "scan the subfolders of :")
        MPDB.log( dirname )
        for item in listdir:
            try:
                joineddir = join(dirname,item)
            except:
                joineddir = join(dirname.encode('utf-8'),item.encode('utf-8'))
                
            joineddir = smart_unicode(joineddir)

            try:
                isjoineddir = isdir(joineddir)
            except:
                isjoineddir = isdir(joineddir.encode('utf-8'))

            if isjoineddir :#un directory
                #browse_folder(dirname,parentfolderID=None,recursive=True,updatepics=False,rescan=False,updatefunc=None)
                browse_folder(joineddir,PFid,recursive,updatepics,addpics,delpics,rescan,updatefunc,dateadded)
            else:
                #listdir contenait un fichier mais pas un dossier
                # inutilisé... on passe pour le moment
                pass
コード例 #13
0
def get_input_nbs_files(files):
    if len(files) == 0:
        return [i for i in oslistdir() if i[-4:] == ".nbs"]
    else:
        return files