2차 추가 개발사항. Input value를 video_id만 입력하는 것에서 video url을 전체 입력할 수 있도록 변경
Showing
2 changed files
with
42 additions
and
2 deletions
... | @@ -9,7 +9,7 @@ import requests | ... | @@ -9,7 +9,7 @@ import requests |
9 | import argparse | 9 | import argparse |
10 | import lxml.html | 10 | import lxml.html |
11 | import io | 11 | import io |
12 | - | 12 | +from urllib.parse import urlparse, parse_qs |
13 | from lxml.cssselect import CSSSelector | 13 | from lxml.cssselect import CSSSelector |
14 | 14 | ||
15 | YOUTUBE_COMMENTS_URL = 'https://www.youtube.com/all_comments?v={youtube_id}' | 15 | YOUTUBE_COMMENTS_URL = 'https://www.youtube.com/all_comments?v={youtube_id}' |
... | @@ -130,6 +130,23 @@ def goto_Menu(result_List) : | ... | @@ -130,6 +130,23 @@ def goto_Menu(result_List) : |
130 | else : | 130 | else : |
131 | print('Not Found') | 131 | print('Not Found') |
132 | 132 | ||
133 | +## input video 값 parsing | ||
134 | +def video_id(value): | ||
135 | + query = urlparse(value) | ||
136 | + if query.hostname == 'youtu.be': | ||
137 | + return query.path[1:] | ||
138 | + if query.hostname in ('www.youtube.com', 'youtube.com'): | ||
139 | + if query.path == '/watch': | ||
140 | + p = parse_qs(query.query) | ||
141 | + return p['v'][0] | ||
142 | + if query.path[:7] == '/embed/': | ||
143 | + return query.path.split('/')[2] | ||
144 | + if query.path[:3] == '/v/': | ||
145 | + return query.path.split('/')[2] | ||
146 | + # fail? | ||
147 | + return None | ||
148 | + | ||
149 | + | ||
133 | def main(): | 150 | def main(): |
134 | 151 | ||
135 | #parser = argparse.ArgumentParser(add_help=False, description=('Download Youtube comments without using the Youtube API')) | 152 | #parser = argparse.ArgumentParser(add_help=False, description=('Download Youtube comments without using the Youtube API')) |
... | @@ -138,6 +155,8 @@ def main(): | ... | @@ -138,6 +155,8 @@ def main(): |
138 | #parser.add_argument('--output', '-o', help='Output filename (output format is line delimited JSON)') | 155 | #parser.add_argument('--output', '-o', help='Output filename (output format is line delimited JSON)') |
139 | #parser.add_argument('--limit', '-l', type=int, help='Limit the number of comments') | 156 | #parser.add_argument('--limit', '-l', type=int, help='Limit the number of comments') |
140 | Youtube_id1 = input('Youtube_ID 입력 :') | 157 | Youtube_id1 = input('Youtube_ID 입력 :') |
158 | + ## Cutting Link를 받고 id만 딸 수 있도록 | ||
159 | + Youtube_id1 = video_id(Youtube_id1) | ||
141 | Output1 = input('결과를 받을 파일 입력 :') | 160 | Output1 = input('결과를 받을 파일 입력 :') |
142 | Limit1 = input('제한 갯수 입력 : ') | 161 | Limit1 = input('제한 갯수 입력 : ') |
143 | ##### argument로 받지 않고 input으로 받기 위한 것 | 162 | ##### argument로 받지 않고 input으로 받기 위한 것 |
... | @@ -186,7 +205,8 @@ def main(): | ... | @@ -186,7 +205,8 @@ def main(): |
186 | if limit and count >= limit: | 205 | if limit and count >= limit: |
187 | break | 206 | break |
188 | print('\nDone!') | 207 | print('\nDone!') |
189 | - goto_Menu(result_List) | 208 | + return result_List |
209 | + #goto_Menu(result_List) | ||
190 | 210 | ||
191 | 211 | ||
192 | 212 | ... | ... |
Youtube/main.py
0 → 100644
1 | +import downloader | ||
2 | +from scraper import scrape_url | ||
3 | +from time import sleep | ||
4 | +from urllib.parse import urlparse | ||
5 | + | ||
6 | +def call_main (): | ||
7 | + print(' Comment Thread 생성중 \n') | ||
8 | + | ||
9 | + sleep(1) | ||
10 | + print(' **************************************************************') | ||
11 | + print(' **************************************************************') | ||
12 | + print(' **************************************************************') | ||
13 | + print(' **************** 생성 완료 정보를 입력하세요. **************** ') | ||
14 | + print(' **************************************************************') | ||
15 | + print(' **************************************************************') | ||
16 | + print(' **************************************************************') | ||
17 | + a = downloader.main() | ||
18 | + return a | ||
19 | + | ||
20 | +CommentList = call_main() |
-
Please register or login to post a comment