Exemple #1
0
 def setUp(self):
     movie = WatchMovie(name='Rambo', release_date=datetime(1982, 1, 1))
     movie_with_colon = WatchMovie(name='The Lego Movie 2: The Second Part',
                                   release_date=datetime(2019, 1, 1))
     show = WatchTVShow(name='Rick and Morty')
     season = WatchTVSeason(watch_tv_show=show, season_number=1)
     episode = WatchTVEpisode(watch_tv_show=show,
                              season_number=1,
                              episode_number=14)
     self.tests = [
         # movie folder
         (movie, "Rambo.1982.1080p.BluRay", None, "Rambo (1982)", False),
         # movie single file
         (movie, "Rambo.1982.1080p.BluRay.mkv", "Rambo (1982)",
          "Rambo (1982).mkv", True),
         # movie folder with a colon in the name which should be replaced with a hyphen
         (movie_with_colon, "The.Lego.Movie.2:The.Second.Part", None,
          "The Lego Movie 2 - The Second Part (2019)", False),
         # full season
         (season,
          "Rick.and.Morty.S01.720p.AMZN.WEBRip.DDP5.1.x264-NTb[rartv]",
          "Rick and Morty", "Rick and Morty - Season 01", False),
         # single episode folder
         (episode,
          "Rick.and.Morty.S01E14.720p.AMZN.WEBRip.DDP5.1.x264-NTb[rartv]",
          "Rick and Morty/Season 01", "Rick and Morty - S01E14", False),
         # single episode single file
         (episode,
          "Rick.and.Morty.S01E14.720p.AMZN.WEBRip.DDP5.1.x264-NTb[rartv].mkv",
          "Rick and Morty/Season 01", "Rick and Morty - S01E14.mkv", True),
     ]
Exemple #2
0
    def test_movie(self):
        # populate some required data
        nefarious_settings = NefariousSettings()
        # required tmdb config data for saving models
        nefarious_settings.tmdb_configuration = {
            'images': {
                'secure_base_url': 'https://image.tmdb.org/t/p/',
            },
        }
        tmdb_client = get_tmdb_client(nefarious_settings)
        # use the first super user account to assign media
        user = User.objects.create_superuser('test', '*****@*****.**', 'test')

        # import
        importer = MovieImporter(
            nefarious_settings=nefarious_settings,
            root_path='/test-download',
            tmdb_client=tmdb_client,
            user=user,
        )
        for test_result in self.movie_tests:
            # prepend '/movie' to the test path
            test_path = os.path.join('/movie', test_result[0])
            import_result = importer.ingest_path(test_path)
            if test_result[1] is False or import_result is False:
                self.assertEqual(
                    test_result[1], import_result,
                    '{} != {}'.format(test_result[1], import_result))
            else:
                watch_movie = WatchMovie(name=test_result[1])
                self.assertTrue(
                    watch_movie.name == import_result.name,
                    '{} != {}'.format(watch_movie.name, import_result.name))
Exemple #3
0
 def setUp(self):
     movie = WatchMovie(name='Rambo', release_date=datetime(1982, 1, 1))
     show = WatchTVShow(name='Rick and Morty')
     season = WatchTVSeason(watch_tv_show=show, season_number=1)
     episode = WatchTVEpisode(watch_tv_show=show,
                              season_number=1,
                              episode_number=14)
     self.tests = [
         # movie folder
         (movie, "Rambo.1982.1080p.BluRay", None, "Rambo (1982)", False),
         # movie single file
         (movie, "Rambo.1982.1080p.BluRay.mkv", "Rambo (1982)",
          "Rambo (1982).mkv", True),
         # full season
         (season,
          "Rick.and.Morty.S01.720p.AMZN.WEBRip.DDP5.1.x264-NTb[rartv]",
          "Rick and Morty", "Rick and Morty - Season 01", False),
         # single episode folder
         (episode,
          "Rick.and.Morty.S01E14.720p.AMZN.WEBRip.DDP5.1.x264-NTb[rartv]",
          "Rick and Morty/Season 01", "Rick and Morty - S01E14", False),
         # single episode single file
         (episode,
          "Rick.and.Morty.S01E14.720p.AMZN.WEBRip.DDP5.1.x264-NTb[rartv].mkv",
          "Rick and Morty/Season 01", "Rick and Morty - S01E14.mkv", True),
     ]
Exemple #4
0
    def post(self, request):
        result = {
            'success': True,
        }
        nefarious_settings = NefariousSettings.get()

        tmdb_media = request.data.get('tmdb_media', {})
        torrent_info = request.data.get('torrent', {})
        torrent_url = torrent_info.get('MagnetUri') or torrent_info.get('Link')

        if not torrent_url:
            return Response({
                'success': False,
                'error': 'Missing torrent link'
            })

        media_type = request.data.get('media_type', MEDIA_TYPE_TV)

        # validate tv
        if media_type == MEDIA_TYPE_TV:
            if 'season_number' not in request.data:
                return Response({
                    'success': False,
                    'error': 'Missing season_number'
                })

        if not is_magnet_url(torrent_url):
            torrent_url = swap_jackett_host(torrent_url, nefarious_settings)

        try:
            torrent_url = trace_torrent_url(torrent_url)
        except Exception as e:
            return Response({
                'success': False,
                'error': 'An unknown error occurred',
                'error_detail': str(e)
            })

        logger_foreground.info('adding torrent: {}'.format(torrent_url))

        # add torrent
        transmission_client = get_transmission_client(nefarious_settings)
        transmission_session = transmission_client.session_stats()

        tmdb = get_tmdb_client(nefarious_settings)

        # set download paths and associate torrent with watch instance
        if media_type == MEDIA_TYPE_MOVIE:
            tmdb_request = tmdb.Movies(tmdb_media['id'])
            tmdb_movie = tmdb_request.info()
            watch_media = WatchMovie(
                user=request.user,
                tmdb_movie_id=tmdb_movie['id'],
                name=tmdb_movie['title'],
                poster_image_url=nefarious_settings.get_tmdb_poster_url(
                    tmdb_movie['poster_path']),
                release_date=parse_date(tmdb_movie['release_date'] or ''),
            )
            watch_media.save()
            download_dir = os.path.join(
                transmission_session.download_dir,
                nefarious_settings.transmission_movie_download_dir.lstrip('/'))
            result['watch_movie'] = WatchMovieSerializer(watch_media).data
        else:
            tmdb_request = tmdb.TV(tmdb_media['id'])
            tmdb_show = tmdb_request.info()

            watch_tv_show, _ = WatchTVShow.objects.get_or_create(
                tmdb_show_id=tmdb_show['id'],
                defaults=dict(
                    user=request.user,
                    name=tmdb_show['name'],
                    poster_image_url=nefarious_settings.get_tmdb_poster_url(
                        tmdb_show['poster_path']),
                ))

            result['watch_tv_show'] = WatchTVShowSerializer(watch_tv_show).data

            # single episode
            if 'episode_number' in request.data:
                tmdb_request = tmdb.TV_Episodes(tmdb_media['id'],
                                                request.data['season_number'],
                                                request.data['episode_number'])
                tmdb_episode = tmdb_request.info()
                watch_media = WatchTVEpisode(
                    user=request.user,
                    watch_tv_show=watch_tv_show,
                    tmdb_episode_id=tmdb_episode['id'],
                    season_number=request.data['season_number'],
                    episode_number=request.data['episode_number'],
                    release_date=parse_date(tmdb_episode['air_date'] or ''))
                watch_media.save()
                result['watch_tv_episode'] = WatchTVEpisodeSerializer(
                    watch_media).data
            # entire season
            else:
                season_result = tmdb.TV_Seasons(tmdb_show['id'],
                                                request.data['season_number'])
                season_data = season_result.info()
                # create the season request
                watch_tv_season_request, _ = WatchTVSeasonRequest.objects.get_or_create(
                    watch_tv_show=watch_tv_show,
                    season_number=request.data['season_number'],
                    defaults=dict(
                        user=request.user,
                        collected=
                        True,  # set collected since we're directly downloading a torrent
                        release_date=parse_date(season_data['air_date']
                                                or '')),
                )
                # create the actual watch season instance
                watch_media = WatchTVSeason(
                    user=request.user,
                    watch_tv_show=watch_tv_show,
                    season_number=request.data['season_number'],
                    release_date=parse_date(season_data['air_date'] or ''))
                watch_media.save()

                # return the season request vs the watch instance
                result[
                    'watch_tv_season_request'] = WatchTVSeasonRequestSerializer(
                        watch_tv_season_request).data

            download_dir = os.path.join(
                transmission_session.download_dir,
                nefarious_settings.transmission_tv_download_dir.lstrip('/'))

        torrent = transmission_client.add_torrent(
            torrent_url,
            paused=settings.DEBUG,
            download_dir=download_dir,
        )
        watch_media.transmission_torrent_hash = torrent.hashString
        watch_media.save()

        return Response(result)