Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Anything Llm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
Mintplex Labs
Anything Llm
Commits
d8961058
Unverified
Commit
d8961058
authored
1 year ago
by
Timothy Carambat
Committed by
GitHub
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
improve error messages from YT scraping (#768)
parse & enforce URL to allow multiple URL schemas
parent
49fbd09a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
collector/utils/extensions/YoutubeTranscript/index.js
+19
-5
19 additions, 5 deletions
collector/utils/extensions/YoutubeTranscript/index.js
with
19 additions
and
5 deletions
collector/utils/extensions/YoutubeTranscript/index.js
+
19
−
5
View file @
d8961058
...
@@ -6,11 +6,15 @@ const { v4 } = require("uuid");
...
@@ -6,11 +6,15 @@ const { v4 } = require("uuid");
const
{
writeToServerDocuments
}
=
require
(
"
../../files
"
);
const
{
writeToServerDocuments
}
=
require
(
"
../../files
"
);
const
{
tokenizeString
}
=
require
(
"
../../tokenizer
"
);
const
{
tokenizeString
}
=
require
(
"
../../tokenizer
"
);
function
validYoutubeVideoUrl
(
url
)
{
function
validYoutubeVideoUrl
(
link
)
{
const
UrlPattern
=
require
(
"
url-pattern
"
);
const
UrlPattern
=
require
(
"
url-pattern
"
);
const
opts
=
new
URL
(
link
);
const
url
=
`
${
opts
.
protocol
}
//
${
opts
.
host
}${
opts
.
pathname
}
?v=
${
opts
.
searchParams
.
get
(
"
v
"
)}
`
;
const
shortPatternMatch
=
new
UrlPattern
(
const
shortPatternMatch
=
new
UrlPattern
(
"
https
\\
://youtu.be/(:videoId)
"
"
https
\\
://
(www.)
youtu.be/(:videoId)
"
).
match
(
url
);
).
match
(
url
);
const
fullPatternMatch
=
new
UrlPattern
(
const
fullPatternMatch
=
new
UrlPattern
(
"
https
\\
://(www.)youtube.com/watch?v=(:videoId)
"
"
https
\\
://(www.)youtube.com/watch?v=(:videoId)
"
...
@@ -32,12 +36,22 @@ async function loadYouTubeTranscript({ url }) {
...
@@ -32,12 +36,22 @@ async function loadYouTubeTranscript({ url }) {
console
.
log
(
`-- Working YouTube
${
url
}
--`
);
console
.
log
(
`-- Working YouTube
${
url
}
--`
);
const
loader
=
YoutubeLoader
.
createFromUrl
(
url
,
{
addVideoInfo
:
true
});
const
loader
=
YoutubeLoader
.
createFromUrl
(
url
,
{
addVideoInfo
:
true
});
const
docs
=
await
loader
.
load
();
const
{
docs
,
error
}
=
await
loader
.
load
()
.
then
((
docs
)
=>
{
return
{
docs
,
error
:
null
};
})
.
catch
((
e
)
=>
{
return
{
docs
:
[],
error
:
e
.
message
?.
split
(
"
Error:
"
)?.[
1
]
||
e
.
message
,
};
});
if
(
!
docs
.
length
)
{
if
(
!
docs
.
length
||
!!
error
)
{
return
{
return
{
success
:
false
,
success
:
false
,
reason
:
"
No transcript found for that YouTube video.
"
,
reason
:
error
??
"
No transcript found for that YouTube video.
"
,
};
};
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment