aboutsummaryrefslogtreecommitdiffstats
path: root/youtube
diff options
context:
space:
mode:
authorJames Taylor <user234683@users.noreply.github.com>2018-11-10 00:27:43 -0800
committerJames Taylor <user234683@users.noreply.github.com>2018-11-10 00:27:43 -0800
commit717bf210937c757595624348db9389969be9654f (patch)
tree7814a81f5c0de1084ab46f3a88b6186798932dfa /youtube
parent9dd8308cf23de69c741f0304ace102718b844e16 (diff)
downloadyt-local-717bf210937c757595624348db9389969be9654f.tar.lz
yt-local-717bf210937c757595624348db9389969be9654f.tar.xz
yt-local-717bf210937c757595624348db9389969be9654f.zip
Can now store settings&data in ~/.youtube-local, keeping program files separate
Diffstat (limited to 'youtube')
-rw-r--r--youtube/account_functions.py4
-rw-r--r--youtube/local_playlist.py6
-rw-r--r--youtube/watch.py3
-rw-r--r--youtube/youtube.py3
4 files changed, 11 insertions, 5 deletions
diff --git a/youtube/account_functions.py b/youtube/account_functions.py
index f34e5f2..0c7973b 100644
--- a/youtube/account_functions.py
+++ b/youtube/account_functions.py
@@ -5,6 +5,8 @@ import json
from youtube import common, proto, comments
import re
import traceback
+import settings
+import os
def _post_comment(text, video_id, session_token, cookie):
headers = {
@@ -103,7 +105,7 @@ def delete_comment(video_id, comment_id, author_id, session_token, cookie):
xsrf_token_regex = re.compile(r'''XSRF_TOKEN"\s*:\s*"([\w-]*(?:=|%3D){0,2})"''')
def post_comment(query_string, fields):
- with open('data/cookie.txt', 'r', encoding='utf-8') as f:
+ with open(os.path.join(settings.data_dir, 'cookie.txt'), 'r', encoding='utf-8') as f:
cookie_data = f.read()
parameters = urllib.parse.parse_qs(query_string)
diff --git a/youtube/local_playlist.py b/youtube/local_playlist.py
index 76e7ee6..715015e 100644
--- a/youtube/local_playlist.py
+++ b/youtube/local_playlist.py
@@ -5,9 +5,11 @@ from youtube import common
import html
import gevent
import urllib
+import settings
+
+playlists_directory = os.path.join(settings.data_dir, "playlists")
+thumbnails_directory = os.path.join(settings.data_dir, "playlist_thumbnails")
-playlists_directory = os.path.normpath("data/playlists")
-thumbnails_directory = os.path.normpath("data/playlist_thumbnails")
with open('yt_local_playlist_template.html', 'r', encoding='utf-8') as file:
local_playlist_template = Template(file.read())
diff --git a/youtube/watch.py b/youtube/watch.py
index 6ed0878..0f70635 100644
--- a/youtube/watch.py
+++ b/youtube/watch.py
@@ -9,6 +9,7 @@ from youtube.common import default_multi_get, get_thumbnail_url, video_id, URL_O
import youtube.comments as comments
import gevent
import settings
+import os
video_height_priority = (360, 480, 240, 720, 1080)
@@ -305,7 +306,7 @@ def get_watch_page(query_string):
music_list_html += '''</tr>\n'''
music_list_html += '''</table>\n'''
if settings.gather_googlevideo_domains:
- with open('data/googlevideo-domains.txt', 'a+', encoding='utf-8') as f:
+ with open(os.path.join(settings.data_dir, 'googlevideo-domains.txt'), 'a+', encoding='utf-8') as f:
url = info['formats'][0]['url']
subdomain = url[0:url.find(".googlevideo.com")]
f.write(subdomain + "\n")
diff --git a/youtube/youtube.py b/youtube/youtube.py
index 1a97b6c..5451254 100644
--- a/youtube/youtube.py
+++ b/youtube/youtube.py
@@ -1,5 +1,6 @@
import mimetypes
import urllib.parse
+import os
from youtube import local_playlist, watch, search, playlist, channel, comments, common, account_functions
import settings
YOUTUBE_FILES = (
@@ -49,7 +50,7 @@ def youtube(env, start_response):
return local_playlist.get_playlist_page(path[10:], query_string=query_string).encode()
elif path.startswith("/data/playlist_thumbnails/"):
- with open(path[1:], 'rb') as f:
+ with open(os.path.join(settings.data_dir, os.path.normpath(path[6:])), 'rb') as f:
start_response('200 OK', (('Content-type', "image/jpeg"),) )
return f.read()