How to use the ytcc.download.Download function in ytcc

To help you get started, we’ve selected a few ytcc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github alexkohler / ytgrep / test / functional / test_real_video.py View on Github external
def test_video_one_missing_captions(self):
        self.download = Download(
            {
                'urls': [
                    'https://www.youtube.com/watch?v=jNQXAC9IVRw',
                    'https://www.youtube.com/watch?v=jyoTZ69mWZE'],
                'pattern': 'elephants',
                'e': False,
                'v': False})
        expected = """https://www.youtube.com/watch?v=jNQXAC9IVRw
[00:00:01.300 --> 00:00:04.400] all right, so here we are in front of the elephants,"""
        expected = expected.replace('elephants', red('elephants'))
        self.assertEqual(expected, self.download.get_captions())
github alexkohler / ytgrep / test / unit / download / test_get_captions.py View on Github external
def test_caption_captions_do_not_exist(self):
        test = {
            'name': 'captions do not exist',
            'urls': ['https://www.swag.com/'],
            'pattern': 'my pattern',
            'regex': False,
            'links': False,
        }

        download = Download({'urls': test['urls'],
                             'pattern': test['pattern'],
                             'e': test['regex'],
                             'v': False,
                             'links': test['links']})
        m = mock_open(read_data=FIXTURE_WEBVTT)
        m.side_effect = FileNotFoundError

        with patch('ytcc.download.open', m, create=True):
            with patch('ytcc.storage.Storage.remove_file', Mock()):
                download.get_result = Mock(return_value=0)
                with self.assertRaises(NoCaptionsException):
                    download.get_captions()
github alexkohler / ytgrep / test / functional / test_real_video.py View on Github external
def test_video_multiline_match_with_regexp(self):
        self.download = Download(
            {
                'urls': ['https://www.youtube.com/watch?v=jNQXAC9IVRw'],
                'pattern': 'cool',
                'e': True,
                'v': False})
        expected = '[00:00:04.400 --> 00:00:09.166] the ' + red(
            'cool') + ' thing about these guys is that they have really,\n[00:00:12.700 --> 00:00:17.000] and thats, thats ' + red('cool') + '."'
        self.assertEqual(expected, self.download.get_captions())
github alexkohler / ytgrep / test / functional / test_real_video.py View on Github external
def test_video(self):
        self.download = Download(
            {
                'urls': [
                    'https://www.youtube.com/watch?v=jNQXAC9IVRw',
                    'https://www.youtube.com/watch?v=jNQXAC9IVRw'],
                'pattern': 'elephants',
                'e': False,
                'v': False})
        expected = """https://www.youtube.com/watch?v=jNQXAC9IVRw
[00:00:01.300 --> 00:00:04.400] all right, so here we are in front of the elephants,
https://www.youtube.com/watch?v=jNQXAC9IVRw
[00:00:01.300 --> 00:00:04.400] all right, so here we are in front of the elephants,"""
        expected = expected.replace('elephants', red('elephants'))
        self.assertEqual(expected, self.download.get_captions())
github alexkohler / ytgrep / test / functional / test_real_video.py View on Github external
def test_video_does_not_exist(self):
        self.download = Download(
            {'urls': ['12323123123'], 'pattern': 'elephants', 'e': False, 'v': False})
        with self.assertRaises(DownloadException):
            self.download.get_captions()
github alexkohler / ytgrep / test / unit / download / test_get_captions.py View on Github external
'urls': ['https://www.swag.com/'],
                  'pattern': 'actor|light',
                  'regex': True,
                  'links': False,
                  'expected': '[00:00:33.666 --> 00:00:38.138] ' + red('actor') + ' as einstein: what ' + red('light') + ' would i see if i rode on a beam of ' + red('light') + '?',
                  },
                 {'name': '1 video, 1 link',
                  'urls': ['https://www.swag.com/'],
                  'pattern': 'actor|light',
                  'regex': True,
                  'links': True,
                  'expected': '[00:00:33.666 --> 00:00:38.138] ' + red('actor') + ' as einstein: what ' + red('light') + ' would i see if i rode on a beam of ' + red('light') + '? (https://www.swag.com/&t=33s)',
                  },
                 ]
        for test in tests:
            download = Download({'urls': test['urls'],
                                 'pattern': test['pattern'],
                                 'e': test['regex'],
                                 'v': False,
                                 'links': test['links']})
            m = mock_open(read_data=FIXTURE_WEBVTT)

            with patch('ytcc.download.open', m, create=True):
                with patch('ytcc.storage.Storage.remove_file', Mock()):
                    download.get_result = Mock(return_value=0)
                    actual = download.get_captions()
                    expected = test['expected']
                    self.assertEqual(actual, expected)
github alexkohler / ytgrep / test / functional / test_real_video.py View on Github external
def test_video_no_captions(self):
        self.download = Download(
            {
                'urls': ['https://www.youtube.com/watch?v=jyoTZ69mWZE'],
                'pattern': 'elephants',
                'e': False,
                'v': False})
        with self.assertRaises(NoCaptionsException):
            self.download.get_captions()
github alexkohler / ytgrep / ytgrep.py View on Github external
help='Interpret PATTERN as an extended regular expression')
    parser.add_argument(
        '-v',
        action="store_true",
        help='Print debug information while searching')
    parser.add_argument(
        '-links',
        action="store_true",
        help='include shortcut links to video at matched time i.e. ?t=<time>')
    parser.add_argument('pattern', type=str, help='term to search for')
    parser.add_argument('urls', nargs='+', help='video URL(s)')

    args = parser.parse_args()
    args_dict = vars(args)

    download = Download(args_dict)
    try:
        captions = download.get_captions()
        if len(captions) == 0:
            print("No matches found.")
            sys.exit(1)
        print(captions)
    except Exception as err:
        print("Unable to retrieve captions, {}".format(err))
</time>