Beispiel #1
0
    def validate(self):
        self.validating_lock.acquire()
        if self.ready in ['yes', 'validated']:
            self.validating_lock.release()
            return True

        # if self.ready == 'failed':
        #     self.validating_lock.release()
        #     return False
        #
        if os.path.exists(self.path):
            self.validating_lock.release()
            self.ready = "yes"
            return True

        # avoid multiple process validating in the meantime
        info = self._get_info_from_url()
        self.validating_lock.release()

        if not info:
            return False

        if self.duration > var.config.getint('bot',
                                             'max_track_duration') * 60 != 0:
            # Check the length, useful in case of playlist, it wasn't checked before)
            log.info("url: " + self.url + " has a duration of " +
                     str(self.duration / 60) + " min -- too long")
            raise ValidationFailedError(tr('too_long', song=self.title))
        else:
            self.ready = "validated"
            self.version += 1  # notify wrapper to save me
            return True
Beispiel #2
0
    def _get_info_from_url(self):
        self.log.info("url: fetching metadata of url %s " % self.url)
        ydl_opts = {'noplaylist': True}
        succeed = False
        with youtube_dl.YoutubeDL(ydl_opts) as ydl:
            attempts = var.config.getint('bot',
                                         'download_attempts',
                                         fallback=2)
            for i in range(attempts):
                try:
                    info = ydl.extract_info(self.url, download=False)
                    self.duration = info['duration']
                    self.title = info['title']
                    self.keywords = info['title']
                    succeed = True
                    return True
                except youtube_dl.utils.DownloadError:
                    pass
                except KeyError:  # info has no 'duration'
                    break

        if not succeed:
            self.ready = 'failed'
            self.log.error("url: error while fetching info from the URL")
            raise ValidationFailedError(
                tr('unable_download', item=self.format_title()))
Beispiel #3
0
    def validate(self):
        if not os.path.exists(self.uri()):
            self.log.info(
                "file: music file missed for %s" % self.format_debug_string())
            raise ValidationFailedError(constants.strings('file_missed', file=self.path))

        # self.version += 1 # 0 -> 1, notify the wrapper to save me when validate() is visited the first time
        self.ready = "yes"
        return True
Beispiel #4
0
    def validate(self):
        try:
            self.validating_lock.acquire()
            if self.ready in ['yes', 'validated']:
                return True

            # if self.ready == 'failed':
            #     self.validating_lock.release()
            #     return False
            #
            if os.path.exists(self.path):
                self.ready = "yes"
                return True

            # Check if this url is banned
            if var.db.has_option('url_ban', self.url):
                raise ValidationFailedError(tr('url_ban', url=self.url))

            # avoid multiple process validating in the meantime
            info = self._get_info_from_url()

            if not info:
                return False

            # Check if the song is too long and is not whitelisted
            max_duration = var.config.getint('bot', 'max_track_duration') * 60
            if max_duration and \
                    not var.db.has_option('url_whitelist', self.url) and \
                    self.duration > max_duration:
                log.info("url: " + self.url + " has a duration of " +
                         str(self.duration / 60) + " min -- too long")
                raise ValidationFailedError(
                    tr('too_long',
                       song=self.format_title(),
                       duration=format_time(self.duration),
                       max_duration=format_time(max_duration)))
            else:
                self.ready = "validated"
                self.version += 1  # notify wrapper to save me
                return True
        finally:
            self.validating_lock.release()
Beispiel #5
0
    def validate(self):
        if not os.path.exists(self.uri()):
            self.log.info(
                "file: music file missed for %s" % self.format_debug_string())
            raise ValidationFailedError(tr('file_missed', file=self.path))

        if self.duration == 0:
            self.duration = util.get_media_duration(self.uri())
            self.version += 1  # 0 -> 1, notify the wrapper to save me
        self.ready = "yes"
        return True