Adjusted source to meat PEP8
This commit is contained in:
201
play.py
201
play.py
@@ -1,21 +1,24 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
#import cProfile
|
# import cProfile
|
||||||
#import re
|
# import re
|
||||||
import requests
|
import requests
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
#import calendar
|
# import calendar
|
||||||
import os
|
import os
|
||||||
from html import unescape
|
from html import unescape
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
#import time
|
# import time
|
||||||
|
from subprocess import Popen, PIPE, DEVNULL
|
||||||
import curses
|
import curses
|
||||||
import sqlite3 as lite
|
import sqlite3 as lite
|
||||||
import youtube
|
import youtube
|
||||||
#import os.path
|
# import os.path
|
||||||
#import math
|
# import math
|
||||||
from curses.textpad import Textbox, rectangle
|
from curses.textpad import Textbox, rectangle
|
||||||
#527 biale z podkreśleniem 520 szare z podkresleniem
|
|
||||||
#https://www.googleapis.com/youtube/v3/search?key=AIzaSyBwecAq2aCjRxStpOclQZNSRpJEI2HtvX0&part=snippet&type=channel&q=etho&maxResults=10
|
|
||||||
|
# 527 biale z podkreśleniem 520 szare z podkresleniem
|
||||||
|
# https://www.googleapis.com/youtube/v3/search?key=AIzaSyBwecAq2aCjRxStpOclQZNSRpJEI2HtvX0&part=snippet&type=channel&q=etho&maxResults=10
|
||||||
|
|
||||||
def get_video_id(url):
|
def get_video_id(url):
|
||||||
url_data = urllib.parse.urlparse(url)
|
url_data = urllib.parse.urlparse(url)
|
||||||
@@ -26,9 +29,9 @@ def get_video_id(url):
|
|||||||
def get_valid_filename(string):
|
def get_valid_filename(string):
|
||||||
return "".join([c for c in string if c.isalpha() or c.isdigit() or c == ' ']).rstrip().replace(' ', '_')
|
return "".join([c for c in string if c.isalpha() or c.isdigit() or c == ' ']).rstrip().replace(' ', '_')
|
||||||
|
|
||||||
def file_exists(video_title):
|
|
||||||
return os.path.isfile("/public/youtube/" + get_valid_filename(video_title)+".mp4")
|
|
||||||
|
|
||||||
|
def file_exists(video_title):
|
||||||
|
return os.path.isfile("/public/youtube/" + get_valid_filename(video_title) + ".mp4")
|
||||||
|
|
||||||
|
|
||||||
class Mc(object):
|
class Mc(object):
|
||||||
@@ -44,24 +47,27 @@ class Mc(object):
|
|||||||
channel_id_filter = 0
|
channel_id_filter = 0
|
||||||
total_videos = 0
|
total_videos = 0
|
||||||
search = ''
|
search = ''
|
||||||
|
subprocess = False
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.read_data()
|
self.read_data()
|
||||||
self.total_videos = self.get_total_videos()
|
self.total_videos = self.get_total_videos()
|
||||||
|
|
||||||
def read_data(self):
|
def read_data(self):
|
||||||
with self.connection:
|
with self.connection:
|
||||||
cur = self.connection.cursor()
|
cur = self.connection.cursor()
|
||||||
cur.execute('SELECT id, nick, uploadsid FROM channel')
|
cur.execute('SELECT id, nick, uploadsid FROM channel')
|
||||||
self.youtube_channels = cur.fetchall()
|
self.youtube_channels = cur.fetchall()
|
||||||
if self.channel_id_filter > 0:
|
if self.channel_id_filter > 0:
|
||||||
cur.execute("SELECT nick, title, videoid, channel_id, seen FROM video JOIN channel ON video.channel_id = channel.id WHERE deleted IS NULL AND channel.id = ? AND title LIKE ? ORDER BY publishtime DESC LIMIT ?, 30", (self.channel_id_filter, '%'+self.search+'%', self.offset))
|
cur.execute(
|
||||||
|
"SELECT nick, title, videoid, channel_id, seen FROM video JOIN channel ON video.channel_id = channel.id WHERE deleted IS NULL AND channel.id = ? AND title LIKE ? ORDER BY publishtime DESC LIMIT ?, 30",
|
||||||
|
(self.channel_id_filter, '%' + self.search + '%', self.offset))
|
||||||
else:
|
else:
|
||||||
cur.execute("SELECT nick, title, videoid, channel_id, seen FROM video JOIN channel ON video.channel_id = channel.id WHERE deleted IS NULL AND title LIKE ? ORDER BY publishtime DESC LIMIT ?, 30", ('%'+self.search+'%', self.offset))
|
cur.execute(
|
||||||
|
"SELECT nick, title, videoid, channel_id, seen FROM video JOIN channel ON video.channel_id = channel.id WHERE deleted IS NULL AND title LIKE ? ORDER BY publishtime DESC LIMIT ?, 30",
|
||||||
|
('%' + self.search + '%', self.offset))
|
||||||
|
|
||||||
self.videos = cur.fetchall()
|
self.videos = cur.fetchall()
|
||||||
|
|
||||||
|
|
||||||
def lite(self, channels):
|
def lite(self, channels):
|
||||||
with self.connection:
|
with self.connection:
|
||||||
@@ -70,7 +76,7 @@ class Mc(object):
|
|||||||
cur.execute("SELECT * FROM channel WHERE nick = :nick", {"nick": channel['nick']})
|
cur.execute("SELECT * FROM channel WHERE nick = :nick", {"nick": channel['nick']})
|
||||||
self.connection.commit()
|
self.connection.commit()
|
||||||
row = cur.fetchone()
|
row = cur.fetchone()
|
||||||
if row == None:
|
if row is None:
|
||||||
cur.execute(
|
cur.execute(
|
||||||
"INSERT INTO channel('playlist', 'nick', 'channel', 'userid', 'uploadsid') VALUES (?, ?, ?, ?, ?)",
|
"INSERT INTO channel('playlist', 'nick', 'channel', 'userid', 'uploadsid') VALUES (?, ?, ?, ?, ?)",
|
||||||
('1', channel['nick'], channel['channel'], channel['userid'], channel['uploadsid']))
|
('1', channel['nick'], channel['channel'], channel['userid'], channel['uploadsid']))
|
||||||
@@ -80,44 +86,50 @@ class Mc(object):
|
|||||||
return self.youtube_info_url + video_id
|
return self.youtube_info_url + video_id
|
||||||
|
|
||||||
def print_videos(self, stdscr):
|
def print_videos(self, stdscr):
|
||||||
iterator = 0
|
iterator = 0
|
||||||
for video in self.videos:
|
for video in self.videos:
|
||||||
is_file = "X" if file_exists(video[1]) else " "
|
is_file = "X" if file_exists(video[1]) else " "
|
||||||
if iterator == self.selected_video:
|
if iterator == self.selected_video:
|
||||||
stdscr.addstr(iterator, 0, "[%s] %s %-60s" % (video[0].ljust(14, ' '), is_file, video[1]), curses.A_STANDOUT)
|
stdscr.addstr(iterator, 0, "[%s] %s %-60s" % (video[0].ljust(14, ' '), is_file, video[1]),
|
||||||
|
curses.A_STANDOUT)
|
||||||
elif video[4] == 1:
|
elif video[4] == 1:
|
||||||
stdscr.addstr(iterator, 0, "[%s] %s %-60s" % (video[0].ljust(14, ' '), is_file, video[1]), curses.color_pair(236))
|
stdscr.addstr(iterator, 0, "[%s] %s %-60s" % (video[0].ljust(14, ' '), is_file, video[1]),
|
||||||
#stdscr.addstr(iterator, 0, "[%s] %s %s %-60s" % (video[0].ljust(14, ' '), is_file, video[1], iterator+self.offset), curses.color_pair(iterator+self.offset))
|
curses.color_pair(236))
|
||||||
|
# stdscr.addstr(iterator, 0, "[%s] %s %s %-60s" % (video[0].ljust(14, ' '), is_file, video[1], iterator+self.offset), curses.color_pair(iterator+self.offset))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
#stdscr.addstr(iterator, 0, "[%s] %s %s %-60s" % (video[0].ljust(14, ' '), is_file, video[1], iterator+self.offset), curses.color_pair(iterator+self.offset))
|
# stdscr.addstr(iterator, 0, "[%s] %s %s %-60s" % (video[0].ljust(14, ' '), is_file, video[1], iterator+self.offset), curses.color_pair(iterator+self.offset))
|
||||||
stdscr.addstr(iterator, 0, "[%s] %s %-60s" % (video[0].ljust(14, ' '), is_file, video[1]), curses.color_pair(255))
|
stdscr.addstr(iterator, 0, "[%s] %s %-60s" % (video[0].ljust(14, ' '), is_file, video[1]),
|
||||||
|
curses.color_pair(255))
|
||||||
iterator += 1
|
iterator += 1
|
||||||
|
|
||||||
def print_botom_info(self, stdscr):
|
def print_botom_info(self, stdscr):
|
||||||
pages = int(self.total_videos) // 30
|
pages = int(self.total_videos) // 30
|
||||||
stdscr.addstr(len(self.videos), 0, "Play [Enter] | Download [D] | Refresh [R] | Exit [Q] |", curses.A_BOLD )
|
stdscr.addstr(len(self.videos), 0, "Play [Enter] | Download [D] | Refresh [R] | Exit [Q] |", curses.A_BOLD)
|
||||||
if_search = curses.color_pair(90) if len(self.search) > 0 else curses.A_BOLD
|
if_search = curses.color_pair(90) if len(self.search) > 0 else curses.A_BOLD
|
||||||
if_filter = curses.color_pair(90) if self.channel_id_filter > 0 else curses.A_BOLD
|
if_filter = curses.color_pair(90) if self.channel_id_filter > 0 else curses.A_BOLD
|
||||||
stdscr.addstr(len(self.videos), 55, "Search [S]", if_search)
|
stdscr.addstr(len(self.videos), 55, "Search [S]", if_search)
|
||||||
stdscr.addstr(len(self.videos), 65, " | ", curses.A_BOLD)
|
stdscr.addstr(len(self.videos), 65, " | ", curses.A_BOLD)
|
||||||
stdscr.addstr(len(self.videos), 68, "Filter [F]" , if_filter)
|
stdscr.addstr(len(self.videos), 68, "Filter [F]", if_filter)
|
||||||
stdscr.addstr(len(self.videos), 78, " | " , curses.A_BOLD)
|
stdscr.addstr(len(self.videos), 78, " | ", curses.A_BOLD)
|
||||||
stdscr.addstr(len(self.videos), 81, "[<-/->] | [%d / %d] " % (self.offset /30+1, pages), curses.A_BOLD)
|
stdscr.addstr(len(self.videos), 81, "[<-/->] | [%d / %d] " % (self.offset / 30 + 1, pages), curses.A_BOLD)
|
||||||
|
|
||||||
def get_total_videos(self):
|
def get_total_videos(self):
|
||||||
with self.connection:
|
with self.connection:
|
||||||
cur = self.connection.cursor()
|
cur = self.connection.cursor()
|
||||||
if self.channel_id_filter > 0:
|
if self.channel_id_filter > 0:
|
||||||
cur.execute("SELECT count(video.id) FROM video JOIN channel ON video.channel_id = channel.id AND channel.id = ? WHERE title like ?", (self.channel_id_filter, '%'+self.search+'%'))
|
cur.execute(
|
||||||
|
"SELECT count(video.id) FROM video JOIN channel ON video.channel_id = channel.id AND channel.id = ? WHERE title like ?",
|
||||||
|
(self.channel_id_filter, '%' + self.search + '%'))
|
||||||
else:
|
else:
|
||||||
cur.execute("SELECT count(video.id) FROM video JOIN channel ON video.channel_id = channel.id WHERE title LIKE ?", ('%'+self.search+'%',))
|
cur.execute(
|
||||||
|
"SELECT count(video.id) FROM video JOIN channel ON video.channel_id = channel.id WHERE title LIKE ?",
|
||||||
|
('%' + self.search + '%',))
|
||||||
return int(cur.fetchone()[0])
|
return int(cur.fetchone()[0])
|
||||||
|
|
||||||
def get_video_direct_urls(self, video_id):
|
def get_video_direct_urls(self, video_id):
|
||||||
streams = []
|
streams = []
|
||||||
data = requests.get(self.get_video_info_url(video_id))
|
data = requests.get(self.get_video_info_url(video_id))
|
||||||
unescaped = unescape(data.text)
|
|
||||||
decoded = urllib.parse.parse_qs(data.text)
|
decoded = urllib.parse.parse_qs(data.text)
|
||||||
|
|
||||||
for stream in decoded['url_encoded_fmt_stream_map'][0].split(','):
|
for stream in decoded['url_encoded_fmt_stream_map'][0].split(','):
|
||||||
@@ -127,27 +139,23 @@ class Mc(object):
|
|||||||
|
|
||||||
def get_all_videos(self):
|
def get_all_videos(self):
|
||||||
for id, channelName, uploadListId in self.youtube_channels:
|
for id, channelName, uploadListId in self.youtube_channels:
|
||||||
|
|
||||||
videos = youtube.playlistItems(uploadListId, self.youtube_api_key, True)
|
videos = youtube.playlistItems(uploadListId, self.youtube_api_key, True)
|
||||||
for row in videos:
|
for row in videos:
|
||||||
self.save_video(id, row)
|
self.save_video(id, row)
|
||||||
|
|
||||||
|
|
||||||
def get_recent_videos_silent(self, allVideos=False):
|
def get_recent_videos_silent(self, allVideos=False):
|
||||||
for id, channelName, uploadListId in self.youtube_channels:
|
for id, channelName, uploadListId in self.youtube_channels:
|
||||||
videos = youtube.playlistItems(uploadListId, self.youtube_api_key, allVideos)
|
videos = youtube.playlistItems(uploadListId, self.youtube_api_key, allVideos)
|
||||||
for row in videos:
|
for row in videos:
|
||||||
self.save_video(id, row)
|
self.save_video(id, row)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_recent_videos(self, stdscr):
|
def get_recent_videos(self, stdscr):
|
||||||
channel_iterator = 1
|
channel_iterator = 1
|
||||||
|
|
||||||
for id, channelName, uploadListId in self.youtube_channels:
|
for id, channelName, uploadListId in self.youtube_channels:
|
||||||
stdscr.addstr(channel_iterator, 0, '%s %d/%d' % (channelName,0,50))
|
stdscr.addstr(channel_iterator, 0, '%s %d/%d' % (channelName, 0, 50))
|
||||||
channel_iterator+=1
|
channel_iterator += 1
|
||||||
|
|
||||||
channel_iterator = 1
|
channel_iterator = 1
|
||||||
for id, channelName, uploadListId in self.youtube_channels:
|
for id, channelName, uploadListId in self.youtube_channels:
|
||||||
@@ -155,43 +163,31 @@ class Mc(object):
|
|||||||
videos_iterator = 1
|
videos_iterator = 1
|
||||||
for row in videos:
|
for row in videos:
|
||||||
self.save_video(id, row)
|
self.save_video(id, row)
|
||||||
stdscr.addstr(channel_iterator, 0, '%s %d/%d' % (channelName,videos_iterator, len(videos)))
|
stdscr.addstr(channel_iterator, 0, '%s %d/%d' % (channelName, videos_iterator, len(videos)))
|
||||||
stdscr.refresh()
|
stdscr.refresh()
|
||||||
videos_iterator+=1
|
videos_iterator += 1
|
||||||
channel_iterator+=1
|
channel_iterator += 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def save_video(self, channel_id, video_row):
|
def save_video(self, channel_id, video_row):
|
||||||
with self.connection:
|
with self.connection:
|
||||||
cur = self.connection.cursor()
|
cur = self.connection.cursor()
|
||||||
|
|
||||||
cur.execute(
|
cur.execute(
|
||||||
"INSERT OR IGNORE INTO video('channel_id', 'title', 'views', 'duration', 'videoid', 'publishtime') VALUES (?, ?, ?, ?, ?, ?)",
|
"INSERT OR IGNORE INTO video('channel_id', 'title', 'views', 'duration', 'videoid', 'publishtime') VALUES (?, ?, ?, ?, ?, ?)",
|
||||||
(channel_id, video_row['title'], 0, 0, video_row['videoid'], video_row['timestamp']))
|
(channel_id, video_row['title'], 0, 0, video_row['videoid'], video_row['timestamp']))
|
||||||
self.connection.commit()
|
self.connection.commit()
|
||||||
|
|
||||||
|
|
||||||
def main_loop(self, stdscr):
|
def main_loop(self, stdscr):
|
||||||
stdscr.keypad(True)
|
stdscr.keypad(True)
|
||||||
stdscr.clear()
|
stdscr.clear()
|
||||||
|
|
||||||
|
|
||||||
curses.use_default_colors()
|
curses.use_default_colors()
|
||||||
|
|
||||||
for i in range(0, curses.COLORS):
|
for i in range(0, curses.COLORS):
|
||||||
curses.init_pair(i, i, -1);
|
curses.init_pair(i, i, -1);
|
||||||
|
|
||||||
self.print_videos(stdscr)
|
self.print_videos(stdscr)
|
||||||
mc.print_botom_info(stdscr)
|
mc.print_botom_info(stdscr)
|
||||||
curses.curs_set(0)
|
curses.curs_set(0)
|
||||||
|
|
||||||
|
|
||||||
while 1:
|
while 1:
|
||||||
stdscr.refresh()
|
stdscr.refresh()
|
||||||
|
|
||||||
key = stdscr.getch()
|
key = stdscr.getch()
|
||||||
|
|
||||||
if key == curses.KEY_UP:
|
if key == curses.KEY_UP:
|
||||||
stdscr.refresh()
|
stdscr.refresh()
|
||||||
mc.selected_video -= 1
|
mc.selected_video -= 1
|
||||||
@@ -206,10 +202,10 @@ class Mc(object):
|
|||||||
stdscr.clear()
|
stdscr.clear()
|
||||||
self.offset += 30;
|
self.offset += 30;
|
||||||
self.read_data()
|
self.read_data()
|
||||||
|
|
||||||
elif key == curses.KEY_LEFT:
|
elif key == curses.KEY_LEFT:
|
||||||
stdscr.clear()
|
stdscr.clear()
|
||||||
if(self.offset > 30):
|
if self.offset > 30:
|
||||||
self.offset -= 30
|
self.offset -= 30
|
||||||
else:
|
else:
|
||||||
self.offset = 0
|
self.offset = 0
|
||||||
@@ -227,28 +223,23 @@ class Mc(object):
|
|||||||
elif key in [ord('A'), ord('a')]:
|
elif key in [ord('A'), ord('a')]:
|
||||||
stdscr.clear()
|
stdscr.clear()
|
||||||
editwin = curses.newwin(1, 49, 2, 1)
|
editwin = curses.newwin(1, 49, 2, 1)
|
||||||
stdscr.addstr(0,0,'Search channel:')
|
stdscr.addstr(0, 0, 'Search channel:')
|
||||||
stdscr.addstr(1, 0, '+-------------------------------------------------+')
|
stdscr.addstr(1, 0, '+-------------------------------------------------+')
|
||||||
stdscr.addstr(2, 0, '| |')
|
stdscr.addstr(2, 0, '| |')
|
||||||
stdscr.addstr(3, 0, '+-------------------------------------------------+')
|
stdscr.addstr(3, 0, '+-------------------------------------------------+')
|
||||||
|
|
||||||
stdscr.refresh()
|
stdscr.refresh()
|
||||||
box = Textbox(editwin)
|
box = Textbox(editwin)
|
||||||
box.edit()
|
box.edit()
|
||||||
|
|
||||||
self.searchChannel = box.gather()
|
self.searchChannel = box.gather()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
elif key in [ord('S'), ord('s')]:
|
elif key in [ord('S'), ord('s')]:
|
||||||
stdscr.clear()
|
stdscr.clear()
|
||||||
editwin = curses.newwin(1,49, 2,1)
|
editwin = curses.newwin(1, 49, 2, 1)
|
||||||
stdscr.addstr(0, 0, 'SEARCH BY TITLE:')
|
stdscr.addstr(0, 0, 'SEARCH BY TITLE:')
|
||||||
stdscr.addstr(1, 0, '+-------------------------------------------------+')
|
stdscr.addstr(1, 0, '+-------------------------------------------------+')
|
||||||
stdscr.addstr(2, 0, '| |')
|
stdscr.addstr(2, 0, '| |')
|
||||||
stdscr.addstr(3, 0, '+-------------------------------------------------+')
|
stdscr.addstr(3, 0, '+-------------------------------------------------+')
|
||||||
|
|
||||||
|
|
||||||
stdscr.refresh()
|
stdscr.refresh()
|
||||||
box = Textbox(editwin)
|
box = Textbox(editwin)
|
||||||
@@ -260,7 +251,6 @@ class Mc(object):
|
|||||||
|
|
||||||
stdscr.clear()
|
stdscr.clear()
|
||||||
|
|
||||||
|
|
||||||
elif key in [ord('R'), ord('r')]:
|
elif key in [ord('R'), ord('r')]:
|
||||||
stdscr.clear()
|
stdscr.clear()
|
||||||
|
|
||||||
@@ -269,7 +259,6 @@ class Mc(object):
|
|||||||
self.read_data()
|
self.read_data()
|
||||||
self.total_videos = self.get_total_videos()
|
self.total_videos = self.get_total_videos()
|
||||||
|
|
||||||
|
|
||||||
elif key in [ord('D'), ord('d')]:
|
elif key in [ord('D'), ord('d')]:
|
||||||
video_id = mc.videos[mc.selected_video][2]
|
video_id = mc.videos[mc.selected_video][2]
|
||||||
streams = mc.get_video_direct_urls(video_id)
|
streams = mc.get_video_direct_urls(video_id)
|
||||||
@@ -279,38 +268,37 @@ class Mc(object):
|
|||||||
os.system('wget -nv --show-progress -O "/public/youtube/%s.mp4" "%s" >> /dev/null &' % (
|
os.system('wget -nv --show-progress -O "/public/youtube/%s.mp4" "%s" >> /dev/null &' % (
|
||||||
get_valid_filename(mc.videos[mc.selected_video][1]), stream['url'][0]))
|
get_valid_filename(mc.videos[mc.selected_video][1]), stream['url'][0]))
|
||||||
|
|
||||||
elif key in [ord('Q'), ord('q')]: # esc
|
elif key in [ord('Q'), ord('q')]: # esc
|
||||||
curses.endwin()
|
curses.endwin()
|
||||||
os._exit(0)
|
os._exit(0)
|
||||||
elif key == 10 or key == curses.KEY_ENTER:
|
elif key == 10 or key == curses.KEY_ENTER:
|
||||||
video_id = mc.videos[mc.selected_video][2]
|
video_id = mc.videos[mc.selected_video][2]
|
||||||
#stdscr.clear()
|
# stdscr.clear()
|
||||||
#stdscr.addstr(0, 0, '/public/youtube/' + get_valid_filename(mc.videos[mc.selected_video][1])+".mp4")
|
# stdscr.addstr(0, 0, '/public/youtube/' + get_valid_filename(mc.videos[mc.selected_video][1])+".mp4")
|
||||||
|
|
||||||
# stdscr.refresh()
|
# stdscr.refresh()
|
||||||
# time.sleep(4)
|
# time.sleep(4)
|
||||||
|
|
||||||
with self.connection:
|
with self.connection:
|
||||||
cur = self.connection.cursor()
|
cur = self.connection.cursor()
|
||||||
cur.execute('UPDATE video SET seen = 1 WHERE videoid = ?', (video_id, ))
|
cur.execute('UPDATE video SET seen = 1 WHERE videoid = ?', (video_id,))
|
||||||
self.youtube_channels = cur.fetchall()
|
self.youtube_channels = cur.fetchall()
|
||||||
self.connection.commit()
|
self.connection.commit()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if file_exists(mc.videos[mc.selected_video][1]):
|
if file_exists(mc.videos[mc.selected_video][1]):
|
||||||
|
#stdscr.addstr(1, 1, '/public/youtube/' + get_valid_filename(mc.videos[mc.selected_video][1])+".mp4")
|
||||||
# stdscr.addstr(1, 1, '/public/youtube/' + get_valid_filename(mc.videos[mc.selected_video][1])+".mp4")
|
# stdscr.refresh()
|
||||||
# stdscr.refresh()
|
os.system('omxplayer -b "%s"' % (
|
||||||
os.system('omxplayer -b "%s"' % ("/public/youtube/" + get_valid_filename(mc.videos[mc.selected_video][1])+".mp4" ))
|
"/public/youtube/" + get_valid_filename(mc.videos[mc.selected_video][1]) + ".mp4"))
|
||||||
else:
|
else:
|
||||||
streams = mc.get_video_direct_urls(video_id)
|
streams = mc.get_video_direct_urls(video_id)
|
||||||
|
|
||||||
for stream in streams:
|
for stream in streams:
|
||||||
# print (stream['itag'])
|
# print (stream['itag'])
|
||||||
if stream['itag'][0] == "22":
|
if stream['itag'][0] == "22":
|
||||||
os.system('omxplayer -b "%s"' % stream['url'][0])
|
# os.system('omxplayer -b "%s"' % stream['url'][0])
|
||||||
|
self.subprocess = Popen(['omxplayer', '-b', stream['url'][0]], stdin=PIPE,
|
||||||
|
stdout=DEVNULL, close_fds=True, bufsize=0)
|
||||||
stdscr.clear()
|
stdscr.clear()
|
||||||
|
|
||||||
mc.print_videos(stdscr)
|
mc.print_videos(stdscr)
|
||||||
@@ -320,27 +308,26 @@ class Mc(object):
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
mc = Mc()
|
mc = Mc()
|
||||||
|
|
||||||
#test('test')
|
# test('test')
|
||||||
|
|
||||||
#print (youtube.search('generikb', 'channel', "AIzaSyBwecAq2aCjRxStpOclQZNSRpJEI2HtvX0"))
|
# print (youtube.search('generikb', 'channel', "AIzaSyBwecAq2aCjRxStpOclQZNSRpJEI2HtvX0"))
|
||||||
|
|
||||||
#videos = youtube.playlistItems("UU-_VTaWqRsZ1nzZLHQIGwQA", "AIzaSyBwecAq2aCjRxStpOclQZNSRpJEI2HtvX0")
|
# videos = youtube.playlistItems("UU-_VTaWqRsZ1nzZLHQIGwQA", "AIzaSyBwecAq2aCjRxStpOclQZNSRpJEI2HtvX0")
|
||||||
#print(videos)
|
# print(videos)
|
||||||
#mc.get_all_videos()
|
# mc.get_all_videos()
|
||||||
|
|
||||||
#mc.lite(channels)
|
# mc.lite(channels)
|
||||||
|
|
||||||
# print (mc.get_video_info_url('https://www.youtube.com/watch?v=vw61gCe2oqI'))
|
# print (mc.get_video_info_url('https://www.youtube.com/watch?v=vw61gCe2oqI'))
|
||||||
|
|
||||||
# mc.get_videos('UUFKDEp9si4RmHFWJW1vYsMA')
|
# mc.get_videos('UUFKDEp9si4RmHFWJW1vYsMA')
|
||||||
|
|
||||||
# mc.get_videos('UUJTWU5K7kl9EE109HBeoldA')
|
# mc.get_videos('UUJTWU5K7kl9EE109HBeoldA')
|
||||||
# os.system('clear')
|
# os.system('clear')
|
||||||
#
|
#
|
||||||
try:
|
try:
|
||||||
curses.wrapper(mc.main_loop)
|
curses.wrapper(mc.main_loop)
|
||||||
#cProfile.run('re.compile("foo|bar")')
|
# cProfile.run('re.compile("foo|bar")')
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
curses.endwin()
|
curses.endwin()
|
||||||
os._exit(0)
|
os._exit(0)
|
||||||
|
|
||||||
|
|||||||
27
youtube.py
27
youtube.py
@@ -2,34 +2,35 @@ import requests
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import calendar
|
import calendar
|
||||||
|
|
||||||
|
|
||||||
def search(what, type, api_key):
|
def search(what, type, api_key):
|
||||||
url = "https://www.googleapis.com/youtube/v3/search?part=snippet&q=%s&type=%s&key=%s" % (what, type, api_key)
|
url = "https://www.googleapis.com/youtube/v3/search?part=snippet&q=%s&type=%s&key=%s" % (what, type, api_key)
|
||||||
r = requests.get(url)
|
r = requests.get(url)
|
||||||
return r.json()
|
return r.json()
|
||||||
|
|
||||||
def playlistItems(playlistId, api_key, all=False, nextToken=None):
|
|
||||||
|
def playlistItems(playlistid, api_key, allmovies=False, nexttoken=None):
|
||||||
videos = []
|
videos = []
|
||||||
info_url = "https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&playlistId=%s&key=%s" % (
|
info_url = "https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&playlistId=%s&key=%s" % (
|
||||||
playlistId,
|
playlistid,
|
||||||
api_key
|
api_key
|
||||||
)
|
)
|
||||||
|
|
||||||
if nextToken is not None:
|
if nexttoken is not None:
|
||||||
info_url += "&pageToken=%s" % (nextToken)
|
info_url += "&pageToken=%s" % (nexttoken)
|
||||||
|
|
||||||
request_data = requests.get(info_url)
|
request_data = requests.get(info_url)
|
||||||
|
|
||||||
request_data_json = request_data.json()
|
request_data_json = request_data.json()
|
||||||
|
|
||||||
videos += parseRequestData(request_data_json)
|
videos += parse_request_data(request_data_json)
|
||||||
if all == True and 'nextPageToken' in request_data_json:
|
if allmovies is True and 'nextPageToken' in request_data_json:
|
||||||
videos += playlistItems(playlistId, api_key, request_data_json['nextPageToken'])
|
videos += playlistItems(playlistid, api_key, request_data_json['nextPageToken'])
|
||||||
|
|
||||||
return videos
|
return videos
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def parseRequestData(request_data_json):
|
|
||||||
|
def parse_request_data(request_data_json):
|
||||||
parsed_videos = []
|
parsed_videos = []
|
||||||
for element in request_data_json['items']:
|
for element in request_data_json['items']:
|
||||||
video = {}
|
video = {}
|
||||||
@@ -41,8 +42,4 @@ def parseRequestData(request_data_json):
|
|||||||
video['channel_id'] = element['snippet']['channelId']
|
video['channel_id'] = element['snippet']['channelId']
|
||||||
video['nick'] = element['snippet']['channelTitle']
|
video['nick'] = element['snippet']['channelTitle']
|
||||||
parsed_videos.append(video)
|
parsed_videos.append(video)
|
||||||
|
return parsed_videos
|
||||||
return parsed_videos
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user