Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Portage & Programming
  • Search

Script for wget to log name of downloaded file? [SOLVED]

Problems with emerge or ebuilds? Have a basic programming question about C, PHP, Perl, BASH or something else?
Post Reply
Advanced search
7 posts • Page 1 of 1
Author
Message
audiodef
Watchman
Watchman
User avatar
Posts: 6656
Joined: Wed Jul 06, 2005 1:02 pm
Location: The soundosphere
Contact:
Contact audiodef
Website

Script for wget to log name of downloaded file? [SOLVED]

  • Quote

Post by audiodef » Mon Feb 25, 2013 4:29 pm

Is it possible to write a script to record the filename of a file wget downloads with --trust-server name? For example, if

Code: Select all

wget --trust-server-name http://electro-music.com/forum/download.php?id=28985
downloads adventures_in_sound_117_110112_454.mp3, how can I get a script to capture the filename "adventures_in_sound_117_110112_454.mp3"?
Last edited by audiodef on Wed Feb 27, 2013 1:40 pm, edited 1 time in total.
decibel Linux: https://decibellinux.org
Github: https://github.com/Gentoo-Music-and-Audio-Technology
Facebook: https://www.facebook.com/decibellinux
Discord: https://discord.gg/73XV24dNPN
Top
Quincy
Apprentice
Apprentice
User avatar
Posts: 203
Joined: Thu Jun 02, 2005 12:28 pm
Location: Germany

  • Quote

Post by Quincy » Mon Feb 25, 2013 5:09 pm

Perhaps I'm going for the wrong point, but will this do your job?

Code: Select all

wget --trust-server-name http://electro-music.com/forum/download.php?id=28985 2>&1 | grep -o -E "»».+««" | tr -d '»«'
It redirects wget's standard error to standard output, scans this for a line with the characters enclosing the file name (in my case/localization ""»»" and "««") and outputs only this to tr which removes the enclosing characters.
Top
khayyam
Watchman
Watchman
User avatar
Posts: 6227
Joined: Thu Jun 07, 2012 2:45 am
Location: Room 101

  • Quote

Post by khayyam » Mon Feb 25, 2013 6:43 pm

audiodef ...

Its not entirely clear if you just want the file name, or if you want also to download the file. Anyhow, I'd probably approach it in a similar way to Quincy, though using '-o log' to be sure that we actually get to the 'save', and not simply take whatever comes from stdout.

Code: Select all

$ wget --trust-server-names=on -o log \
    http://electro-music.com/forum/download.php?id=28985 && \
    awk -F"'" '/saved/{print $2}' log
best ... khay
Top
audiodef
Watchman
Watchman
User avatar
Posts: 6656
Joined: Wed Jul 06, 2005 1:02 pm
Location: The soundosphere
Contact:
Contact audiodef
Website

  • Quote

Post by audiodef » Tue Feb 26, 2013 3:33 pm

Thanks, guys. This is the kind of thing I'm looking for. I only need to get the filename. I like what Quincy did - it outputs the filename, and I like khayyam's code that puts it in a file. I tried adding > downloaded_file to Quincy's code, but > doesn't seem to work with wget. What's the best way to do that?
decibel Linux: https://decibellinux.org
Github: https://github.com/Gentoo-Music-and-Audio-Technology
Facebook: https://www.facebook.com/decibellinux
Discord: https://discord.gg/73XV24dNPN
Top
khayyam
Watchman
Watchman
User avatar
Posts: 6227
Joined: Thu Jun 07, 2012 2:45 am
Location: Room 101

  • Quote

Post by khayyam » Tue Feb 26, 2013 6:29 pm

audiodef wrote:I only need to get the filename.
audiodef ... in which case both Quincy and my suggestions are off target as both will wget the file. To provide the filename, without downloading the file, '--spider' should be used.
audiodef wrote:I like what Quincy did - it outputs the filename, and I like khayyam's code that puts it in a file. I tried adding > downloaded_file to Quincy's code, but > doesn't seem to work with wget. What's the best way to do that?
Well, the following will print the filename to stdout, stdout can then be redirected to a file if need be.

Code: Select all

$ wget --trust-server-names=on --spider -o log \
    http://electro-music.com/forum/download.php?id=28985 && \
    awk -F"/" '/Location/{print substr($NF, 1, length($NF) - 12)}' log
best ... khay
Top
Quincy
Apprentice
Apprentice
User avatar
Posts: 203
Joined: Thu Jun 02, 2005 12:28 pm
Location: Germany

  • Quote

Post by Quincy » Tue Feb 26, 2013 8:47 pm

I have to correct my code a bit because I checked again and it would output the name twice when the download finishes (I didn't load the full file last time). Therefore a better solution (with actually downloading the file) would be to just use the short output of wget and then redirect as needed. But this does unfortunately not work with spider mode:

Code: Select all

wget -nv --trust-server-namehttp://electro-music.com/forum/download.php?id=28985 2>&1 | grep -o -E "\".+\"" | tr -d '"' > downloaded_file
Top
audiodef
Watchman
Watchman
User avatar
Posts: 6656
Joined: Wed Jul 06, 2005 1:02 pm
Location: The soundosphere
Contact:
Contact audiodef
Website

  • Quote

Post by audiodef » Wed Feb 27, 2013 1:32 pm

Thanks again, khay and Quincy. This is exactly what I was looking for! :)
decibel Linux: https://decibellinux.org
Github: https://github.com/Gentoo-Music-and-Audio-Technology
Facebook: https://www.facebook.com/decibellinux
Discord: https://discord.gg/73XV24dNPN
Top
Post Reply

7 posts • Page 1 of 1

Return to “Portage & Programming”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic