File size: 2,112 Bytes
b49425d
6a71666
 
1fbe89d
d3cad85
 
 
1fbe89d
b49425d
 
1fbe89d
e5fc29e
 
 
b49425d
 
 
 
 
1fbe89d
e5fc29e
 
 
 
 
b49425d
 
 
9a071f2
 
3a5d47f
 
 
 
 
 
 
 
 
 
 
9a071f2
1fbe89d
9a071f2
6bd710b
d966a0d
 
1fbe89d
 
 
 
 
3a5d47f
d3cad85
 
1fbe89d
 
 
3a5d47f
1fbe89d
 
 
 
 
3a5d47f
1fbe89d
 
d3cad85
1fbe89d
 
d3cad85
1fbe89d
 
 
3a5d47f
1fbe89d
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# -*- coding: utf-8 -*-
from pytube import Playlist

short_test_pl = 'https://www.youtube.com/watch?v=' \
    'm5q2GCsteQs&list=PL525f8ds9RvsXDl44X6Wwh9t3fCzFNApw'
long_test_pl = 'https://www.youtube.com/watch?v=' \
               '9CHDoAsX1yo&list=UUXuqSBlHAE6Xw-yeJA0Tunw'


def test_construct():
    ob = Playlist(short_test_pl)
    expected = 'https://www.youtube.com/' \
               'playlist?list=' \
               'PL525f8ds9RvsXDl44X6Wwh9t3fCzFNApw'

    assert ob.construct_playlist_url() == expected


def test_populate():
    ob = Playlist(short_test_pl)
    expected = [
        'https://www.youtube.com/watch?v=m5q2GCsteQs',
        'https://www.youtube.com/watch?v=5YK63cXyJ2Q',
        'https://www.youtube.com/watch?v=Rzt4rUPFYD4',
    ]

    ob.populate_video_urls()
    assert ob.video_urls == expected


def test_link_parse():
    ob = Playlist(short_test_pl)

    expected = [
        '/watch?v=m5q2GCsteQs',
        '/watch?v=5YK63cXyJ2Q',
        '/watch?v=Rzt4rUPFYD4',
    ]
    assert ob.parse_links() == expected


def test_download():
    ob = Playlist(short_test_pl)
    ob.download_all()
    ob.download_all('.')
    ob.download_all(prefix_number=False)
    ob.download_all('.', prefix_number=False)


def test_numbering():
    ob = Playlist(short_test_pl)
    ob.populate_video_urls()
    gen = ob._path_num_prefix_generator(reverse=False)
    assert '1' in next(gen)
    assert '2' in next(gen)

    ob = Playlist(short_test_pl)
    ob.populate_video_urls()
    gen = ob._path_num_prefix_generator(reverse=True)
    assert str(len(ob.video_urls)) in next(gen)
    assert str(len(ob.video_urls) - 1) in next(gen)

    ob = Playlist(long_test_pl)
    ob.populate_video_urls()
    gen = ob._path_num_prefix_generator(reverse=False)
    nxt = next(gen)
    assert len(nxt) > 1
    assert '1' in nxt
    nxt = next(gen)
    assert len(nxt) > 1
    assert '2' in nxt

    ob = Playlist(long_test_pl)
    ob.populate_video_urls()
    gen = ob._path_num_prefix_generator(reverse=True)
    assert str(len(ob.video_urls)) in next(gen)
    assert str(len(ob.video_urls) - 1) in next(gen)