Can now store settings&data in ~/.youtube-local, keeping program files separate

This commit is contained in:
James Taylor
2018-11-10 00:27:43 -08:00
parent 9dd8308cf2
commit 717bf21093
6 changed files with 62 additions and 35 deletions

View File

@@ -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)

View File

@@ -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())

View File

@@ -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")

View File

@@ -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()