コード例 #1
0
ファイル: main.py プロジェクト: Elandril/CouchPotatoServer
    def createFromSearch(self, search_results, media, quality):

        try:
            db = get_db()

            found_releases = []

            is_3d = False
            try: is_3d = quality['custom']['3d']
            except: pass

            for rel in search_results:

                rel_identifier = md5(rel['url'])
                found_releases.append(rel_identifier)

                release = {
                    '_t': 'release',
                    'identifier': rel_identifier,
                    'media_id': media.get('_id'),
                    'quality': quality.get('identifier'),
                    'is_3d': is_3d,
                    'status': rel.get('status', 'available'),
                    'last_edit': int(time.time()),
                    'info': {}
                }

                # Add downloader info if provided
                try:
                    release['download_info'] = rel['download_info']
                    del rel['download_info']
                except:
                    pass

                try:
                    rls = db.get('release_identifier', rel_identifier, with_doc = True)['doc']
                except:
                    rls = db.insert(release)
                    rls.update(release)

                # Update info, but filter out functions
                for info in rel:
                    try:
                        if not isinstance(rel[info], (str, unicode, int, long, float)):
                            continue

                        rls['info'][info] = toUnicode(rel[info]) if isinstance(rel[info], (str, unicode)) else rel[info]
                    except:
                        log.debug('Couldn\'t add %s to ReleaseInfo: %s', (info, traceback.format_exc()))

                db.update(rls)

                # Update release in search_results
                rel['status'] = rls.get('status')

            return found_releases
        except:
            log.error('Failed: %s', traceback.format_exc())

        return []
コード例 #2
0
ファイル: main.py プロジェクト: willko23/CouchPotatoServer
    def createFromSearch(self, search_results, media, quality_type):

        available_status = fireEvent('status.get', ['available'], single=True)

        try:
            db = get_session()

            found_releases = []

            for rel in search_results:

                rel_identifier = md5(rel['url'])
                found_releases.append(rel_identifier)

                rls = db.query(Relea).filter_by(
                    identifier=rel_identifier).first()
                if not rls:
                    rls = Relea(
                        identifier=rel_identifier,
                        movie_id=media.get('id'),
                        #media_id = media.get('id'),
                        quality_id=quality_type.get('quality_id'),
                        status_id=available_status.get('id'))
                    db.add(rls)
                else:
                    [db.delete(old_info) for old_info in rls.info]
                    rls.last_edit = int(time.time())

                db.commit()

                for info in rel:
                    try:
                        if not isinstance(rel[info],
                                          (str, unicode, int, long, float)):
                            continue

                        rls_info = ReleaseInfo(identifier=info,
                                               value=toUnicode(rel[info]))
                        rls.info.append(rls_info)
                    except InterfaceError:
                        log.debug('Couldn\'t add %s to ReleaseInfo: %s',
                                  (info, traceback.format_exc()))

                db.commit()

                rel['status_id'] = rls.status_id

            return found_releases
        except:
            log.error('Failed: %s', traceback.format_exc())
            db.rollback()
        finally:
            db.close()

        return []
コード例 #3
0
ファイル: main.py プロジェクト: Bart1983/CouchPotatoServer
    def createFromSearch(self, search_results, media, quality_type):

        available_status = fireEvent('status.get', ['available'], single = True)

        try:
            db = get_session()

            found_releases = []

            for rel in search_results:

                rel_identifier = md5(rel['url'])
                found_releases.append(rel_identifier)

                rls = db.query(Relea).filter_by(identifier = rel_identifier).first()
                if not rls:
                    rls = Relea(
                        identifier = rel_identifier,
                        movie_id = media.get('id'),
                        #media_id = media.get('id'),
                        quality_id = quality_type.get('quality_id'),
                        status_id = available_status.get('id')
                    )
                    db.add(rls)
                else:
                    [db.delete(old_info) for old_info in rls.info]
                    rls.last_edit = int(time.time())

                db.commit()

                for info in rel:
                    try:
                        if not isinstance(rel[info], (str, unicode, int, long, float)):
                            continue

                        rls_info = ReleaseInfo(
                            identifier = info,
                            value = toUnicode(rel[info])
                        )
                        rls.info.append(rls_info)
                    except InterfaceError:
                        log.debug('Couldn\'t add %s to ReleaseInfo: %s', (info, traceback.format_exc()))

                db.commit()

                rel['status_id'] = rls.status_id

            return found_releases
        except:
            log.error('Failed: %s', traceback.format_exc())
            db.rollback()
        finally:
            db.close()

        return []
コード例 #4
0
    def getPoster(self, media, image_urls):
        if 'files' not in media:
            media['files'] = {}

        existing_files = media['files']

        image_type = 'poster'
        file_type = 'image_%s' % image_type

        # Make existing unique
        unique_files = list(set(existing_files.get(file_type, [])))

        # Remove files that can't be found
        for ef in unique_files:
            if not os.path.isfile(ef):
                unique_files.remove(ef)

        # Replace new files list
        existing_files[file_type] = unique_files
        if len(existing_files) == 0:
            del existing_files[file_type]

        images = image_urls.get(image_type, [])
        for y in ['SX300', 'tmdb']:
            initially_try = [x for x in images if y in x]
            images[:-1] = initially_try

        # Loop over type
        for image in images:
            if not isinstance(image, (str, unicode)):
                continue

            # Check if it has top image
            filename = '%s.%s' % (md5(image), getExt(image))
            existing = existing_files.get(file_type, [])
            has_latest = False
            for x in existing:
                if filename in x:
                    has_latest = True

            if not has_latest or file_type not in existing_files or len(existing_files.get(file_type, [])) == 0:
                file_path = fireEvent('file.download', url = image, single = True)
                if file_path:
                    existing_files[file_type] = [toUnicode(file_path)]
                    break
            else:
                break
コード例 #5
0
    def download(self, data, media, manual=False):

        if not data.get('protocol'):
            data['protocol'] = data['type']
            data['type'] = 'movie'

        # Test to see if any downloaders are enabled for this type
        downloader_enabled = fireEvent('download.enabled',
                                       manual,
                                       data,
                                       single=True)

        if downloader_enabled:
            snatched_status, done_status, active_status = fireEvent(
                'status.get', ['snatched', 'done', 'active'], single=True)

            # Download release to temp
            filedata = None
            if data.get('download') and (ismethod(data.get('download'))
                                         or isfunction(data.get('download'))):
                filedata = data.get('download')(url=data.get('url'),
                                                nzb_id=data.get('id'))
                if filedata == 'try_next':
                    return filedata

            download_result = fireEvent('download',
                                        data=data,
                                        movie=media,
                                        manual=manual,
                                        filedata=filedata,
                                        single=True)
            log.debug('Downloader result: %s', download_result)

            if download_result:
                try:
                    # Mark release as snatched
                    db = get_session()
                    rls = db.query(Relea).filter_by(
                        identifier=md5(data['url'])).first()
                    if rls:
                        renamer_enabled = Env.setting('enabled', 'renamer')

                        # Save download-id info if returned
                        if isinstance(download_result, dict):
                            for key in download_result:
                                rls_info = ReleaseInfo(
                                    identifier='download_%s' % key,
                                    value=toUnicode(download_result.get(key)))
                                rls.info.append(rls_info)
                        db.commit()

                        log_movie = '%s (%s) in %s' % (getTitle(
                            media['library']), media['library']['year'],
                                                       rls.quality.label)
                        snatch_message = 'Snatched "%s": %s' % (
                            data.get('name'), log_movie)
                        log.info(snatch_message)
                        fireEvent('%s.snatched' % data['type'],
                                  message=snatch_message,
                                  data=rls.to_dict())

                        # If renamer isn't used, mark media done
                        if not renamer_enabled:
                            try:
                                if media['status_id'] == active_status.get(
                                        'id'):
                                    for profile_type in media['profile'][
                                            'types']:
                                        if profile_type[
                                                'quality_id'] == rls.quality.id and profile_type[
                                                    'finish']:
                                            log.info(
                                                'Renamer disabled, marking media as finished: %s',
                                                log_movie)

                                            # Mark release done
                                            self.updateStatus(
                                                rls.id, status=done_status)

                                            # Mark media done
                                            mdia = db.query(Media).filter_by(
                                                id=media['id']).first()
                                            mdia.status_id = done_status.get(
                                                'id')
                                            mdia.last_edit = int(time.time())
                                            db.commit()
                            except:
                                log.error(
                                    'Failed marking media finished, renamer disabled: %s',
                                    traceback.format_exc())
                        else:
                            self.updateStatus(rls.id, status=snatched_status)

                except:
                    log.error('Failed marking media finished: %s',
                              traceback.format_exc())

                return True

        log.info(
            'Tried to download, but none of the "%s" downloaders are enabled or gave an error',
            (data.get('protocol')))

        return False
コード例 #6
0
ファイル: main.py プロジェクト: Elandril/CouchPotatoServer
    def download(self, data, media, manual = False):

        # Test to see if any downloaders are enabled for this type
        downloader_enabled = fireEvent('download.enabled', manual, data, single = True)
        if not downloader_enabled:
            log.info('Tried to download, but none of the "%s" downloaders are enabled or gave an error', data.get('protocol'))
            return False

        # Download NZB or torrent file
        filedata = None
        if data.get('download') and (ismethod(data.get('download')) or isfunction(data.get('download'))):
            try:
                filedata = data.get('download')(url = data.get('url'), nzb_id = data.get('id'))
            except:
                log.error('Tried to download, but the "%s" provider gave an error: %s', (data.get('protocol'), traceback.format_exc()))
                return False

            if filedata == 'try_next':
                return filedata
            elif not filedata:
                return False

        # Send NZB or torrent file to downloader
        download_result = fireEvent('download', data = data, media = media, manual = manual, filedata = filedata, single = True)
        if not download_result:
            log.info('Tried to download, but the "%s" downloader gave an error', data.get('protocol'))
            return False
        log.debug('Downloader result: %s', download_result)

        try:
            db = get_db()

            try:
                rls = db.get('release_identifier', md5(data['url']), with_doc = True)['doc']
            except:
                log.error('No release found to store download information in')
                return False

            renamer_enabled = Env.setting('enabled', 'renamer')

            # Save download-id info if returned
            if isinstance(download_result, dict):
                rls['download_info'] = download_result
                db.update(rls)

            log_movie = '%s (%s) in %s' % (getTitle(media), media['info'].get('year'), rls['quality'])
            snatch_message = 'Snatched "%s": %s' % (data.get('name'), log_movie)
            log.info(snatch_message)
            fireEvent('%s.snatched' % data['type'], message = snatch_message, data = media)

            # Mark release as snatched
            if renamer_enabled:
                self.updateStatus(rls['_id'], status = 'snatched')

            # If renamer isn't used, mark media done if finished or release downloaded
            else:

                if media['status'] == 'active':
                    profile = db.get('id', media['profile_id'])
                    if fireEvent('quality.isfinish', {'identifier': rls['quality'], 'is_3d': rls.get('is_3d', False)}, profile, single = True):
                        log.info('Renamer disabled, marking media as finished: %s', log_movie)

                        # Mark release done
                        self.updateStatus(rls['_id'], status = 'done')

                        # Mark media done
                        fireEvent('media.restatus', media['_id'], single = True)

                        return True

                # Assume release downloaded
                self.updateStatus(rls['_id'], status = 'downloaded')

        except:
            log.error('Failed storing download status: %s', traceback.format_exc())
            return False

        return True
コード例 #7
0
    def createFromSearch(self, search_results, media, quality):

        try:
            db = get_db()

            found_releases = []

            is_3d = False
            try:
                is_3d = quality['custom']['3d']
            except:
                pass

            for rel in search_results:

                rel_identifier = md5(rel['url'])
                found_releases.append(rel_identifier)

                release = {
                    '_t': 'release',
                    'identifier': rel_identifier,
                    'media_id': media.get('_id'),
                    'quality': quality.get('identifier'),
                    'is_3d': is_3d,
                    'status': rel.get('status', 'available'),
                    'last_edit': int(time.time()),
                    'info': {}
                }

                # Add downloader info if provided
                try:
                    release['download_info'] = rel['download_info']
                    del rel['download_info']
                except:
                    pass

                try:
                    rls = db.get('release_identifier',
                                 rel_identifier,
                                 with_doc=True)['doc']
                except:
                    rls = db.insert(release)
                    rls.update(release)

                # Update info, but filter out functions
                for info in rel:
                    try:
                        if not isinstance(rel[info],
                                          (str, unicode, int, long, float)):
                            continue

                        rls['info'][info] = toUnicode(rel[info]) if isinstance(
                            rel[info], (str, unicode)) else rel[info]
                    except:
                        log.debug('Couldn\'t add %s to ReleaseInfo: %s',
                                  (info, traceback.format_exc()))

                db.update(rls)

                # Update release in search_results
                rel['status'] = rls.get('status')

            return found_releases
        except:
            log.error('Failed: %s', traceback.format_exc())

        return []
コード例 #8
0
    def download(self, data, media, manual=False):

        # Test to see if any downloaders are enabled for this type
        downloader_enabled = fireEvent('download.enabled',
                                       manual,
                                       data,
                                       single=True)
        if not downloader_enabled:
            log.info(
                'Tried to download, but none of the "%s" downloaders are enabled or gave an error',
                data.get('protocol'))
            return False

        # Download NZB or torrent file
        filedata = None
        if data.get('download') and (ismethod(data.get('download'))
                                     or isfunction(data.get('download'))):
            try:
                filedata = data.get('download')(url=data.get('url'),
                                                nzb_id=data.get('id'))
            except:
                log.error(
                    'Tried to download, but the "%s" provider gave an error: %s',
                    (data.get('protocol'), traceback.format_exc()))
                return False

            if filedata == 'try_next':
                return filedata
            elif not filedata:
                return False

        # Send NZB or torrent file to downloader
        download_result = fireEvent('download',
                                    data=data,
                                    media=media,
                                    manual=manual,
                                    filedata=filedata,
                                    single=True)
        if not download_result:
            log.info(
                'Tried to download, but the "%s" downloader gave an error',
                data.get('protocol'))
            return False
        log.debug('Downloader result: %s', download_result)

        try:
            db = get_db()

            try:
                rls = db.get('release_identifier',
                             md5(data['url']),
                             with_doc=True)['doc']
            except:
                log.error('No release found to store download information in')
                return False

            renamer_enabled = Env.setting('enabled', 'renamer')

            # Save download-id info if returned
            if isinstance(download_result, dict):
                rls['download_info'] = download_result
                db.update(rls)

            log_movie = '%s (%s) in %s' % (
                getTitle(media), media['info']['year'], rls['quality'])
            snatch_message = 'Snatched "%s": %s' % (data.get('name'),
                                                    log_movie)
            log.info(snatch_message)
            fireEvent('%s.snatched' % data['type'],
                      message=snatch_message,
                      data=media)

            # Mark release as snatched
            if renamer_enabled:
                self.updateStatus(rls['_id'], status='snatched')

            # If renamer isn't used, mark media done if finished or release downloaded
            else:

                if media['status'] == 'active':
                    profile = db.get('id', media['profile_id'])
                    if fireEvent('quality.isfinish', {
                            'identifier': rls['quality'],
                            'is_3d': rls.get('is_3d', False)
                    },
                                 profile,
                                 single=True):
                        log.info(
                            'Renamer disabled, marking media as finished: %s',
                            log_movie)

                        # Mark release done
                        self.updateStatus(rls['_id'], status='done')

                        # Mark media done
                        fireEvent('media.restatus', media['_id'], single=True)

                        return True

                # Assume release downloaded
                self.updateStatus(rls['_id'], status='downloaded')

        except:
            log.error('Failed storing download status: %s',
                      traceback.format_exc())
            return False

        return True
コード例 #9
0
    def download(self, data, media, manual = False):

        if not data.get('protocol'):
            data['protocol'] = data['type']
            data['type'] = 'movie'

        # Test to see if any downloaders are enabled for this type
        downloader_enabled = fireEvent('download.enabled', manual, data, single = True)

        if downloader_enabled:
            snatched_status, done_status, active_status = fireEvent('status.get', ['snatched', 'done', 'active'], single = True)

            # Download release to temp
            filedata = None
            if data.get('download') and (ismethod(data.get('download')) or isfunction(data.get('download'))):
                filedata = data.get('download')(url = data.get('url'), nzb_id = data.get('id'))
                if filedata == 'try_next':
                    return filedata

            download_result = fireEvent('download', data = data, movie = media, manual = manual, filedata = filedata, single = True)
            log.debug('Downloader result: %s', download_result)

            if download_result:
                try:
                    # Mark release as snatched
                    db = get_session()
                    rls = db.query(Relea).filter_by(identifier = md5(data['url'])).first()
                    if rls:
                        renamer_enabled = Env.setting('enabled', 'renamer')

                        # Save download-id info if returned
                        if isinstance(download_result, dict):
                            for key in download_result:
                                rls_info = ReleaseInfo(
                                    identifier = 'download_%s' % key,
                                    value = toUnicode(download_result.get(key))
                                )
                                rls.info.append(rls_info)
                        db.commit()

                        log_movie = '%s (%s) in %s' % (getTitle(media['library']), media['library']['year'], rls.quality.label)
                        snatch_message = 'Snatched "%s": %s' % (data.get('name'), log_movie)
                        log.info(snatch_message)
                        fireEvent('%s.snatched' % data['type'], message = snatch_message, data = rls.to_dict())

                        # If renamer isn't used, mark media done
                        if not renamer_enabled:
                            try:
                                if media['status_id'] == active_status.get('id'):
                                    for profile_type in media['profile']['types']:
                                        if profile_type['quality_id'] == rls.quality.id and profile_type['finish']:
                                            log.info('Renamer disabled, marking media as finished: %s', log_movie)

                                            # Mark release done
                                            self.updateStatus(rls.id, status = done_status)

                                            # Mark media done
                                            mdia = db.query(Media).filter_by(id = media['id']).first()
                                            mdia.status_id = done_status.get('id')
                                            mdia.last_edit = int(time.time())
                                            db.commit()
                            except:
                                log.error('Failed marking media finished, renamer disabled: %s', traceback.format_exc())
                        else:
                            self.updateStatus(rls.id, status = snatched_status)

                except:
                    log.error('Failed marking media finished: %s', traceback.format_exc())

                return True

        log.info('Tried to download, but none of the "%s" downloaders are enabled or gave an error', (data.get('protocol')))

        return False