YouTube.com 0.7 - GUI for youtube-dl

Discuss and share scripts and script files...
highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Youtube.com 0.3 (Only requires Xyplorer now)

Post by highend »

the above script is only for youtube videos having size less than 100Mb only
Already stated in the first post...
i have added option to download from the clipboard or type URL
Why not check if the clipboard already contains an url and just confirm if the user wants to download it / let him type one if none was found? Surrounding spaces or quotes are removed automatically.

Code: Select all

	// Check clipboard if it contains a youtube url
	$cp = formatlist("<clipboard>", "tu");
	if (regexreplace($cp, "https?://www\.youtube", "") != $cp) {
		$url = input("Do you want to download from the following source?", , $cp, , , 400, 200);
	} else {
		$url = input("Please insert the youtube url:", , , , , 400, 200);
		if ($url == "") {
			status "No url provided, aborted", FF0000, "alert";
			end(true);
		}
	}
	$YoutubeSource_All = readurl($url);
One of my scripts helped you out? Please donate via Paypal

klownboy
Posts: 4109
Joined: 28 Feb 2012 19:27

Re: Youtube.com 0.3 (Only requires Xyplorer now)

Post by klownboy »

Hi highend,
I like your youtube url check above since a few times I had forgot that I copied something else to the clipboard subsequent to the copying the youtube url. But, for the cases that a legitimate youtube url is in the clipboard, which is hopefully most of the time, I'd rather the script simply continue with the url that's in the clipboard with no prompt or comfirmation to do so. What I did was just replace the line, $url = input("Do you... with $url = $cp. It still will give me the next input box to insert a youtube url if I didn't provide a youtube url. Is that the best way to handle my situation?

I know 40k said getting the "title" name may need work and I know you're the closest thing to a RegEx genius around here. :) Most resultant titles I've downloaded weren't too bad actually (i.e., close enough), but I noticed on this http://www.youtube.com/watch?v=6gwLQAuHJv8, with a title of Hendrix Interview - "I'm not the greatest guitar player" resulted in a title of Hendrix Interview quot I #39 m not the greatest guitar player quot YouTube.mp4 The issues I imagine are due to the dash, apostrophe and quotes. I stepped through the script but it was way past my knowledge of regex, which is none. It's certainly not a biggie unless you see something obvious and quick that comes to mind.

Until this script, I rarely went to Youtube for anything, but I find myself actually using youtube a bit more now with 40k's handy script (whether that's good or bad depends I suppose :) ) ...thanks 40k.
Thanks,
Ken
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

highend
Posts: 13274
Joined: 06 Feb 2011 00:33

Re: Youtube.com 0.3 (Only requires Xyplorer now)

Post by highend »

Hi Ken,
Is that the best way to handle my situation?
If you mean if that's the best way to modify the code: I'd say yes :)

Regarding the regex problem, I'd replace a few things before I run the (slightly modified) regex

Try to replace:

Code: Select all

 $RegEx = "[^:&;()\/ ]+\b";
with:

Code: Select all

 $Title = replacelist($Title, ""|'| - YouTube", "|'|", "|");
 $RegEx = "[^:&;()\/ ]+\b|-";
And run a few urls through it. Tell me if you can see anything weired...
One of my scripts helped you out? Please donate via Paypal

40k
Posts: 234
Joined: 09 Dec 2011 21:25

Re: Youtube.com 0.3 (Only requires Xyplorer now)

Post by 40k »

The file name issues should be gone in the next update. I wrote the code for getting the file name rather quickly and so it's a bit sloppy.
I'm probably also going to re-introduce VLC as an optional addition to the script. I've opened a thread on the "Bug Reports" forum about the 100mb file size limitation but it seems Don isn't around at the moment so as a quick fix I will provide code for using the script with VLC as well.

What I suggest to do is open a second Xyplorer if your intention is to download a bunch of Youtube videos. Currently I do not know of a way to make the download (readurl function) run in the background of a single Xyplorer instance.

The issue of what is the easiest way to feed a URL to the script comes down to personal taste I imagine. I've seen the code proposed by others in this thread but in the end I think the best way is simply to allow the specific user to modify the code to their liking. What I may do in the future is include different solutions in the code and comment them out, so the user can choose which input method he would like to use.

So in short here is what I have planned for the next update:

1. (Hopefully) removal of the 100mb Xyplorer limitation
2. (OPTIONAL) re-introduction support for VLC
3. (OPTIONAL) Audio only and Video only demuxing using VLC.
4. (INTERESTED?) Pod-cast creator. Download your favorite Youtube shows/videocasts into a folder and have them automatically turned into mp3/m4b so you can listen to them using your ipod/mp3 player.
I develop scripts that integrate media functionality into Xyplorer.
Hash - Twitch.tv in VLC (NEW 2.0!) - FFmpeg GUI - Youtube downloading
XYplorer for Linux! Tutorial

Marco
Posts: 2347
Joined: 27 Jun 2011 15:20

Re: Youtube.com 0.3 (Only requires Xyplorer now)

Post by Marco »

highend wrote:...
Try to replace:

Code: Select all

 $RegEx = "[^:&;()\/ ]+\b";
with:

Code: Select all

 $Title = replacelist($Title, ""|'| - YouTube", "|'|", "|");
 $RegEx = "[^:&;()\/ ]+\b|-";
And run a few urls through it. Tell me if you can see anything weired...
Also, https://en.wikipedia.org/wiki/List_of_X ... ies_in_XML gives the five escaping sequences that are going to garble file names. So

Code: Select all

$Title = replacelist("$Title", "",",&,&,&apos;,',<,<,>,>", ""","",&,&,',',<,<,>,>," ",");
And that's for HTML. Then you should take into account filesystem forbidden characters. As I wrote before, http://www.xyplorer.com/xyfc/posting.ph ... =7&p=84389
...
According to Wikipedia, https://en.wikipedia.org/wiki/NTFS

Code: Select all

Allowed characters in filenames
[cut]
In Win32 namespace, any UTF-16 code unit (case insensitive) except U+0000 (NUL) / (slash) \ (backslash) : (colon) * (asterisk) ? (Question mark) " (quote) < (less than) > (greater than) and | (pipe)
so your regex for purifying titles should be

Code: Select all

[\x00/\\:\*\?"<>\|]
HTH
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]

40k
Posts: 234
Joined: 09 Dec 2011 21:25

Re: Youtube.com 0.3 (Only requires Xyplorer now)

Post by 40k »

Hi Marco, your remarks will be incorporated in the next version (with credit!) :)
I develop scripts that integrate media functionality into Xyplorer.
Hash - Twitch.tv in VLC (NEW 2.0!) - FFmpeg GUI - Youtube downloading
XYplorer for Linux! Tutorial

klownboy
Posts: 4109
Joined: 28 Feb 2012 19:27

Re: Youtube.com 0.3 (Only requires Xyplorer now)

Post by klownboy »

Hey highend, sorry I'm slow in getting back, but I was experiencing an issue while attempting to download youtube videos (i.e., I was receiving a "URL not found error"). I know it was unrelated to your modified code since it was the "URL" not the "title". Anyway, with your recommended code changes I had excellent results with Titles that contained some odd characters (e.g., Jimi Hendrix - "Jimi Hendrix: The Dick Cavett Show" trailer resulted in a file title of Jimi Hendrix - Jimi Hendrix The Dick Cavett Show trailer and Hendrix Interview - "I'm not the greatest guitar player" resulted in Hendrix Interview - I'm not the greatest guitar player ).

Hi Marco, I saw that you had followed-up with additional recommendations. I wasn't positive if your first recommendation for the "replacelist" was intended as a replacement for highend's or in addition to. I assumed the regex suggestion was a replacement to clean up the title. I actually tried both ways but the results ended with a blank titles, just the mp4 extension. I must have substituted your recommendations incorrectly. :)
We'll see what 40k comes up with...
Thanks,
Ken
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

Marco
Posts: 2347
Joined: 27 Jun 2011 15:20

Re: Youtube.com 0.3 (Only requires Xyplorer now)

Post by Marco »

@klownboy
Hi. Both steps are necessary.
The first replacelist converts the title from what you can define as an HTML/XML expression to what you actually see in the browser title bar. Five special characters, that are written as &code; in HTML are converted into their "readable" counterparts. At the end of this step you have a perfectly readable title, without strange escapes.
The second step on the other hand "purifies" such readable title, removing the characters that are not allowed in FAT/NTFS filenames/paths. This is what XY does with "Autoreplace invalid characters", basically. I provided a regex since 40k originally used a regex, however replacelist might be more performing.
Bottom line: both are necessary. They could be merged into one single replacelist, but imo two different lines make everything more clear.

EDIT: yes you're right, there's something messed up with quoting. Investigating...

EDIT2: ok, this seems to work so far

Code: Select all

 $Title = replace($Title, """, '"');
 $Title = replace($Title, """, '"');
 $Title = replacelist($Title, "&,&,&apos;,',<,<,>,>", "&,&,',',<,<,>,>", ",");

 $Title = replace($Title, '"', "");
 $Title = replacelist($Title, "/,\,:,*,?,<,>,|", "", ",");
Double quotes make things weird, that's why they're separated from the rest. Tested on
https://www.youtube.com/watch?v=3Yc0LcST5cc
https://www.youtube.com/watch?v=AuSoPnpTM4Y
https://www.youtube.com/watch?v=RUsRh0j_9Iw
https://www.youtube.com/watch?v=QMivdso5EBM
https://www.youtube.com/watch?v=XNOn6LECDvk
https://www.youtube.com/watch?v=smQvQjTi1oQ
Attention: the last two lines remove forbidden chars. If you want to replace them, specify something between the double double quotes.
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]

klownboy
Posts: 4109
Joined: 28 Feb 2012 19:27

Re: Youtube.com 0.3 (Only requires Xyplorer now)

Post by klownboy »

Sorry Marco, I think I'm getting lost in all the regex's and replace's. :) What line of code comes before your 5 recommended lines and what lines comes after? I ask because I was not getting a title, just an extension. Is it

Code: Select all

 $Title = replacelist($Title, ""|'| - YouTube", "|'|", "|");
before and after would be your recommended regex line of,

Code: Select all

 $RegEx = [\x00/\\:\*\?"<>\|];  //didn't seem to work quoted or unquoted
 $g_Title = regexmatches ("$Title", "$RegEx", " ", "0");
What worked for me (i.e., good correct titles) on all your links (thought the filesizes was too long to actually download) was using highend's "regex" along with all your replace and replacelist recommended above.

Code: Select all

  $YoutubeSource_All = readurl($url);
  $RegEx ="<title>.+<\/title>";
  $Title = regexmatches ("$YoutubeSource_All", "$RegEx", "", "0");
  $RegEx ="<title>|<\/title>";
  $Title = regexreplace ("$Title", "$RegEx", "", "0");
  $Title = replacelist($Title, ""|'| - YouTube", "|'|", "|");
 
  $Title = replace($Title, """, '"');
  $Title = replace($Title, """, '"');
  $Title = replacelist($Title, "&,&,&apos;,',<,<,>,>", "&,&,',',<,<,>,>", ",");

  $Title = replace($Title, '"', "");
  $Title = replacelist($Title, "/,\,:,*,?,<,>,|", "", ",");
  $RegEx = "[^:&;()\/ ]+\b|-";
 
  $g_Title = regexmatches ("$Title", "$RegEx", " ", "0");

Thanks. Does that make any sense? Hopefully the tweaks and testing help out in 40k's next rendition.
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

Marco
Posts: 2347
Joined: 27 Jun 2011 15:20

Re: Youtube.com 0.3 (Only requires Xyplorer now)

Post by Marco »

:)

Code: Select all

  $YoutubeSource_All = readurl($url);
  $RegEx ="<title>.+<\/title>";
  $Title = regexmatches ("$YoutubeSource_All", "$RegEx", "", "0");
  $RegEx ="<title>|<\/title>";
  $Title = regexreplace ("$Title", "$RegEx", "", "0");
  $Title = replacelist($Title, ""|'| - YouTube", "|'|", "|"); //###########you can remove this, however titles will all end with " - Youtube"
  $Title = regexreplace($Title, " - Youtube$", ""); //################you can substitute the line above with this, that will remove the ending " - Youtube" from titles
 
  $Title = replace($Title, """, '"');
  $Title = replace($Title, """, '"');
  $Title = replacelist($Title, "&,&,&apos;,',<,<,>,>", "&,&,',',<,<,>,>", ",");

  $Title = replace($Title, '"', "");
  $Title = replacelist($Title, "/,\,:,*,?,<,>,|", "", ",");
  $RegEx = "[^:&;()\/ ]+\b|-"; //################you can remove this...
 
  $g_Title = regexmatches ("$Title", "$RegEx", " ", "0"); //###############...and this
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]

klownboy
Posts: 4109
Joined: 28 Feb 2012 19:27

Re: Youtube.com 0.3 (Only requires Xyplorer now)

Post by klownboy »

Thanks Marco, it worked very well. However, since you used "replacelist" in lieu of the "regex", and as you noted the last 2 lines can be removed, if they are removed, you have to change the new last line to:

Code: Select all

 $g_Title = replacelist($Title, "/,\,:,*,?,<,>,|", "", ",");
to get the $g_Title variable needed (that's where I was going wrong earlier). You may want to note that on your last post. Thanks again to you and highend.
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

40k
Posts: 234
Joined: 09 Dec 2011 21:25

Re: Youtube.com 0.3 (Only requires Xyplorer now)

Post by 40k »

klownboy wrote:Thanks Marco, it worked very well. However, since you used "replacelist" in lieu of the "regex", and as you noted the last 2 lines can be removed, if they are removed, you have to change the new last line to:

Code: Select all

 $g_Title = replacelist($Title, "/,\,:,*,?,<,>,|", "", ",");
to get the $g_Title variable needed (that's where I was going wrong earlier). You may want to note that on your last post. Thanks again to you and highend.
I have integrated Marco's code into the script. The file naming code seems to be pretty robust now.
I'm currently working on putting VLC support back in since it seems Don isn't responding to my query about the file limit (yet).

I'm hoping to publish version 0.4 by this friday :)
I develop scripts that integrate media functionality into Xyplorer.
Hash - Twitch.tv in VLC (NEW 2.0!) - FFmpeg GUI - Youtube downloading
XYplorer for Linux! Tutorial

klownboy
Posts: 4109
Joined: 28 Feb 2012 19:27

Re: Youtube.com 0.3 (Only requires Xyplorer now)

Post by klownboy »

Don appears to be off line for a week or more. I wouldn't rule him out expanding the download limitation though. Maybe you should consider leaving the XY download option in your script and work your VLC options back in for full video and audio only. That would seem to make sense. We could always take the VLC option for the larger downloads. Thanks again.
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440

40k
Posts: 234
Joined: 09 Dec 2011 21:25

Re: Youtube.com XY+VLC 0.5 Update 15/04/13

Post by 40k »

Script is now at 0.5
Check OP for update notes :)
I develop scripts that integrate media functionality into Xyplorer.
Hash - Twitch.tv in VLC (NEW 2.0!) - FFmpeg GUI - Youtube downloading
XYplorer for Linux! Tutorial

Enternal
Posts: 1174
Joined: 10 Jan 2012 18:26

Re: Youtube.com XY+VLC 0.5 Update 15/04/13

Post by Enternal »

Congratulation! The script is now very capable without the limit. It's also great that you still have the option to use VLC if you need to use it. :biggrin:

Post Reply