cleanup around compat
Browse files- pytube/api.py +6 -5
- pytube/compat.py +7 -2
pytube/api.py
CHANGED
@@ -1,5 +1,7 @@
|
|
1 |
#!/usr/bin/env python
|
2 |
# -*- coding: utf-8 -*-
|
|
|
|
|
3 |
import json
|
4 |
import logging
|
5 |
import re
|
@@ -14,7 +16,7 @@ from .utils import safe_filename
|
|
14 |
log = logging.getLogger(__name__)
|
15 |
|
16 |
# YouTube quality and codecs id map.
|
17 |
-
|
18 |
# flash
|
19 |
5: ("flv", "240p", "Sorenson H.263", "N/A", "0.25", "MP3", "64"),
|
20 |
|
@@ -36,7 +38,7 @@ YT_QUALITY_PROFILES = {
|
|
36 |
}
|
37 |
|
38 |
# The keys corresponding to the quality/codec map above.
|
39 |
-
|
40 |
"extension",
|
41 |
"resolution",
|
42 |
"video_codec",
|
@@ -400,13 +402,12 @@ class YouTube(object):
|
|
400 |
itag = int(itag[0])
|
401 |
# Given an itag, refer to the YouTube quality profiles to get the
|
402 |
# properties (media type, resolution, etc.) of the video.
|
403 |
-
quality_profile =
|
404 |
if not quality_profile:
|
405 |
return itag, None
|
406 |
# Here we just combine the quality profile keys to the
|
407 |
# corresponding quality profile, referenced by the itag.
|
408 |
-
return itag, dict(list(zip(
|
409 |
-
YT_QUALITY_PROFILE_KEYS, quality_profile)))
|
410 |
if not itag:
|
411 |
raise PytubeError("Unable to get encoding profile, no itag found.")
|
412 |
elif len(itag) > 1:
|
|
|
1 |
#!/usr/bin/env python
|
2 |
# -*- coding: utf-8 -*-
|
3 |
+
from __future__ import absolute_import
|
4 |
+
from future_builtins import zip
|
5 |
import json
|
6 |
import logging
|
7 |
import re
|
|
|
16 |
log = logging.getLogger(__name__)
|
17 |
|
18 |
# YouTube quality and codecs id map.
|
19 |
+
QUALITY_PROFILES = {
|
20 |
# flash
|
21 |
5: ("flv", "240p", "Sorenson H.263", "N/A", "0.25", "MP3", "64"),
|
22 |
|
|
|
38 |
}
|
39 |
|
40 |
# The keys corresponding to the quality/codec map above.
|
41 |
+
QUALITY_PROFILE_KEYS = (
|
42 |
"extension",
|
43 |
"resolution",
|
44 |
"video_codec",
|
|
|
402 |
itag = int(itag[0])
|
403 |
# Given an itag, refer to the YouTube quality profiles to get the
|
404 |
# properties (media type, resolution, etc.) of the video.
|
405 |
+
quality_profile = QUALITY_PROFILES.get(itag)
|
406 |
if not quality_profile:
|
407 |
return itag, None
|
408 |
# Here we just combine the quality profile keys to the
|
409 |
# corresponding quality profile, referenced by the itag.
|
410 |
+
return itag, dict(list(zip(QUALITY_PROFILE_KEYS, quality_profile)))
|
|
|
411 |
if not itag:
|
412 |
raise PytubeError("Unable to get encoding profile, no itag found.")
|
413 |
elif len(itag) > 1:
|
pytube/compat.py
CHANGED
@@ -1,9 +1,14 @@
|
|
1 |
#!/usr/bin/env python
|
2 |
# -*- coding: utf-8 -*-
|
3 |
# flake8: noqa
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
5 |
from urllib2 import urlopen
|
6 |
from urlparse import urlparse, parse_qs, unquote
|
7 |
-
|
8 |
from urllib.parse import urlparse, parse_qs, unquote
|
9 |
from urllib.request import urlopen
|
|
|
1 |
#!/usr/bin/env python
|
2 |
# -*- coding: utf-8 -*-
|
3 |
# flake8: noqa
|
4 |
+
import sys
|
5 |
+
|
6 |
+
PY2 = sys.version_info[0] == 2
|
7 |
+
PY3 = sys.version_info[0] == 3
|
8 |
+
|
9 |
+
if PY2:
|
10 |
from urllib2 import urlopen
|
11 |
from urlparse import urlparse, parse_qs, unquote
|
12 |
+
if PY3:
|
13 |
from urllib.parse import urlparse, parse_qs, unquote
|
14 |
from urllib.request import urlopen
|