Beispiel #1
0
def download_episode(series, season, episode):
    all_episotes = eztvit.EztvIt().get_episodes(series)
    episode = all_episotes[season][episode]
    episode = sorted(episode, key=lambda k: k['size_mb'])[-1]
    print("Downloading: {}, Size: {}".format(episode["release"],
                                             episode["size_mb"]))
    magnet = episode['download']['magnet']
    os.startfile(magnet)
Beispiel #2
0
def download_season(series, season):
    all_episotes = eztvit.EztvIt().get_episodes(series)
    season = all_episotes[season]
    for key, value in season.iteritems():
        episode = sorted(value, key=lambda k: k['size_mb'])[-1]
        print("Downloading: {}, Size: {}".format(episode["release"],
                                                 episode["size_mb"]))
        magnet = episode['download']['magnet']
        os.startfile(magnet)
    def test_get_episodes_matches_partial_correctly(self, mock_getepisodesbyid,
                                                    mock_poolmanager):
        with open('tests/fixtures/search_shows1.js') as fixture:
            mock_poolmanager(
            ).request.return_value = urllib3.response.HTTPResponse(
                fixture.read())

        # Possible candidates: "Castle (2009)"
        eztvit.EztvIt().get_episodes('Castle')

        mock_getepisodesbyid.assert_called_with(42)
    def test_get_episodes_matches_exact_correctly(self, mock_getepisodesbyid,
                                                  mock_poolmanager):
        with open('tests/fixtures/search_shows1.js') as fixture:
            mock_poolmanager(
            ).request.return_value = urllib3.response.HTTPResponse(
                fixture.read())

        # Possible candidates: "The Blacklist" and "The Blacklist: Redemption"
        eztvit.EztvIt().get_episodes('The Blacklist')

        mock_getepisodesbyid.assert_called_with(887)
    def test_shows_list(self, mock_poolmanager):
        with open('tests/fixtures/search_shows1.js') as fixture:
            mock_poolmanager(
            ).request.return_value = urllib3.response.HTTPResponse(
                fixture.read())

        # Fetch the dictionary that represents all of available shows.
        shows = eztvit.EztvIt().get_shows()

        self.assertEquals(shows[495], 'Suits')
        self.assertEquals(shows[101], 'Fringe')
        self.assertEquals(shows[42], 'Castle (2009)')
        self.assertEquals(shows[442], 'The Cape (2011)')
        # Check the "The" has come back to the beginning.
        self.assertEquals(shows[23], 'The Big Bang Theory')
    def test_suits_via_show_id(self, mock_poolmanager):
        # Mock urllib2 to return the episodes of the awesome TV show "Suits".
        with open('tests/fixtures/suits.html') as fixture:
            mock_poolmanager(
            ).request.return_value = urllib3.response.HTTPResponse(
                fixture.read())

        # Fetch the dictionary that represents all of the episodes of "Suits".
        suits = eztvit.EztvIt().get_episodes_by_id(495)

        # Ensure we're dealing with exactly dictionaries, not defaultdicts or
        # some other subclass of dict.
        self.assertEquals(type(suits), dict)
        for episodes in suits.values():
            self.assertEquals(type(episodes), dict)

        # Check the four seasons have the correct number of episodes.
        self.assertEquals(len(suits[2]), 16)
        self.assertEquals(len(suits[3]), 16)
        self.assertLessEqual(len(suits[4]), 16)

        # Test that "S04E06" has 2 episodes, in a particular order, with the
        # correct magnet links.
        suits_4x06 = suits[4][6]
        self.assertEquals(len(suits_4x06), 2)

        self.assertEquals(suits_4x06[0]['release'],
                          "Suits S04E06 REPACK HDTV x264-KILLERS [eztv]")
        self.assertIn('magnet:?xt=urn:btih:D4JVVOTZ3YNAYO',
                      suits_4x06[0]['download']['magnet'])

        self.assertEquals(suits_4x06[1]['release'],
                          "Suits S04E06 HDTV x264-KILLERS [eztv]")
        self.assertIn('magnet:?xt=urn:btih:VNL5SUXHIMCODE',
                      suits_4x06[1]['download']['magnet'])

        # Check that we made an appropriate HTTP request to get this page.
        (method, url) = self._get_request_from_mock(mock_poolmanager)
        self.assertEquals(url,
                          'https://eztv.ag/search/?q1=&q2=495&search=Search')
        self.assertEquals(method, 'GET')

        headers = self._get_headers_from_mock(mock_poolmanager)
        self.assertEquals(len(headers), 1)
        self.assertIn('WebKit', headers['User-Agent'])

        # Check that we didn't make any other HTTP requests.
        self.assertEquals(mock_poolmanager().request.call_count, 1)
    def test_fringe_via_show_id(self, mock_poolmanager):
        # Mock urllib2 to return the episodes of the awesome TV show "Fringe".
        with open('tests/fixtures/fringe.html') as fixture:
            mock_poolmanager(
            ).request.return_value = urllib3.response.HTTPResponse(
                fixture.read())

        # Fetch the dictionary that represents all of the episodes of "Fringe".
        fringe = eztvit.EztvIt().get_episodes_by_id(101)

        # Ensure we're dealing with exactly dictionaries, not defaultdicts or
        # some other subclass of dict.
        self.assertEquals(type(fringe), dict)
        for episodes in fringe.values():
            self.assertEquals(type(episodes), dict)

        # Check the four seasons have the correct number of episodes (season 1 and 2 are missing).
        self.assertEquals(len(fringe[3]), 21)
        self.assertEquals(len(fringe[4]), 22)
        self.assertEquals(len(fringe[5]), 13)
Beispiel #8
0
    def test_suits(self):
        suits = eztvit.EztvIt().get_episodes('Suits')

        # Check the four seasons have the correct number of episodes.
        self.assertEquals(len(suits[2]), 16)
        self.assertEquals(len(suits[3]), 16)
        self.assertLessEqual(len(suits[4]), 16)

        # Test that "S04E06" has 2 episodes, in a particular order, with the
        # correct magnet links.
        suits_4x06 = suits[4][6]
        self.assertEquals(len(suits_4x06), 2)

        self.assertEquals(suits_4x06[0]['release'],
                          "Suits S04E06 REPACK HDTV x264-KILLERS [eztv]")
        self.assertIn('magnet:?xt=urn:btih:D4JVVOTZ3YNAYO',
                      suits_4x06[0]['download']['magnet'])

        self.assertEquals(suits_4x06[1]['release'],
                          "Suits S04E06 HDTV x264-KILLERS [eztv]")
        self.assertIn('magnet:?xt=urn:btih:VNL5SUXHIMCODE',
                      suits_4x06[1]['download']['magnet'])
    def test_suits_via_show_name(self, mock_poolmanager):
        with open('tests/fixtures/search_shows1.js') as fixture:
            mock_poolmanager(
            ).request.return_value = urllib3.response.HTTPResponse(
                fixture.read())

        eztv_client = eztvit.EztvIt()
        eztv_client.get_episodes_by_id = mock.MagicMock()

        eztv_client.get_episodes('Suits')
        eztv_client.get_episodes_by_id.assert_called_with(495)

        # Check that we requested the homepage.
        (method, url) = self._get_request_from_mock(mock_poolmanager)
        self.assertEquals(url, 'https://eztv.ag/js/search_shows1.js')
        self.assertEquals(method, 'GET')

        headers = self._get_headers_from_mock(mock_poolmanager)
        self.assertEquals(len(headers), 1)
        self.assertIn('WebKit', headers['User-Agent'])

        # Check that we didn't make any other HTTP requests.
        self.assertEquals(mock_poolmanager().request.call_count, 1)
Beispiel #10
0
class ShowAPI(object):
    '''
    Api for getting magent links of new episodes.
    '''

    api = eztvit.EztvIt()

    def __init__(self, shows, callback):
        '''
        Initializes the class.

        :param dict shows: Dictionary of shows to scan.
        :param func callback: Callback function to run on each episode found.
        '''
        self._callback = callback
        self._shows = shows

    def check_torrents(self, torrents):
        '''
        Returns the largest torrent of each list of torrents.
        (Larger file size == Higher quality)

        :param list torrents: list of torrents
        '''
        largest = None
        for torrent in torrents:
            if largest is None or torrent['size_mb'] > largest['size_mb']:
                largest = torrent
        return largest

    def check_season(self, show, season, episodes, new_season=False):
        '''
        Checks a season for new episodes, and runs the callback on each
        new episode found.

        :param str show: show name
        :param int season: currently checked season
        :param dict episodes: a dictionary of all episodes in the current season
        :param bool new_season: wether or not this is a new season(compared to
        what is written in the shows.json)
        '''
        for episode, torrents in episodes.items():
            if new_season or episode >= self._shows[show]['episode']:
                torrent = self.check_torrents(torrents)
                self._callback(show, season, episode, torrent)

    def check_show(self, show, seasons):
        '''
        Checks show for new episodes/seasons.

        :param str show: show name
        :param dict seasons: all show's seasons.
        '''
        for season, episodes in seasons.items():
            if season == self._shows[show]['season']:
                self.check_season(show, season, episodes)
            elif season > self._shows[show]['season']:
                self.check_season(show, season, episodes, new_season=True)

    def run(self):
        '''
        Runs the checker.
        '''
        for show in self._shows:
            seasons = self.api.get_episodes(show)
            self.check_show(show, seasons)