Completed
Pull Request — master (#297)
by Bart
01:19
created

fuel.downloaders.download()   A

Complexity

Conditions 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 2
dl 0
loc 8
rs 9.4285
1
try:
2
    import pafy
3
    PAFY_AVAILABLE = True
4
except ImportError:
5
    PAFY_AVAILABLE = False
6
7
8
def download(directory, youtube_id, clear=False):
0 ignored issues
show
Unused Code introduced by
The argument directory seems to be unused.
Loading history...
Unused Code introduced by
The argument clear seems to be unused.
Loading history...
9
    if not PAFY_AVAILABLE:
10
        raise ImportError("pafy is required to download YouTube videos")
11
    url = 'https://www.youtube.com/watch?v={}'.format(youtube_id)
12
    video = pafy.new(url)
13
    audio = video.getbestaudio()
14
    filepath = '{}.m4a'.format(youtube_id)
15
    audio.download(quiet=False, filepath=filepath)
16
17
18
def fill_subparser(subparser):
19
    subparser.add_argument(
20
        '--youtube-id', type=str, required=True,
21
        help=("The YouTube ID of the video from which to extract audio, "
22
              "usually an 11-character string.")
23
    )
24
    return download
25