aboutsummaryrefslogtreecommitdiffstats
path: root/youtube
diff options
context:
space:
mode:
Diffstat (limited to 'youtube')
-rw-r--r--youtube/common.py2
-rw-r--r--youtube/playlist.py11
-rw-r--r--youtube/search.py2
3 files changed, 7 insertions, 8 deletions
diff --git a/youtube/common.py b/youtube/common.py
index 76fd7c3..ae2ada1 100644
--- a/youtube/common.py
+++ b/youtube/common.py
@@ -168,7 +168,7 @@ def fetch_url(url, headers=(), timeout=15, report_text=None):
content = response.read()
read_finish = time.time()
if report_text:
- print(report_text, ' Latency:', response_time - start_time, ' Read time:', read_finish - response_time)
+ print(report_text, ' Latency:', round(response_time - start_time,3), ' Read time:', round(read_finish - response_time,3))
content = decode_content(content, response.getheader('Content-Encoding', default='identity'))
return content
diff --git a/youtube/playlist.py b/youtube/playlist.py
index d146b92..c16dc7f 100644
--- a/youtube/playlist.py
+++ b/youtube/playlist.py
@@ -46,9 +46,9 @@ headers_1 = (
('X-YouTube-Client-Version', '2.20180614'),
)
-def playlist_first_page(playlist_id):
+def playlist_first_page(playlist_id, report_text = "Retrieved playlist"):
url = 'https://m.youtube.com/playlist?list=' + playlist_id + '&ajax=1&disable_polymer=true'
- content = common.fetch_url(url, common.mobile_ua + headers_1)
+ content = common.fetch_url(url, common.mobile_ua + headers_1, report_text=report_text)
if content[0:4] == b")]}'":
content = content[4:]
content = json.loads(common.uppercase_escape(content.decode('utf-8')))
@@ -66,12 +66,11 @@ def get_videos_ajax(playlist_id, page):
'X-YouTube-Client-Name': '2',
'X-YouTube-Client-Version': '1.20180508',
}
- print("Sending playlist ajax request")
- content = common.fetch_url(url, headers)
+
+ content = common.fetch_url(url, headers, report_text="Retrieved playlist")
'''with open('debug/playlist_debug', 'wb') as f:
f.write(content)'''
content = content[4:]
- print("Finished recieving playlist response")
info = json.loads(common.uppercase_escape(content.decode('utf-8')))
return info
@@ -88,7 +87,7 @@ def get_playlist_page(query_string):
this_page_json = first_page_json
else:
tasks = (
- gevent.spawn(playlist_first_page, playlist_id ),
+ gevent.spawn(playlist_first_page, playlist_id, report_text="Retrieved playlist info" ),
gevent.spawn(get_videos_ajax, playlist_id, page)
)
gevent.joinall(tasks)
diff --git a/youtube/search.py b/youtube/search.py
index 8bb3aff..206f000 100644
--- a/youtube/search.py
+++ b/youtube/search.py
@@ -55,7 +55,7 @@ def get_search_json(query, page, autocorrect, sort):
'X-YouTube-Client-Version': '2.20180418',
}
url += "&pbj=1&sp=" + page_number_to_sp_parameter(page, autocorrect, sort).replace("=", "%3D")
- content = common.fetch_url(url, headers=headers)
+ content = common.fetch_url(url, headers=headers, report_text="Got search results")
info = json.loads(content)
return info