Exemple #1
0
    def run(self):
        logger.debug('Starting task GeneratePlaylists')
        self.app.task_cmd('task_start', message='Generating playlists ...')
        playlist_dir = appconf.playlists_dir()
        videodirlist = os.listdir(os.path.join(playlist_dir, 'video'))
        audiodirlist = os.listdir(os.path.join(playlist_dir, 'audio'))
        
        db = DB.new_connection()
        pls = db.playlist_list()
        for pl in pls:
            audiolist = []
            videolist = []
            videos = db.playlist_video_list(pl['id'])
            for video in videos:
                filename = self.get_filename(video['id'], videodirlist)
                if filename:
                    videolist.append(os.path.join('video', filename))
                
                filename = self.get_filename(video['id'], audiodirlist)
                if filename:
                    audiolist.append(os.path.join('audio', filename))

            videopl = '{0}_video.m3u'.format(pl['title'])
            audiopl = '{0}_audio.m3u'.format(pl['title'])
            vpath = os.path.join(playlist_dir, videopl)
            apath = os.path.join(playlist_dir, audiopl)
            pl = PlaylistFile(videolist)
            pl.save(vpath)
            
            pl = PlaylistFile(audiolist)
            pl.save(apath)
        
        logger.debug('Done task GeneratePlaylists')
        self.app.task_cmd('task_stop', message='Done.')
Exemple #2
0
 def run(self):
     db = DB.new_connection()
     self.app.task_cmd('task_start', message='Loading data ...')
     pls = db.playlist_list()
     for pl in pls:
         self.app.task_cmd('add_playlist', playlist=pl, save=False)
         videos = db.playlist_video_list(pl['id'])
         for video in videos:
             self.app.task_cmd('add_video', playlist_id=pl['id'],
                               video=video, save=False)
     self.app.task_cmd('task_stop', message='Done.')
Exemple #3
0
    def run(self):
        logger.debug('Starting task PlaylistCopyTo')
        self.app.task_cmd('task_start', message='Copying Playlist audio/video files ...')
        playlist_dir = appconf.playlists_dir()
        videodirlist = os.listdir(os.path.join(playlist_dir, 'video'))
        audiodirlist = os.listdir(os.path.join(playlist_dir, 'audio'))
        
        db = DB.new_connection()
        playlist = db.playlist_find(self.playlist_id)
        audiolist = []
        videolist = []
        videos = db.playlist_video_list(self.playlist_id)
        for video in videos:
            filename = self.get_filename(video['id'], videodirlist)
            if filename:
                copy_from = os.path.join(playlist_dir, 'video', filename)
                copy_to = os.path.join(self.path, filename)
                try:
                    shutil.copyfile(copy_from, copy_to)
                except IOError as e:
                    raise e
                videolist.append(filename)
            
            filename = self.get_filename(video['id'], audiodirlist)
            if filename:
                copy_from = os.path.join(playlist_dir, 'audio', filename)
                copy_to = os.path.join(self.path, filename)
                try:
                    shutil.copyfile(copy_from, copy_to)
                except IOError as e:
                    raise e
                audiolist.append(filename)

        videopl = '{0}__video.m3u'.format(playlist['title'])
        vpath = os.path.join(self.path, videopl)
        if videolist:
            pl = PlaylistFile(videolist)
            pl.save(vpath)
        
        audiopl = '{0}__audio.m3u'.format(playlist['title'])
        apath = os.path.join(self.path, audiopl)
        if audiolist:
            pl = PlaylistFile(audiolist)
            pl.save(apath)
        
        logger.debug('Done task PlaylistCopyTo')
        self.app.task_cmd('task_stop', message='Done.')
Exemple #4
0
    def run(self):
        db = DB.new_connection()
        self.app.task_cmd('task_start', message='Downloading videos ...')
        videos = db.video_list()
        curdir = os.getcwd()
        for v in videos:
            if self.app.task_cancel.is_set():
                self.app.task_cmd('task_stop', message='Canceled.')
                self.app.task_cancel.clear()
                return

            # Video download
            if appconf.is_video_download_active():
                self.download_video(v)
            else:
                logger.info('Video download inactive.')
            # Audio download
            if appconf.is_audio_download_active():
                self.download_audio(v)
            else:
                logger.info('Audio download inactive.')
        os.chdir(curdir)
        self.app.task_cmd('task_stop', message='Done.')