ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am not sure if anyone here knows about Youtube scripting but the part of this script that might not be working is the this part
Code:
sed "s/.*\?v=\([^\"]*\)\".*/\1/g")
I have been using a script to find the last video uploaded to my account for a few years. For about the last week I have had to manually add the video id to am embed code because the code did not find the video ID.
Has there been a change that I missed. The code I use is below.
Code:
#!/bin/bash
#
# Script to find last video id from my channel and create an embed code to put in a file.
# Need to replace the Working directory and Your channel id for this to work
#
date
# work from
cd working directory
# Define RSS feed for your channel
URL="https://www.youtube.com/feeds/videos.xml?channel_id="Your Channel ID"
videoid=$(curl -s $URL | grep "/watch?v=" | head -1 | sed "s/.*\?v=\([^\"]*\)\".*/\1/g")
echo $videoid
echo Last Video ID = $videoid
s="<center><iframe width=\"640\" height=\"480\""
s="$s src=\"https://www.youtube.com/embed/${videoid}?feature=player_embedded\""
s="$s frameborder=\"0\" allowfullscreen></iframe></center>"
echo "$s" > youtube-iframe.php
echo Copy complete and Youtube-iframe file copied over to html
date
cp youtube-iframe.php "web site folder"
I am not a programmer so forgive me if I got this wrong.
I tried to get this command to run but could not. This is what I did from command line.
Code:
URL="https://www.youtube.com/feeds/videos.xml?channel_id=My Channel ID
sudo yt-dlp --skip-download --get-id --playlist-end=1 "$URL"
This is the result.
Code:
Traceback (most recent call last):
File "/usr/bin/yt-dlp", line 6, in <module>
from pkg_resources import load_entry_point
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3254, in <module>
def _initialize_master_working_set():
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3237, in _call_aside
f(*args, **kwargs)
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3266, in _initialize_master_working_set
working_set = WorkingSet._build_master()
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 584, in _build_master
ws.require(__requires__)
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 901, in require
needed = self.resolve(parse_requirements(requirements))
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 787, in resolve
raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'brotli' distribution was not found and is required by yt-dlp
I have brotli installed
Code:
sudo apt install brotli Reading package lists... Done
Building dependency tree
Reading state information... Done
brotli is already the newest version (1.0.7-6ubuntu0.1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
The "77huZZ415vg" is what I am after as the $videoid. I do not understand what
Code:
sed "s/.*\?v=\([^"]*\)".*/\1/g
does.
I am a 74 year old fart and the brain cells aren't what they used to be.
Turns out LLM's can do this now:
Quote:
Don't worry, I'll break down the command for you:
Code:
sed "s/.*\?v=\([^"]*\)".*/\1/g
This is a command using `sed`, which stands for stream editor. It's commonly used to perform text transformations on an input stream (a file or data passed through a pipeline). Let's break down the command step by step:
1. `s/`: This indicates that we are performing a substitution operation.
2. `.*\?v=`: This part matches any characters (`.*`) followed by `?v=`. The `.*` matches any character (except for a newline) zero or more times. `\?` matches the literal question mark character. So, `.*\?v=` together matches any characters followed by `?v=`.
3. `\([^"]*\)`: This part is enclosed in `\(` and `\)` which means it's a capture group. It captures the string between `=` and `"`. `[^"]*` matches any character except for `"`, zero or more times.
4. `.*`: This matches any remaining characters after the part we're interested in.
5. `\1`: This refers to the first capture group, which is the string between `=` and `"`.
6. `g`: This flag stands for "global" and ensures that all occurrences in each line are substituted, not just the first one.
So, in essence, the command is searching for a pattern that looks like `?v=...` in the input text and extracts the characters following `?v=` up to the next `"`. Then it replaces the whole line with just the extracted characters.
(it seems to have forgot the closing " after the capture group in the step by step part, but is otherwise correct.)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.