How to use the sickrage.helper.common.episode_num function in sickrage

To help you get started, we’ve selected a few sickrage examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pymedusa / Medusa / sickbeard / tv.py View on Github external
main_db_con = db.DBConnection()
        sql_results = main_db_con.select(
            b'SELECT '
            b'  * '
            b'FROM '
            b'  tv_episodes '
            b'WHERE '
            b'  showid = ? '
            b'  AND season = ? '
            b'  AND episode = ?', [self.show.indexerid, season, episode])

        if len(sql_results) > 1:
            raise MultipleEpisodesInDatabaseException('Your DB has two records for the same show somehow.')
        elif not sql_results:
            logger.log(u'{id}: Episode {ep} not found in the database'.format
                       (id=self.show.indexerid, ep=episode_num(self.season, self.episode)),
                       logger.DEBUG)
            return False
        else:
            if sql_results[0][b'name']:
                self.name = sql_results[0][b'name']

            self.season = season
            self.episode = episode
            self.absolute_number = sql_results[0][b'absolute_number']
            self.description = sql_results[0][b'description']
            if not self.description:
                self.description = ''
            if sql_results[0][b'subtitles'] and sql_results[0][b'subtitles']:
                self.subtitles = sql_results[0][b'subtitles'].split(',')
            self.subtitles_searchcount = sql_results[0][b'subtitles_searchcount']
            self.subtitles_lastsearch = sql_results[0][b'subtitles_lastsearch']
github pymedusa / Medusa / sickbeard / tv.py View on Github external
episodes = [ep for ep in parse_result.episode_numbers if ep is not None]
        if not episodes:
            logger.log(u'{0}: parse_result: {1}'.format(self.indexerid, parse_result))
            logger.log(u'{0}: No episode number found in {1}, ignoring it'.format
                       (self.indexerid, filepath), logger.WARNING)
            return None

        # for now lets assume that any episode in the show dir belongs to that show
        season = parse_result.season_number if parse_result.season_number is not None else 1
        root_ep = None

        sql_l = []
        for current_ep in episodes:
            logger.log(u'{0}: {1} parsed to {2} {3}'.format
                       (self.indexerid, filepath, self.name, episode_num(season, current_ep)), logger.DEBUG)

            check_quality_again = False
            same_file = False

            cur_ep = self.get_episode(season, current_ep)
            if not cur_ep:
                try:
                    cur_ep = self.get_episode(season, current_ep, filepath)
                    if not cur_ep:
                        raise EpisodeNotFoundException
                except EpisodeNotFoundException:
                    logger.log(u'{0}: Unable to figure out what this file is, skipping {1}'.format
                               (self.indexerid, filepath), logger.ERROR)
                    continue

            else:
github pymedusa / Medusa / sickbeard / tv.py View on Github external
logger.log(u'Error loading the NFO, backing up the NFO and skipping for now: ' + ex(e),
                               logger.ERROR)
                    try:
                        ek(os.rename, nfo_file, nfo_file + '.old')
                    except Exception as e:
                        logger.log(u"Failed to rename your episode's NFO file - "
                                   u'you need to delete it or fix it: ' + ex(e), logger.ERROR)
                    raise NoNFOException('Error in NFO format')

                for ep_details in list(show_xml.iter('episodedetails')):
                    if ep_details.findtext('season') is None or int(ep_details.findtext('season')) != self.season or \
                       ep_details.findtext('episode') is None or int(ep_details.findtext('episode')) != self.episode:
                        logger.log(u'{id}: NFO has an  block for a different episode - '
                                   u'wanted {ep_wanted} but got {ep_found}'.format
                                   (id=self.show.indexerid, ep_wanted=episode_num(self.season, self.episode),
                                    ep_found=episode_num(ep_details.findtext('season'),
                                                         ep_details.findtext('episode'))), logger.DEBUG)
                        continue

                    if ep_details.findtext('title') is None or ep_details.findtext('aired') is None:
                        raise NoNFOException('Error in NFO format (missing episode title or airdate)')

                    self.name = ep_details.findtext('title')
                    self.episode = int(ep_details.findtext('episode'))
                    self.season = int(ep_details.findtext('season'))

                    xem_refresh(self.show.indexerid, self.show.indexer)

                    self.scene_absolute_number = get_scene_absolute_numbering(
                        self.show.indexerid,
                        self.show.indexer,
                        self.absolute_number
github pymedusa / Medusa / sickbeard / tv.py View on Github external
(self.show.name, episode_num(self.season, self.episode) or
                        episode_num(self.season, self.episode, numbering='absolute')), logger.DEBUG)
            return

        new_subtitles = subtitles.download_subtitles(self)
        if new_subtitles:
            self.subtitles = subtitles.merge_subtitles(self.subtitles, new_subtitles)

        self.subtitles_searchcount += 1 if self.subtitles_searchcount else 1
        self.subtitles_lastsearch = datetime.datetime.now().strftime(dateTimeFormat)
        self.save_to_db()

        if new_subtitles:
            subtitle_list = ', '.join([subtitles.name_from_code(code) for code in new_subtitles])
            logger.log(u'Downloaded {} subtitles for {} {}'.format
                       (subtitle_list, self.show.name, episode_num(self.season, self.episode) or
                        episode_num(self.season, self.episode, numbering='absolute')))

            notifiers.notify_subtitle_download(self.pretty_name(), subtitle_list)

        return new_subtitles
github pymedusa / Medusa / sickbeard / tv.py View on Github external
# if we know we don't want it then just say no
        if ep_status in Quality.ARCHIVED + [UNAIRED, SKIPPED, IGNORED] and not forced_search:
            logger.log(u"Existing episode status is '{status}', "
                       u'ignoring found result for {name} {ep} with quality {quality}'.format
                       (status=ep_status_text, name=self.name, ep=episode_num(season, episode),
                        quality=Quality.qualityStrings[quality]), logger.DEBUG)
            return False

        _, cur_quality = Quality.splitCompositeStatus(ep_status)

        # if it's one of these then we want it as long as it's in our allowed initial qualities
        if ep_status in (WANTED, SKIPPED, UNKNOWN):
            logger.log(u"Existing episode status is '{status}', "
                       u'getting found result for {name} {ep} with quality {quality}'.format
                       (status=ep_status_text, name=self.name, ep=episode_num(season, episode),
                        quality=Quality.qualityStrings[quality]), logger.DEBUG)
            return True
        elif forced_search:
            if (download_current_quality and quality >= cur_quality) or (
                    not download_current_quality and quality > cur_quality):
                logger.log(u'Usually ignoring found result, but forced search allows the quality,'
                           u' getting found result for {name} {ep} with quality {quality}'.format
                           (name=self.name, ep=episode_num(season, episode), quality=Quality.qualityStrings[quality]),
                           logger.DEBUG)
                return True

        # if we are re-downloading then we only want it if it's in our
        # preferred_qualities list and better than what we have, or we only have
        # one bestQuality and we do not have that quality yet
        if ep_status in Quality.DOWNLOADED + Quality.SNATCHED + Quality.SNATCHED_PROPER and \
                quality in preferred_qualities and (quality > cur_quality or cur_quality not in preferred_qualities):
github pymedusa / Medusa / sickbeard / tv.py View on Github external
season = try_int(season, None)
        episode = try_int(episode, None)
        absolute_number = try_int(absolute_number, None)

        # if we get an anime get the real season and episode
        if self.is_anime and absolute_number and not season and not episode:
            main_db_con = db.DBConnection()
            sql = b'SELECT season, episode FROM tv_episodes WHERE showid = ? AND absolute_number = ? AND season != 0'
            sql_results = main_db_con.select(sql, [self.indexerid, absolute_number])

            if len(sql_results) == 1:
                episode = int(sql_results[0][b'episode'])
                season = int(sql_results[0][b'season'])
                logger.log(u'Found episode by absolute number {absolute} which is {ep}'.format
                           (absolute=absolute_number,
                            ep=episode_num(season, episode)), logger.DEBUG)
            elif len(sql_results) > 1:
                logger.log(u'Multiple entries for absolute number: {absolute} in show: {name} found '.format
                           (absolute=absolute_number, name=self.name), logger.ERROR)

                return None
            else:
                logger.log(
                    'No entries for absolute number: ' + str(absolute_number) + ' in show: ' + self.name + ' found.',
                    logger.DEBUG)
                return None

        if season not in self.episodes:
            self.episodes[season] = {}

        if episode in self.episodes[season] and self.episodes[season][episode] is not None:
            return self.episodes[season][episode]
github pymedusa / Medusa / sickbeard / tv.py View on Github external
sql_l = []
        for season in show_obj:
            scanned_eps[season] = {}
            for episode in show_obj[season]:
                # need some examples of wtf episode 0 means to decide if we want it or not
                if episode == 0:
                    continue
                try:
                    ep = self.get_episode(season, episode)
                    if not ep:
                        raise EpisodeNotFoundException
                except EpisodeNotFoundException:
                    logger.log(u'{id}: {indexer} object for {ep} is incomplete, skipping this episode'.format
                               (id=self.indexerid, indexer=sickbeard.indexerApi(self.indexer).name,
                                ep=episode_num(season, episode)))
                    continue
                else:
                    try:
                        ep.load_from_indexer(tvapi=t)
                    except EpisodeDeletedException:
                        logger.log(u'The episode was deleted, skipping the rest of the load')
                        continue

                with ep.lock:
                    ep.load_from_indexer(season, episode, tvapi=t)

                    sql_l.append(ep.get_sql())

                scanned_eps[season][episode] = True

        if sql_l:
github pymedusa / Medusa / sickbeard / tv.py View on Github external
def _specify_episode(self, season, episode):

        sql_results = self.load_from_db(season, episode)

        if not sql_results:
            # only load from NFO if we didn't load from DB
            if self.is_location_valid():
                try:
                    self.__load_from_nfo(self.location)
                except NoNFOException:
                    logger.log(u'{id}: There was an error loading the NFO for episode {ep}'.format
                               (id=self.show.indexerid, ep=episode_num(season, episode)), logger.ERROR)

                # if we tried loading it from NFO and didn't find the NFO, try the Indexers
                if not self.hasnfo:
                    try:
                        result = self.load_from_indexer(season, episode)
                    except EpisodeDeletedException:
                        result = False

                    # if we failed SQL *and* NFO, Indexers then fail
                    if not result:
                        raise EpisodeNotFoundException(
                            u"Couldn't find episode {ep}".format(ep=episode_num(season, episode)))
github pymedusa / Medusa / sickbeard / tv.py View on Github external
return
            else:
                logger.log(u'' + sickbeard.indexerApi(self.indexer).name + u' timed out, unable to create the episode',
                           logger.ERROR)
                return False
        except (sickbeard.indexer_episodenotfound, sickbeard.indexer_seasonnotfound):
            logger.log(u'Unable to find the episode on ' + sickbeard.indexerApi(
                self.indexer).name + u'... has it been removed? Should I delete from db?', logger.DEBUG)
            # if I'm no longer on the Indexers but I once was then delete myself from the DB
            if self.indexerid != -1:
                self.delete_episode()
            return

        if getattr(my_ep, 'episodename', None) is None:
            logger.log(u'This episode {show} - {ep} has no name on {indexer}. Setting to an empty string'.format
                       (show=self.show.name, ep=episode_num(season, episode),
                        indexer=sickbeard.indexerApi(self.indexer).name))
            setattr(my_ep, 'episodename', '')

        if getattr(my_ep, 'absolute_number', None) is None:
            logger.log(u'{id}: This episode {show} - {ep} has no absolute number on {indexer}'.format
                       (id=self.show.indexerid, show=self.show.name, ep=episode_num(season, episode),
                        indexer=sickbeard.indexerApi(self.indexer).name), logger.DEBUG)
        else:
            logger.log(u'{id}: The absolute number for {ep} is: {absolute} '.format
                       (id=self.show.indexerid, ep=episode_num(season, episode), absolute=my_ep['absolute_number']),
                       logger.DEBUG)
            self.absolute_number = int(my_ep['absolute_number'])

        self.name = getattr(my_ep, 'episodename', '')
        self.season = season
        self.episode = episode
github pymedusa / Medusa / sickbeard / tv.py View on Github external
logger.log(str(self.indexerid) + u': Writing NFOs for all episodes', logger.DEBUG)

        main_db_con = db.DBConnection()
        sql_results = main_db_con.select(
            b'SELECT '
            b'  season, '
            b'  episode '
            b'FROM '
            b'  tv_episodes '
            b'WHERE '
            b'  showid = ? '
            b"  AND location != ''", [self.indexerid])

        for ep_result in sql_results:
            logger.log(u'{id}: Retrieving/creating episode {ep}'.format
                       (id=self.indexerid, ep=episode_num(ep_result[b'season'], ep_result[b'episode'])),
                       logger.DEBUG)
            cur_ep = self.get_episode(ep_result[b'season'], ep_result[b'episode'])
            if not cur_ep:
                continue

            cur_ep.create_meta_files()