-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbasicFunctions.py
120 lines (87 loc) · 4.19 KB
/
basicFunctions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import logging
MAX_VIDEO_FETCH_COUNT = 20
log = logging.getLogger('Floatplane')
def showVideoComments(client, video, limit=None):
for comment in client.getVideoComments(video.guid, limit):
print(" > {} +{} -{}:\n {}".format(
comment.user.username,
comment.interactionCounts.like,
comment.interactionCounts.dislike,
comment.text.strip()
))
for comment in comment.replies:
print(" | > {} +{} -{}:\n {}".format(
comment.user.username,
comment.interactionCounts.like,
comment.interactionCounts.dislike,
comment.text.strip()
))
def showVideo(client, video, commentLimit=None, displayDownloadLink=False, showRelatedVideos=False, showComments=False):
try:
print('Video: [{}] {}'.format(video.guid, video.title))
videoInfo = client.getVideoInfo(video.guid)
if hasattr(videoInfo, 'releaseDate'):
print('ReleaseDate: {}'.format(videoInfo.releaseDate.strftime("%d.%m.%Y %H:%M:%S")))
if displayDownloadLink:
print('Link: {}'.format(client.getDirectVideoURL(video.guid)))
print('Related videos:')
if showRelatedVideos:
related = client.getReleatedVideos(video.guid)
for vid in related:
creator = client.getCreatorInfo(vid.creator.id)
print('-> [{}][{}] {}'.format(creator[0].title, vid.guid, vid.title))
print()
if showComments:
showVideoComments(client, video, commentLimit)
except Exception as e:
print('Ignoring video')
print(e)
def showCreatorPlaylists(client, creator, playlistLimit=None, videosPerPlaylist=None):
playlists = client.getCreatorPlaylists(creator, playlistLimit)
if playlists is None:
return
for playlist in playlists:
print('-> {}'.format(playlist.title))
videos = client.getPlaylistVideos(playlist)
if videos is None:
continue
for video in videos:
print('--> [{}] {}'.format(video.guid, video.title))
def showCreator(client, creator, videoLimit=None, commentsPerVideo=None, resolveVideos=True, showVideoFunc=None,
displayDownloadLink=False):
# print('Owner: {}'.format(client.getUser(creator.owner)))
if not resolveVideos:
return
videos = []
skip_count = 0
while skip_count < videoLimit:
tmp_limit = videoLimit if videoLimit <= MAX_VIDEO_FETCH_COUNT else videoLimit - skip_count if videoLimit - skip_count <= MAX_VIDEO_FETCH_COUNT else MAX_VIDEO_FETCH_COUNT
limit = None if skip_count > 0 and tmp_limit == MAX_VIDEO_FETCH_COUNT else tmp_limit
log.info('Getting videos for {} {} -> {}'.format(creator.title, skip_count,
skip_count + (limit if limit is not None else 0)))
tmp_vids = client.getVideosByCreator(creator.id, limit=limit, fetch_after=skip_count)
if len(tmp_vids) == 0:
break
for vid in tmp_vids:
videos.append(vid)
skip_count = skip_count + len(tmp_vids)
if videos is None:
print('No videos found for creator {}'.format(creator.title))
else:
for video in videos:
print()
if showVideoFunc:
showVideoFunc(client, video, creator=creator, commentLimit=commentsPerVideo,
displayDownloadLink=displayDownloadLink)
def showEdgeSelection(client):
edgeInfo = client.getEdges()
print('Found {} Edges'.format(len(edgeInfo.edges)))
for edge in edgeInfo.edges:
print(
'-> [{}-{}] {} BW:{}GBit/s Download:{} Stream:{}'.format(edge.datacenter.country_code,
edge.datacenter.region_code,
edge.hostname, edge.bandwidth / 1000 / 1000 / 1000,
edge.allowDownload, edge.allowStreaming))
selected_edge = client.getTargetEdgeServer()
print()
print('=> Selected Edge: {}'.format(selected_edge.hostname))