aboutsummaryrefslogtreecommitdiffstats
path: root/youtube/util.py
diff options
context:
space:
mode:
authorJames Taylor <user234683@users.noreply.github.com>2019-12-19 19:48:53 -0800
committerJames Taylor <user234683@users.noreply.github.com>2019-12-19 19:48:53 -0800
commitd1d908d5b1aadb0dc75b25df1a47789c021f89e2 (patch)
tree56a1a0e8361a732241774fee35ae521858d16d5f /youtube/util.py
parent76376b29a0adf6bd6d7a0202d904f923bdc8aa57 (diff)
downloadyt-local-d1d908d5b1aadb0dc75b25df1a47789c021f89e2.tar.lz
yt-local-d1d908d5b1aadb0dc75b25df1a47789c021f89e2.tar.xz
yt-local-d1d908d5b1aadb0dc75b25df1a47789c021f89e2.zip
Extraction: Move html post processing stuff from yt_data_extract to util
Diffstat (limited to 'youtube/util.py')
-rw-r--r--youtube/util.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/youtube/util.py b/youtube/util.py
index 9023b98..feeec8c 100644
--- a/youtube/util.py
+++ b/youtube/util.py
@@ -1,4 +1,5 @@
import settings
+from youtube import yt_data_extract
import socks, sockshandler
import gzip
import brotli
@@ -6,6 +7,7 @@ import urllib.parse
import re
import time
import os
+import json
import gevent
import gevent.queue
import gevent.lock
@@ -321,3 +323,39 @@ def left_remove(string, substring):
return string[len(substring):]
return string
+
+def prefix_urls(item):
+ try:
+ item['thumbnail'] = prefix_url(item['thumbnail'])
+ except KeyError:
+ pass
+
+ try:
+ item['author_url'] = prefix_url(item['author_url'])
+ except KeyError:
+ pass
+
+def add_extra_html_info(item):
+ if item['type'] == 'video':
+ item['url'] = (URL_ORIGIN + '/watch?v=' + item['id']) if item.get('id') else None
+
+ video_info = {}
+ for key in ('id', 'title', 'author', 'duration'):
+ try:
+ video_info[key] = item[key]
+ except KeyError:
+ video_info[key] = ''
+
+ item['video_info'] = json.dumps(video_info)
+
+ elif item['type'] == 'playlist':
+ item['url'] = (URL_ORIGIN + '/playlist?list=' + item['id']) if item.get('id') else None
+ elif item['type'] == 'channel':
+ item['url'] = (URL_ORIGIN + "/channel/" + item['id']) if item.get('id') else None
+
+def parse_info_prepare_for_html(renderer, additional_info={}):
+ item = yt_data_extract.extract_item_info(renderer, additional_info)
+ prefix_urls(item)
+ add_extra_html_info(item)
+
+ return item