eaglelandsonce commited on
Commit
cca39e1
1 Parent(s): 3283b2e

Update pages/3_ChannelAgregator.py

Browse files
Files changed (1) hide show
  1. pages/3_ChannelAgregator.py +20 -16
pages/3_ChannelAgregator.py CHANGED
@@ -17,21 +17,25 @@ def extract_channel_videos(channel_id, api_key):
17
  video_ids = []
18
  next_page_token = None
19
 
20
- while True:
21
- request = youtube.search().list(
22
- part="id",
23
- channelId=channel_id,
24
- maxResults=50, # You can fetch up to 50 results per request
25
- type="video",
26
- order="date", # Newest videos first
27
- pageToken=next_page_token
28
- )
29
- response = request.execute()
30
- video_ids += [item['id']['videoId'] for item in response.get('items', [])]
 
31
 
32
- next_page_token = response.get('nextPageToken')
33
- if not next_page_token:
34
- break
 
 
 
35
 
36
  return video_ids
37
 
@@ -54,7 +58,7 @@ st.title("YouTube Channel Transcription Extractor")
54
  api_key = st.text_input("Enter your Google API Key", type="password")
55
  channel_id = st.text_input("Enter YouTube Channel ID", placeholder="Example: UCK8sQmJBp8GCxrOtXWBpyEA")
56
  if st.button("Fetch Video List"):
57
- if api_key:
58
  video_ids = extract_channel_videos(channel_id, api_key)
59
  video_ids_string = ", ".join(video_ids)
60
  edited_videos = st.text_area("Edit Video IDs (comma-separated):", value=video_ids_string, height=100)
@@ -64,4 +68,4 @@ if st.button("Fetch Video List"):
64
  st.text_area("Transcriptions:", value=result, height=300)
65
  st.download_button("Download Transcripts", data=result, file_name="transcripts.txt", mime="text/plain")
66
  else:
67
- st.error("Please enter a valid Google API Key.")
 
17
  video_ids = []
18
  next_page_token = None
19
 
20
+ try:
21
+ while True:
22
+ request = youtube.search().list(
23
+ part="id",
24
+ channelId=channel_id,
25
+ maxResults=50, # You can fetch up to 50 results per request
26
+ type="video",
27
+ order="date", # Newest videos first
28
+ pageToken=next_page_token
29
+ )
30
+ response = request.execute()
31
+ video_ids += [item['id']['videoId'] for item in response.get('items', [])]
32
 
33
+ next_page_token = response.get('nextPageToken')
34
+ if not next_page_token:
35
+ break
36
+ except Exception as e:
37
+ st.error(f"Failed to fetch video IDs: {str(e)}")
38
+ return []
39
 
40
  return video_ids
41
 
 
58
  api_key = st.text_input("Enter your Google API Key", type="password")
59
  channel_id = st.text_input("Enter YouTube Channel ID", placeholder="Example: UCK8sQmJBp8GCxrOtXWBpyEA")
60
  if st.button("Fetch Video List"):
61
+ if api_key and channel_id:
62
  video_ids = extract_channel_videos(channel_id, api_key)
63
  video_ids_string = ", ".join(video_ids)
64
  edited_videos = st.text_area("Edit Video IDs (comma-separated):", value=video_ids_string, height=100)
 
68
  st.text_area("Transcriptions:", value=result, height=300)
69
  st.download_button("Download Transcripts", data=result, file_name="transcripts.txt", mime="text/plain")
70
  else:
71
+ st.error("Please enter a valid Google API Key and YouTube Channel ID.")