コード例 #1
0
    def add_movie_to_radarr(self, tmdb_info):
        """Perform a POST request to the Radarr API to add a new movie based on a TMDB_Info object."""

        payload = {
            'title':
            tmdb_info.title,
            'year':
            tmdb_info.year,
            'qualityProfileId':
            self.RADARR_QUALITY_PROFILE,
            'rootFolderPath':
            self.RADARR_ROOT_PATH,
            'tmdbId':
            tmdb_info.id,
            'titleSlug':
            tmdb_info.title_slug,
            'images': [{
                'covertype': 'poster',
                'url': '{}'.format(tmdb_info.poster_url)
            }],
            'addOptions': {
                'searchForMovie': 'true'
            }
        }
        try:
            requests.post('{}/api/movie?apikey={}'.format(
                self.RADARR_API_URL, self.RADARR_API_KEY),
                          data=json.dumps(payload))
        except Exception as e:
            log.log_to_file(
                'There was an error performing the Radarr post request: {0} \n'
                .format(e))
            raise Exception(
                'There was an error performing the Radarr post request')
コード例 #2
0
    def get_movies(self):
        """Perform an API Request for all movies in your configured Radarr library"""

        radarr_movie_titles = []
        try:
            radarr_get_url = '{}/api/movie?apikey={}'.format(
                self.RADARR_API_URL, self.RADARR_API_KEY)
            radarr_page_request = requests.get(radarr_get_url,
                                               allow_redirects=False)
            radarr_movies_json = radarr_page_request.json()
        except Exception as e:
            log.log_to_file(
                'There was an error retrieving movies from Radarr: {0} \n'.
                format(e))
            raise Exception('There was an error retrieving movies from Radarr')

        for movie in radarr_movies_json:
            movie_title = json.dumps(movie['title'])
            movie_title = movie_title.replace('"', '')
            radarr_movie_titles.append(movie_title)

        return radarr_movie_titles
コード例 #3
0
    def create_tmdb_obj(self, letterboxd_response):
        """Create TMDB_Info objects from info parsed from a letterboxd movie page."""
        try:
            soup = BeautifulSoup(letterboxd_response.text, 'html.parser')

            tmdb_element = soup.find('a', attrs={'data-track-action': 'TMDb'})
            tmdb_url = tmdb_element.get('href')
            try:
                if 'tv' in tmdb_url:
                    log.log_to_file(
                        'Found a TMDB url incompatible with Radarr: {0}.\n'.
                        format(tmdb_url))
                    return None
                else:
                    tmdb_id = (tmdb_url.split('/movie/',
                                              1)[1]).replace('/', '')

                film_title_element = soup.find('h1',
                                               attrs={'itemprop': 'name'})
                film_title = film_title_element.get_text()

                film_image_element = soup.find('img',
                                               attrs={'itemprop': 'image'})
                film_image = film_image_element.get('src')

                date_published_element = soup.find(
                    'small', attrs={'itemprop': 'datePublished'})
                date_anchor = date_published_element.find('a')
                film_published_date = date_anchor.get_text()

                tmdb_obj = tmdb_info.TMDB_Info(film_title, film_published_date,
                                               tmdb_id, film_image)
            except Exception as e:
                log.log_to_file(
                    'Failed to create TMDB object from url: {0}'.format(
                        tmdb_url))

            return tmdb_obj
        except TypeError as e:
            log.log_to_file(
                'TypeError while parsing letterboxd response: {0} \n'.format(
                    e))
        except Exception as e:
            log.log_to_file('Exception Args: {0} \n'.format(e.args))
            raise Exception('Failure while parsing letterboxd response')
コード例 #4
0
    def get_lists(self):
        movies = []

        for list_url in self.LETTERBOXD_LISTS:
            try:
                letterboxd_page_req = requests.get('https://letterboxd.com/' +
                                                   list_url)
                soup = BeautifulSoup(letterboxd_page_req.text, 'html.parser')

                if (soup.find_all(class_='paginate-page')):
                    pages = soup.find_all(class_='paginate-page')
                    for page_element in pages:
                        pass
                    if page_element:
                        num_of_pages = int(page_element.getText())
                    else:
                        num_of_pages = len(pages)
                    for page_num in range(1, num_of_pages + 1):

                        page_request = requests.get(
                            'https://letterboxd.com/{}/page/{}'.format(
                                list_url, page_num))
                        page_soup = BeautifulSoup(page_request.text,
                                                  'html.parser')

                        for frame_title in page_soup.find_all(
                                'div', class_='film-poster'):
                            letterboxd_url_sub = frame_title.get(
                                'data-film-slug')
                            letterboxd_film_url = 'https://letterboxd.com{}'.format(
                                letterboxd_url_sub)
                            film_page_request = requests.get(
                                letterboxd_film_url, allow_redirects=False)
                            if (film_page_request.status_code
                                    in [200, 201, 202, 203, 204, 205, 206]):
                                tmdb_obj = self.helpers.create_tmdb_obj(
                                    film_page_request)
                                if (tmdb_obj):
                                    movies.append(tmdb_obj)
                            else:
                                log.log_to_file("{} was unavailable \n".format(
                                    letterboxd_film_url,
                                    allow_redirects=False))
                else:
                    for frame_title in soup.find_all('div',
                                                     class_='film-poster'):
                        letterboxd_url_sub = frame_title.get('data-film-slug')
                        letterboxd_film_url = 'https://letterboxd.com{}'.format(
                            letterboxd_url_sub)
                        film_page_request = requests.get(letterboxd_film_url,
                                                         allow_redirects=False)
                        tmdb_obj = self.helpers.create_tmdb_obj(
                            film_page_request)
                        if (tmdb_obj):
                            movies.append(tmdb_obj)
            except Exception as e:
                log.log_to_file(
                    'There was an error retrieving films from Letterboxd: {0} \n'
                    .format(e))
                raise Exception(
                    'There was an error retrieving films from Letterboxd')
        return movies