Drifty: [BUG] YouTube video link with playlist parameter is mistaken as playlist link

Describe the bug

A person clicked on a video from a YouTube playlist and when the link to the video is pasted in Drifty,

  • Drifty GUI tries to fetch the video name indefinitely. It also shows a popup window mentioning how many videos are there in the playlist but, it fails to download any. So, it keeps on detecting filename and computer heats up.
  • Drifty CLI shows an error that it fails to detect the filename and prompts the user to exit.

Steps To Reproduce

  1. Open Drifty GUI application.
  2. Paste a YouTube video link (containing both watch?v= and list= parameters), for example, this link - https://www.youtube.com/watch?v=uy_PEGgUF4U&list=PL0lo9MOBetEFGPccyxyfex8BYF_PQUQWn&index=1
  3. You can see that Drifty GUI tries to fetch the filename and the progress bar moves continuously indefinitely.
  4. Repeat the same in Drifty CLI to see that bug also.

Expected Behavior

Drifty must recognize that the URL is of a YouTube video and not of any playlists.

Screenshots

Drifty CLI

image

Drifty GUI

https://github.com/user-attachments/assets/db281ab2-10d2-4a25-811f-da45f78b4cad

Additional information

A regex match to identify if the provided link is a YouTube playlist or a specific YouTube video link, must be added. Yt-dlp fails to identify if a specific video is asked rather than the full playlist as seen when this code fragment is executed. https://github.com/SaptarshiSarkar12/Drifty/blob/3fff0e5e05a4fd871b50129aefff458ac246d59d/GUI/src/main/java/ui/GetFilename.java#L172-L192 A possible and reliable soluyion is to truncate the url upto the specific video id (the resultant url will be of the form https://www.youtube.com/watch?v=uy_PEGgUF4U).

If anyone wants to work on this issue, please comment below.

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 67 (37 by maintainers)

Commits related to this issue

Most upvoted comments

@Tarunkumarkanakam

Well, I think If we have a simple function that can identify each part would be better and future-proofed (for example, if in the future we require the application to deal with a playlist just use this function to extract the list param or any required param put the param in a URL, it works without any issue).

You are right. Moreover, the current version of drifty doesn’t detect duplicate links if they have the tracking parameter different although the ID of video or playlist is same. So, your method would also help in that case.

As per your information youtu.be/<videoID> is a link that doesn’t require any query param right. So first we will validate the YouTube link, then we will check if the link is a .com domain or a .be domain. If it is a .be we process it for download. Else it would be a link with .com and has watch?v={videoID} right. From this, we will extract the video ID and create a new URL like youtu.be\{videoID} to be processed by our backend.

Right 👍. There should be a / instead of \ in youtu.be\{videoID}.

By this we have a unified approach and every video will be handled based on one format under the hood even if the user gives any type of link (youtu.be/<videoID> youtube.com/watch?v=<videoID>). It’s future-proofed to extract the query params using a library and those params can be used in future functionality

Right. Agreed 💯.

Well I think this would be a better choice since whatever YouTube link we receive we handle it with a unified URL (youtu.be/{videoID}) format by converting it in the backend

Please don’t use youtu.be/{videoID}. Instead use youtube.com/watch?v={videoID} or youtube.com/playlist?list={listID} because you can have both playlists and videos under the same domain as youtu.be doesn’t support playlists. What do you think?

@Tarunkumarkanakam Can you share any of your socials (linkedIn preferably or twitter)? I would like to discuss something with you.

We can connect through LinkedIn, https://www.linkedin.com/in/tarun-kanakam

The current changes (the code I sent in previous messages) are in Drifty_CLI.java I observed that all the link validation is done in Utility.java in the Core Module. The same functions are being used in CLI and GUI. Shall I update the code in Utility.java?

@Tarunkumarkanakam If done, no need to update then. Where have you kept the sanitizeLink() method? Are you calling it from the link validation method?

else if (isYoutube(link)) {
    String videoId = null;
    try {
        URI uri = URI.create(link);
        String domain = uri.getHost();

        // checking if the domain is youtu.be
        if ("youtu.be".equals(domain)) {
            String path = uri.getPath();
            if (path != null && path.length() > 1) {
                videoId = path.substring(1); // removing the leading "/"
            }
        }
        // checking if the domain is youtube.com
        else if ("www.youtube.com".equals(domain) || "youtube.com".equals(domain)) {
            Map<String, String> queryParams = extractQueryParams(link, "v");
            videoId = queryParams.get("v");
        }

        if (videoId != null) {
            // constructing link in youtube.com/watch?v={videoID}
            uri = new URI("https", "www.youtube.com", "/watch", "v=" + videoId, null);
            link = uri.toString();
        } else {
            messageBroker.msgLinkError("YouTube video ID not found in the link.");
        }

    } catch (IllegalArgumentException | URISyntaxException e) {
        messageBroker.msgLinkError("Failed to process the YouTube link: " + e.getMessage());
    }
}

This is the updated code in Drifty_CLI.java This handles any type of YouTube link thrown by the user. This is right after the Instagram link handling in main method of Drifty_CLI.java

I’m preparing screenshots and short videos, I’ll send once done

mvn javafx:run

Yep it worked, I’ll work on it and let you know. If possible can you list out the things that need to be finished

Screenshot 2024-09-02 at 9 02 03 AM

Can you help me with this issue. I added DISPLAY variable in my WSL bash, and I also downloaded VcXSrv, Tested it with xclock working without any issue. But still this error is still there in my console

@Tarunkumarkanakam Which version of WSL were you using? It needs to be WSL version 2.

Yes its WSL 2

4. docker run -e DISPLAY=$DISPLAY --net=host -v /tmp/.X11-unix:/tmp/.X11-unix ghcr.io/saptarshisarkar12/drifty-gui:master

😔 Same issue Unable to open DISPLAY

@SaptarshiSarkar12 As per the issue description, using CLI the filename isn’t getting fetched and the application is prompting the user to exit. Well, In my case the file name was found and the video got downloaded too without any changes in the code. Please check the attached image. Let me know if I’m missing anything

@Tarunkumarkanakam The filename is the name of the playlist and not of the video. So, sometimes it shows filename detection failed if yt-dlp reported error else it uses playlist name if available. Hence, it is better to use watch?v= instead of list= when both are present to prevent confusion of yt-dlp 😆.

Got it

The same issue. Please check the attached image

Interesting. It used to work some months back and without even a small change, it stopped working now 😢. How inconsistent can these systems be 🙃!

Well, I am a Windows user. To run in a docker environment I need to execute xhost +local:docker right. So initially, I need to set up X Server on my machine right? If yes can you give steps to do that?

@Tarunkumarkanakam I think yes. I don’t have a windows machine and I tried multiple times to install wsl in my Windows VM but it failed each time and finally destructed the whole VM, so, I had to delete the whole setup 😢. The docs regarding the docker setup for Windows also needs to be more detailed but, this project is lacking in contributors now, I suppose 😆.

😄 Well I’m a Windows, Mac and a Linux user. LoL XD

Well, I am a Windows user. To run in a docker environment I need to execute xhost +local:docker right. So initially, I need to set up X Server on my machine right?

If yes can you give steps to do that?

@Tarunkumarkanakam I think yes. I don’t have a windows machine and I tried multiple times to install wsl in my Windows VM but it failed each time and finally destructed the whole VM, so, I had to delete the whole setup 😢. The docs regarding the docker setup for Windows also needs to be more detailed but, this project is lacking in contributors now, I suppose 😆.

image

@SaptarshiSarkar12 When I executed the CLI with code from the master branch using docker-compose run cli. I am getting the error as in the image attached. Is that an issue that needs to be reported?

EDIT: Sorry, My bad it’s my firewall issue. 😞