Ejemplo n.º 1
0
    def periodical_task(self):
        feeds = self.config.get("feeds")
        if feeds:
            added_items = []
            feeds = feeds.replace(" ", "").split(',')
            for feed in feeds:
                feed = feedparser.parse(
                    get_url(feed, self.configfile, self.dbfile, self.scraper))
                for post in feed.entries:
                    key = post.title.replace(" ", ".")

                    epoch = datetime(1970, 1, 1)
                    current_epoch = int(time())
                    published_format = "%Y-%m-%d %H:%M:%S+00:00"
                    published_timestamp = str(parser.parse(post.published))
                    published_epoch = int((datetime.strptime(
                        published_timestamp, published_format) -
                                           epoch).total_seconds())
                    if (current_epoch - 1800) > published_epoch:
                        link_pool = post.summary
                        unicode_links = re.findall(r'(http.*)', link_pool)
                        links = []
                        for link in unicode_links:
                            if check_hoster(link, self.configfile):
                                links.append(str(link))
                        if self.config.get("hoster_fallback") and not links:
                            for link in unicode_links:
                                links.append(str(link))
                        storage = self.db.retrieve_all(key)
                        if not links:
                            if 'added' not in storage and 'notdl' not in storage:
                                wrong_hoster = '[' + self._SITE + '/Hoster fehlt] - ' + key
                                if 'wrong_hoster' not in storage:
                                    print(wrong_hoster)
                                    self.db.store(key, 'wrong_hoster')
                                    notify([wrong_hoster], self.configfile)
                                else:
                                    self.log_debug(wrong_hoster)
                        elif 'added' in storage:
                            self.log_debug(
                                "%s - Release ignoriert (bereits gefunden)" %
                                key)
                        else:
                            self.device = myjd_download(
                                self.configfile, self.dbfile, self.device, key,
                                "FeedCrawler", links, "")
                            if self.device:
                                self.db.store(key, 'added')
                                log_entry = '[Englisch] - ' + key + ' - [' + self._SITE + ']'
                                self.log_info(log_entry)
                                notify([log_entry], self.configfile)
                                added_items.append(log_entry)
                    else:
                        self.log_debug(
                            "%s - Releasezeitpunkt weniger als 30 Minuten in der Vergangenheit - wird ignoriert."
                            % key)
        else:
            self.log_debug("Liste ist leer. Stoppe Suche für " + self._SITE +
                           "!")
        return self.device
Ejemplo n.º 2
0
def dw_parse_download(self, release_url, title, language_id):
    if not check_valid_release(title, self.retail_only, self.hevc_retail,
                               self.dbfile):
        self.log_debug(
            title +
            u" - Release ignoriert (Gleiche oder bessere Quelle bereits vorhanden)"
        )
        return False
    if self.filename == 'List_ContentAll_Seasons':
        if not self.config.get("seasonpacks"):
            staffelpack = re.search(r"s\d.*(-|\.).*s\d", title.lower())
            if staffelpack:
                self.log_debug("%s - Release ignoriert (Staffelpaket)" % title)
                return False
        if not re.search(self.seasonssource, title.lower()):
            self.log_debug(title + " - Release hat falsche Quelle")
            return False
    try:
        release_info = get_url(release_url, self.configfile, self.dbfile)
        post_hosters = BeautifulSoup(release_info, 'lxml').find(
            "div", {
                "id": "download"
            }).findAll("img", src=re.compile(r"images/hosterimg"))
        hosters = []
        valid = False
        for hoster in post_hosters:
            hoster = hoster["title"].replace("Premium-Account bei ",
                                             "").replace("ddownload", "ddl")
            if hoster not in hosters:
                hosters.append(hoster)

        for hoster in hosters:
            if hoster:
                if check_hoster(hoster, self.configfile):
                    valid = True
        if not valid and not self.hoster_fallback:
            storage = self.db.retrieve_all(title)
            if 'added' not in storage and 'notdl' not in storage:
                wrong_hoster = '[SJ/Hoster fehlt] - ' + title
                if 'wrong_hoster' not in storage:
                    print(wrong_hoster)
                    self.db.store(title, 'wrong_hoster')
                    notify([wrong_hoster], self.configfile)
                else:
                    self.log_debug(wrong_hoster)
                return False
        else:
            return [title, release_url, language_id, False, False]
    except:
        print(self._INTERNAL_NAME +
              u" hat die Serien-API angepasst. Breche Download-Prüfung ab!")
        return False
Ejemplo n.º 3
0
def j_parse_download(self, series_url, title, language_id):
    if not check_valid_release(title, self.retail_only, self.hevc_retail,
                               self.dbfile):
        self.log_debug(
            title +
            u" - Release ignoriert (Gleiche oder bessere Quelle bereits vorhanden)"
        )
        return False
    if self.filename == 'List_ContentAll_Seasons':
        if not self.config.get("seasonpacks"):
            staffelpack = re.search(r"s\d.*(-|\.).*s\d", title.lower())
            if staffelpack:
                self.log_debug("%s - Release ignoriert (Staffelpaket)" % title)
                return False
        if not re.search(self.seasonssource, title.lower()):
            self.log_debug(title + " - Release hat falsche Quelle")
            return False
    try:
        series_info = get_url(series_url, self.configfile, self.dbfile)
        series_id = re.findall(r'data-mediaid="(.*?)"', series_info)[0]
        api_url = 'https://' + self.url + '/api/media/' + series_id + '/releases'

        response = get_url(api_url, self.configfile, self.dbfile, self.scraper)
        seasons = json.loads(response)
        for season in seasons:
            season = seasons[season]
            for item in season['items']:
                if item['name'] == title:
                    valid = False
                    for hoster in item['hoster']:
                        if hoster:
                            if check_hoster(hoster, self.configfile):
                                valid = True
                    if not valid and not self.hoster_fallback:
                        storage = self.db.retrieve_all(title)
                        if 'added' not in storage and 'notdl' not in storage:
                            wrong_hoster = '[SJ/Hoster fehlt] - ' + title
                            if 'wrong_hoster' not in storage:
                                print(wrong_hoster)
                                self.db.store(title, 'wrong_hoster')
                                notify([wrong_hoster], self.configfile)
                            else:
                                self.log_debug(wrong_hoster)
                            return False
                    else:
                        return [title, series_url, language_id, False, False]
    except:
        print(self._INTERNAL_NAME +
              u" hat die Serien-API angepasst. Breche Download-Prüfung ab!")
        return False
Ejemplo n.º 4
0
def send_package(self, title, link, language_id, season, episode, site):
    englisch = ''
    if language_id == 2:
        englisch = '/Englisch'
    if self.filename == 'List_ContentShows_Shows':
        link_placeholder = '[Episode' + englisch + '] - '
    elif self.filename == 'List_ContentShows_Shows_Regex':
        link_placeholder = '[Episode/RegEx' + englisch + '] - '
    elif self.filename == 'List_ContentShows_Seasons_Regex':
        link_placeholder = '[Staffel/RegEx' + englisch + '] - '
    elif self.filename == 'List_ContentAll_Seasons':
        link_placeholder = '[Staffel' + englisch + '] - '
    elif self.filename == 'List_CustomDJ_Documentaries':
        link_placeholder = '[Doku] - ' + englisch
    elif self.filename == 'List_CustomDJ_Documentaries_Regex':
        link_placeholder = '[Doku/RegEx] - ' + englisch
    else:
        return
    try:
        storage = self.db.retrieve_all(title)
    except Exception as e:
        self.log_debug("Fehler bei Datenbankzugriff: %s, Grund: %s" %
                       (e, title))

    if 'added' in storage or 'notdl' in storage:
        self.log_debug(title + " - Release ignoriert (bereits gefunden)")
    else:
        if season and episode:
            link = link.replace(
                '&_=',
                '&season=' + str(season) + '&episode=' + str(episode) + '&_=')
        download = add_decrypt(title, link, self.url, self.dbfile)
        if download:
            self.db.store(title, 'added')
            log_entry = link_placeholder + title + ' - [' + site + ']'
            self.log_info(log_entry)
            notify(["[Click'n'Load notwendig] - " + log_entry],
                   self.configfile)
            return log_entry
Ejemplo n.º 5
0
def download(payload, configfile, dbfile):
    hostnames = CrawlerConfig('Hostnames', configfile)
    sj = hostnames.get('sj')

    payload = decode_base64(payload).split("|")
    href = payload[0]
    title = payload[1]
    special = payload[2].strip().replace("None", "")

    series_url = 'https://' + sj + href
    series_info = get_url(series_url, configfile, dbfile)
    series_id = re.findall(r'data-mediaid="(.*?)"', series_info)[0]

    api_url = 'https://' + sj + '/api/media/' + series_id + '/releases'
    releases = get_url(api_url, configfile, dbfile)

    unsorted_seasons = json.loads(releases)

    listen = ["List_ContentShows_Shows", "List_ContentAll_Seasons"]
    for liste in listen:
        cont = ListDb(dbfile, liste).retrieve()
        list_title = sanitize(title)
        if not cont:
            cont = ""
        if list_title not in cont:
            ListDb(dbfile, liste).store(list_title)

    config = CrawlerConfig('ContentShows', configfile)
    english_ok = CrawlerConfig('FeedCrawler', configfile).get("english")
    quality = config.get('quality')
    ignore = config.get('rejectlist')

    result_seasons = {}
    result_episodes = {}

    seasons = {}
    for season in unsorted_seasons:
        if "sp" in season.lower():
            seasons[season] = unsorted_seasons[season]
    for season in unsorted_seasons:
        if "sp" not in season.lower():
            seasons[season] = unsorted_seasons[season]

    for season in seasons:
        releases = seasons[season]
        for release in releases['items']:
            name = release['name'].encode('ascii',
                                          errors='ignore').decode('utf-8')
            try:
                season = re.findall(r'.*\.(s\d{1,3}).*', name,
                                    re.IGNORECASE)[0]
            except:
                pass
            hosters = release['hoster']
            try:
                valid = bool(release['resolution'] == quality)
            except:
                valid = re.match(re.compile(r'.*' + quality + r'.*'), name)
            if valid and special:
                valid = bool("." + special.lower() + "." in name.lower())
            if valid and not english_ok:
                valid = bool(".german." in name.lower())
            if valid:
                valid = False
                for hoster in hosters:
                    if hoster and check_hoster(
                            hoster,
                            configfile) or config.get("hoster_fallback"):
                        valid = True
            if valid:
                try:
                    ep = release['episode']
                    if ep:
                        existing = result_episodes.get(season)
                        if existing:
                            valid = False
                            for e in existing:
                                if e == ep:
                                    if rate(name, ignore) > rate(
                                            existing[e], ignore):
                                        valid = True
                                else:
                                    valid = True
                            if valid:
                                existing.update({ep: name})
                        else:
                            existing = {ep: name}
                        result_episodes.update({season: existing})
                        continue
                except:
                    pass

                existing = result_seasons.get(season)
                dont = False
                if existing:
                    if rate(name, ignore) < rate(existing, ignore):
                        dont = True
                if not dont:
                    result_seasons.update({season: name})

        try:
            if result_seasons[season] and result_episodes[season]:
                del result_episodes[season]
        except:
            pass

        success = False
        try:
            if result_seasons[season]:
                success = True
        except:
            try:
                if result_episodes[season]:
                    success = True
            except:
                pass

        if success:
            logger.debug(u"Websuche erfolgreich für " + title + " - " + season)
        else:
            for release in releases['items']:
                name = release['name'].encode('ascii',
                                              errors='ignore').decode('utf-8')
                hosters = release['hoster']
                valid = True
                if valid and special:
                    valid = bool("." + special.lower() + "." in name.lower())
                if valid and not english_ok:
                    valid = bool(".german." in name.lower())
                if valid:
                    valid = False
                    for hoster in hosters:
                        if hoster and check_hoster(
                                hoster,
                                configfile) or config.get("hoster_fallback"):
                            valid = True
                if valid:
                    try:
                        ep = release['episode']
                        if ep:
                            existing = result_episodes.get(season)
                            if existing:
                                for e in existing:
                                    if e == ep:
                                        if rate(name, ignore) > rate(
                                                existing[e], ignore):
                                            existing.update({ep: name})
                            else:
                                existing = {ep: name}
                            result_episodes.update({season: existing})
                            continue
                    except:
                        pass

                    existing = result_seasons.get(season)
                    dont = False
                    if existing:
                        if rate(name, ignore) < rate(existing, ignore):
                            dont = True
                    if not dont:
                        result_seasons.update({season: name})

            try:
                if result_seasons[season] and result_episodes[season]:
                    del result_episodes[season]
            except:
                pass
            logger.debug(u"Websuche erfolgreich für " + title + " - " + season)

    matches = []

    for season in result_seasons:
        matches.append(result_seasons[season])
    for season in result_episodes:
        for episode in result_episodes[season]:
            matches.append(result_episodes[season][episode])

    notify_array = []
    for title in matches:
        db = FeedDb(dbfile, 'FeedCrawler')
        if add_decrypt(title, series_url, sj, dbfile):
            db.store(title, 'added')
            log_entry = u'[Suche/Serie] - ' + title + ' - [SJ]'
            logger.info(log_entry)
            notify_array.append(log_entry)

    notify(notify_array, configfile)

    if not matches:
        return False
    return matches
Ejemplo n.º 6
0
def download(payload, device, configfile, dbfile):
    config = CrawlerConfig('ContentAll', configfile)
    db = FeedDb(dbfile, 'FeedCrawler')
    hostnames = CrawlerConfig('Hostnames', configfile)
    by = hostnames.get('by')
    nk = hostnames.get('nk')

    payload = decode_base64(payload).split("|")
    link = payload[0]
    password = payload[1]

    site = check_is_site(link, configfile)
    if not site:
        return False
    elif "DW" in site:
        download_method = add_decrypt_instead_of_download
        download_links = [link]
        key = payload[1]
        password = payload[2]
    else:
        url = get_url(link, configfile, dbfile)
        if not url or "NinjaFirewall 429" in url:
            return False
        download_method = myjd_download
        soup = BeautifulSoup(url, 'lxml')

        if "BY" in site:
            key = soup.find("small").text
            links = soup.find_all("iframe")
            async_link_results = []
            for link in links:
                link = link["src"]
                if 'https://' + by in link:
                    async_link_results.append(link)
            async_link_results = get_urls_async(async_link_results, configfile,
                                                dbfile)
            links = async_link_results[0]
            url_hosters = []
            for link in links:
                if link:
                    link = BeautifulSoup(link, 'lxml').find(
                        "a", href=re.compile("/go\.php\?"))
                    if link:
                        url_hosters.append(
                            [link["href"],
                             link.text.replace(" ", "")])
        elif "NK" in site:
            key = soup.find("span", {"class": "subtitle"}).text
            url_hosters = []
            hosters = soup.find_all("a", href=re.compile("/go/"))
            for hoster in hosters:
                url_hosters.append(
                    ['https://' + nk + hoster["href"], hoster.text])
        elif "FX" in site:
            key = payload[1]
            password = payload[2]
        else:
            return False

        links = {}
        if "FX" in site:

            class FX:
                configfile = ""

            FX.configfile = configfile
            download_links = fx_get_download_links(FX, url, key)
        else:
            for url_hoster in reversed(url_hosters):
                try:
                    link_hoster = url_hoster[1].lower().replace(
                        'target="_blank">',
                        '').replace(" ", "-").replace("ddownload", "ddl")
                    if check_hoster(link_hoster, configfile):
                        link = url_hoster[0]
                        if by in link:
                            demasked_link = get_redirected_url(
                                link, configfile, dbfile, False)
                            if demasked_link:
                                link = demasked_link
                        links[link_hoster] = link
                except:
                    pass
            if config.get("hoster_fallback") and not links:
                for url_hoster in reversed(url_hosters):
                    link_hoster = url_hoster[1].lower().replace(
                        'target="_blank">',
                        '').replace(" ", "-").replace("ddownload", "ddl")
                    link = url_hoster[0]
                    if by in link:
                        demasked_link = get_redirected_url(
                            link, configfile, dbfile, False)
                        if demasked_link:
                            link = demasked_link
                    links[link_hoster] = link
            download_links = list(links.values())

    englisch = False
    if "*englisch" in key.lower() or "*english" in key.lower():
        key = key.replace('*ENGLISCH', '').replace("*Englisch", "").replace(
            "*ENGLISH", "").replace("*English", "").replace("*", "")
        englisch = True

    staffel = re.search(r"s\d{1,2}(-s\d{1,2}|-\d{1,2}|\.)", key.lower())

    if download_links:
        if staffel:
            if download_method(configfile, dbfile, device, key, "FeedCrawler",
                               download_links, password):
                db.store(
                    key.replace(".COMPLETE", "").replace(".Complete", ""),
                    'notdl' if config.get('enforcedl')
                    and '.dl.' not in key.lower() else 'added')
                log_entry = '[Suche/Staffel] - ' + key.replace(
                    ".COMPLETE", "").replace(".Complete",
                                             "") + ' - [' + site + ']'
                logger.info(log_entry)
                notify([log_entry], configfile)
                return True
        else:
            retail = False
            if config.get('cutoff') and '.COMPLETE.' not in key.lower():
                if is_retail(key, dbfile):
                    retail = True
            if download_method(configfile, dbfile, device, key, "FeedCrawler",
                               download_links, password):
                db.store(
                    key, 'notdl' if config.get('enforcedl')
                    and '.dl.' not in key.lower() else 'added')
                log_entry = '[Suche/Film' + (
                    '/Englisch' if englisch and not retail else
                    '') + ('/Englisch/Retail' if englisch and retail else
                           '') + ('/Retail' if not englisch and retail else
                                  '') + '] - ' + key + ' - [' + site + ']'
                logger.info(log_entry)
                notify([log_entry], configfile)
                return [key]
    else:
        return False
Ejemplo n.º 7
0
def sf_parse_download(self, series_url, title, language_id):
    if not check_valid_release(title, self.retail_only, self.hevc_retail,
                               self.dbfile):
        self.log_debug(
            title +
            u" - Release ignoriert (Gleiche oder bessere Quelle bereits vorhanden)"
        )
        return False
    if self.filename == 'List_ContentAll_Seasons':
        if not self.config.get("seasonpacks"):
            staffelpack = re.search(r"s\d.*(-|\.).*s\d", title.lower())
            if staffelpack:
                self.log_debug("%s - Release ignoriert (Staffelpaket)" % title)
                return False
        if not re.search(self.seasonssource, title.lower()):
            self.log_debug(title + " - Release hat falsche Quelle")
            return False
    try:
        if language_id == 2:
            lang = 'EN'
        else:
            lang = 'DE'
        epoch = str(datetime.datetime.now().timestamp()).replace('.', '')[:-3]
        api_url = series_url + '?lang=' + lang + '&_=' + epoch
        response = get_url(api_url, self.configfile, self.dbfile, self.scraper)
        info = json.loads(response)

        is_episode = re.findall(r'.*\.(s\d{1,3}e\d{1,3})\..*', title,
                                re.IGNORECASE)
        if is_episode:
            episode_string = re.findall(r'.*S\d{1,3}(E\d{1,3}).*',
                                        is_episode[0])[0].lower()
            season_string = re.findall(r'.*(S\d{1,3})E\d{1,3}.*',
                                       is_episode[0])[0].lower()
            season_title = rreplace(title.lower().replace(episode_string,
                                                          ''), "-", ".*",
                                    1).lower().replace(".repack", "")
            season_title = season_title.replace(".untouched", ".*").replace(
                ".dd+51", ".dd.51")
            episode = str(int(episode_string.replace("e", "")))
            season = str(int(season_string.replace("s", "")))
            episode_name = re.findall(r'.*\.s\d{1,3}(\..*).german',
                                      season_title, re.IGNORECASE)
            if episode_name:
                season_title = season_title.replace(episode_name[0], '')
            codec_tags = [".h264", ".x264"]
            for tag in codec_tags:
                season_title = season_title.replace(tag, ".*264")
            web_tags = [".web-rip", ".webrip", ".webdl", ".web-dl"]
            for tag in web_tags:
                season_title = season_title.replace(tag, ".web.*")
        else:
            season = False
            episode = False
            season_title = title
            multiple_episodes = re.findall(r'(e\d{1,3}-e*\d{1,3}\.)',
                                           season_title, re.IGNORECASE)
            if multiple_episodes:
                season_title = season_title.replace(multiple_episodes[0], '.*')

        content = BeautifulSoup(info['html'], 'lxml')
        releases = content.find(
            "small", text=re.compile(season_title,
                                     re.IGNORECASE)).parent.parent.parent
        links = releases.findAll("div", {'class': 'row'})[1].findAll('a')
        download_link = False
        for link in links:
            if check_hoster(link.text.replace('\n', ''), self.configfile):
                download_link = get_redirected_url(
                    "https://" + self.url + link['href'], self.configfile,
                    self.dbfile, self.scraper)
                break
        if not download_link and not self.hoster_fallback:
            storage = self.db.retrieve_all(title)
            if 'added' not in storage and 'notdl' not in storage:
                wrong_hoster = '[SF/Hoster fehlt] - ' + title
                if 'wrong_hoster' not in storage:
                    print(wrong_hoster)
                    self.db.store(title, 'wrong_hoster')
                    notify([wrong_hoster], self.configfile)
                else:
                    self.log_debug(wrong_hoster)
                return False
        else:
            return [title, download_link, language_id, season, episode]
    except:
        print(u"SF hat die Serien-API angepasst. Breche Download-Prüfung ab!")
        return False
Ejemplo n.º 8
0
def crawldog(configfile, dbfile):
    disable_request_warnings(InsecureRequestWarning)
    crawljobs = CrawlerConfig('Crawljobs', configfile)
    autostart = crawljobs.get("autostart")
    db = FeedDb(dbfile, 'crawldog')

    grabber_was_collecting = False
    grabber_collecting = False
    device = False

    while True:
        try:
            if not device or not is_device(device):
                device = get_device(configfile)

            myjd_packages = get_info(configfile, device)
            if myjd_packages:
                grabber_collecting = myjd_packages[2]

                if grabber_was_collecting or grabber_collecting:
                    grabber_was_collecting = grabber_collecting
                    time.sleep(5)
                else:
                    packages_in_downloader_decrypted = myjd_packages[4][0]
                    packages_in_linkgrabber_decrypted = myjd_packages[4][1]
                    offline_packages = myjd_packages[4][2]
                    encrypted_packages = myjd_packages[4][3]

                    try:
                        watched_titles = db.retrieve_all_titles()
                    except:
                        watched_titles = False

                    notify_list = []

                    if packages_in_downloader_decrypted or packages_in_linkgrabber_decrypted or offline_packages or encrypted_packages:

                        if watched_titles:
                            for title in watched_titles:
                                if packages_in_downloader_decrypted:
                                    for package in packages_in_downloader_decrypted:
                                        if title[0] in package[
                                                'name'] or title[0].replace(
                                                    ".",
                                                    " ") in package['name']:
                                            check = hoster_check(
                                                configfile, device, [package],
                                                title[0], [0])
                                            device = check[0]
                                            if device:
                                                db.delete(title[0])

                                if packages_in_linkgrabber_decrypted:
                                    for package in packages_in_linkgrabber_decrypted:
                                        if title[0] in package[
                                                'name'] or title[0].replace(
                                                    ".",
                                                    " ") in package['name']:
                                            check = hoster_check(
                                                configfile, device, [package],
                                                title[0], [0])
                                            device = check[0]
                                            episode = FeedDb(
                                                dbfile,
                                                'episode_remover').retrieve(
                                                    title[0])
                                            if episode:
                                                filenames = package[
                                                    'filenames']
                                                if len(filenames) > 1:
                                                    fname_episodes = []
                                                    for fname in filenames:
                                                        try:
                                                            if re.match(
                                                                    r'.*S\d{1,3}E\d{1,3}.*',
                                                                    fname,
                                                                    flags=re.
                                                                    IGNORECASE
                                                            ):
                                                                fname = re.findall(
                                                                    r'S\d{1,3}E(\d{1,3})',
                                                                    fname,
                                                                    flags=re.
                                                                    IGNORECASE
                                                                ).pop()
                                                            else:
                                                                fname = fname.replace(
                                                                    "hddl8", ""
                                                                ).replace(
                                                                    "dd51", ""
                                                                ).replace(
                                                                    "264", ""
                                                                ).replace(
                                                                    "265", "")
                                                        except:
                                                            fname = fname.replace(
                                                                "hddl8",
                                                                "").replace(
                                                                    "dd51", ""
                                                                ).replace(
                                                                    "264", ""
                                                                ).replace(
                                                                    "265", "")
                                                        fname_episode = "".join(
                                                            re.findall(
                                                                r'\d+',
                                                                fname.split(
                                                                    ".part")
                                                                [0]))
                                                        try:
                                                            fname_episodes.append(
                                                                str(
                                                                    int(fname_episode
                                                                        )))
                                                        except:
                                                            pass
                                                    replacer = longest_substr(
                                                        fname_episodes)

                                                    new_fname_episodes = []
                                                    for new_ep_fname in fname_episodes:
                                                        try:
                                                            new_fname_episodes.append(
                                                                str(
                                                                    int(
                                                                        new_ep_fname
                                                                        .
                                                                        replace(
                                                                            replacer,
                                                                            ""
                                                                        ))))
                                                        except:
                                                            pass
                                                    replacer = longest_substr(
                                                        new_fname_episodes)

                                                    newer_fname_episodes = []
                                                    for new_ep_fname in new_fname_episodes:
                                                        try:
                                                            newer_fname_episodes.append(
                                                                str(
                                                                    int(
                                                                        re.sub(
                                                                            replacer,
                                                                            "",
                                                                            new_ep_fname,
                                                                            1))
                                                                ))
                                                        except:
                                                            pass

                                                    replacer = longest_substr(
                                                        newer_fname_episodes)

                                                    even_newer_fname_episodes = []
                                                    for newer_ep_fname in newer_fname_episodes:
                                                        try:
                                                            even_newer_fname_episodes.append(
                                                                str(
                                                                    int(
                                                                        re.sub(
                                                                            replacer,
                                                                            "",
                                                                            newer_ep_fname,
                                                                            1))
                                                                ))
                                                        except:
                                                            pass

                                                    if even_newer_fname_episodes:
                                                        fname_episodes = even_newer_fname_episodes
                                                    elif newer_fname_episodes:
                                                        fname_episodes = newer_fname_episodes
                                                    elif new_fname_episodes:
                                                        fname_episodes = new_fname_episodes

                                                    delete_linkids = []
                                                    pos = 0
                                                    for delete_id in package[
                                                            'linkids']:
                                                        if str(episode) != str(
                                                                fname_episodes[
                                                                    pos]):
                                                            delete_linkids.append(
                                                                delete_id)
                                                        pos += 1
                                                    if delete_linkids:
                                                        delete_uuids = [
                                                            package['uuid']
                                                        ]
                                                        FeedDb(
                                                            dbfile,
                                                            'episode_remover'
                                                        ).delete(title[0])
                                                        device = remove_from_linkgrabber(
                                                            configfile, device,
                                                            delete_linkids,
                                                            delete_uuids)
                                            if autostart:
                                                device = move_to_downloads(
                                                    configfile, device,
                                                    package['linkids'],
                                                    [package['uuid']])
                                            if device:
                                                db.delete(title[0])

                                if offline_packages:
                                    for package in offline_packages:
                                        if title[0] in package[
                                                'name'] or title[0].replace(
                                                    ".",
                                                    " ") in package['name']:
                                            notify_list.append("[Offline] - " +
                                                               title[0])
                                            print((u"[Offline] - " + title[0]))
                                            db.delete(title[0])

                                if encrypted_packages:
                                    for package in encrypted_packages:
                                        if title[0] in package[
                                                'name'] or title[0].replace(
                                                    ".",
                                                    " ") in package['name']:
                                            if title[1] == 'added':
                                                if retry_decrypt(
                                                        configfile, dbfile,
                                                        device,
                                                        package['linkids'],
                                                    [package['uuid']],
                                                        package['urls']):
                                                    db.delete(title[0])
                                                    db.store(
                                                        title[0], 'retried')
                                            else:
                                                add_decrypt(
                                                    package['name'],
                                                    package['url'], "", dbfile)
                                                device = remove_from_linkgrabber(
                                                    configfile, device,
                                                    package['linkids'],
                                                    [package['uuid']])
                                                notify_list.append(
                                                    "[Click'n'Load notwendig] - "
                                                    + title[0])
                                                print(
                                                    u"[Click'n'Load notwendig] - "
                                                    + title[0])
                                                db.delete(title[0])
                    else:
                        if not grabber_collecting:
                            db.reset()

                    if notify_list:
                        notify(notify_list, configfile)

                time.sleep(30)
            else:
                print(
                    u"Scheinbar ist der JDownloader nicht erreichbar - bitte prüfen und neustarten!"
                )
        except Exception:
            traceback.print_exc()
            time.sleep(30)