You are not logged in.

#1 2020-12-11 23:01:35

horo
Member
Registered: 2016-03-13
Posts: 47

variable in wget?

Hey there, i recently got gifted a virtual course on programming, about 20 some odd videos accessible online.
I find it much more convenient to save the vids locally and watch them, but clicking though all the menus was tedious. I managed to dl a few of the vids using wget (all on my own like a big boy!) but couldn't figure out an expression to have it fetch all the vids. It is my understanding that wildcards and wget don't work together and you are stuck with -A for such actions, but I haven't gotten that to work out.

here's the command that works-

me@home$ wget "https://securedownloads.teach12.com/anon.eastbaymedia-drm/courses/2074/m4v/TGC_2074_Lect01_IntroductionCPlusPlus.m4v?userid=A69D0C&orderid=1454726&courseid=2074&FName=TGC_2074_Lect01_IntroductionCPlusPlus"

The key is the two instances of Lect01. If i can change those numbers, I can access the other vids, but I'm not sure how to make that happen without wildcards, or even how to do it with wildcards since I need quotes for the command to work at all

Offline

#2 2020-12-12 08:27:23

ohnonot
...again
Registered: 2015-09-29
Posts: 5,394
Website

Re: variable in wget?

horo wrote:

I managed to dl a few of the vids using wget (all on my own like a big boy!) but couldn't figure out an expression to have it fetch all the vids.

Wget can trawl a site (if you are talking about a website) and download all files of a certain types; if it has permission, that is:
https://dt.iki.fi/download-filetype-wget

The key is the two instances of Lect01. If i can change those numbers, I can access the other vids, but I'm not sure how to make that happen without wildcards, or even how to do it with wildcards since I need quotes for the command to work at all

Not sure what you're alludiong to here. Maybe you need to iterate through a list of numbers, like 01, 02, 03 etc., and are asking for shell scripting fu?
If the above article does not solve your problem, please elaborate.


Please use CODE tags for code.
Search youtube without a browser: repo | thread
BL quote proposals to this thread please.
my repos / my repos

Offline

#3 2020-12-12 12:25:53

twoion
ほやほや
Registered: 2015-08-10
Posts: 3,140

Re: variable in wget?

for n in {1..10}; do
  num=$(printf %02d $n)
  wget "https://securedownloads.teach12.com/anon.eastbaymedia-drm/courses/2074/m4v/TGC_2074_Lect01_IntroductionCPlusPlus.m4v?userid=A69D0C&orderid=1454726&courseid=2074&FName=TGC_2074_Lect${num}_IntroductionCPlusPlus" done
done

Adjust the range as needed.


Music makes us braver

Offline

#4 2020-12-13 00:38:08

horo
Member
Registered: 2016-03-13
Posts: 47

Re: variable in wget?

Thank you, ohnonot, I'll review the sight.

twoion, would i enter the lines you posted directly into the terminal or would i save this as a script and execute it?

Offline

#5 2020-12-13 11:10:46

twoion
ほやほや
Registered: 2015-08-10
Posts: 3,140

Re: variable in wget?

horo wrote:

Thank you, ohnonot, I'll review the sight.

twoion, would i enter the lines you posted directly into the terminal or would i save this as a script and execute it?

You can do either. As long as you adjust the "page range" to what you need.


Music makes us braver

Offline

#6 2020-12-13 19:37:13

horo
Member
Registered: 2016-03-13
Posts: 47

Re: variable in wget?

Yay! I wrote it as a script and it worked flawlessly!

Next question is how to rename them all?
I have

rename.ul

from linux-utls but I get the feeling I'll need more complex bash-fu to make it work. I would like to go from

TGC_2074_Lect01_IntroductionCPlusPlus.m4v?userid=A69D0C&orderid=1454726&courseid=2074&FName=TGC_2074_Lect01_IntroductionCPlusPlus

to

Lect01

The syntax for

rename.ul

is expression replacement target-file so i tried

$ rename.ul -nv *Lect* Lect T*

but that got me nowhere
I'm thinking I need to do something like the wget script

for n in {1..10}; do
  num=$(printf %02d $n)
  mv "TGC_2074_Lect${num}_IntroductionCPlusPlus.m4v?userid=A69D0C&orderid=1454726&courseid=2074&FName=TGC_2074_Lect${num}_IntroductionCPlusPlus" Lect${num} done

Is that close?

edit: Also in the original command what is the '%02d' for int he printf command?

Last edited by horo (2020-12-13 19:41:35)

Offline

#7 2020-12-13 22:16:11

twoion
ほやほや
Registered: 2015-08-10
Posts: 3,140

Re: variable in wget?

Try

perl-rename -nv 's/^.*(Lect\d+).*$/$1.m4v/' *.m4v*

(replace perl-rename with replace.pl or just replace on Debian).

If it checks out, remove the -n flag to make it execute the renames.


Music makes us braver

Offline

#8 2020-12-13 23:04:24

horo
Member
Registered: 2016-03-13
Posts: 47

Re: variable in wget?

i do not have any replace function, what package would it be in?

Offline

#9 2020-12-14 14:31:31

JCN-9000
Member
From: Turin, Italy
Registered: 2016-04-22
Posts: 16

Re: variable in wget?

mmv  is a great tool for this kind of stuff, also great to mess everything.

Offline

Board footer

Powered by FluxBB