Tishacy / SciDownl

An unofficial api for downloading papers from SciHub via DOI, PMID, title
MIT License
204 stars 43 forks source link

Is there any character limit for file name downloaded by this package? #8

Closed ping543f closed 3 years ago

ping543f commented 3 years ago

I am trying to download a paper with doi : 10.1021/nn100856y and title is, "Preparation and Characterization of Flexible Asymmetric Supercapacitors Based on Transition-Metal-Oxide Nanowire Single-Walled Carbon Nanotube Hybrid Thin-Film Electrodes".

then I get this,

[INFO] Choose the available link 3: https://sci-hub.se [INFO] PDF url -> http://dacemirror.sci-hub.se/journal-article/ed7b231d4f4214bbd4c58ccf9ee781f5/chen2010.pdf [INFO] Article title -> Preparation and Characterization of Flexible Asymmetric Supercapacitors Based on Transition-Metal-Oxide Nanowire Single-Walled Carbon Nanotube Hybrid Thin-Film Electrodes [INFO] Verifying... [INFO] Verification success.

FileNotFoundError Traceback (most recent call last)

in 10 for doi in DOIs: 11 print(doi) ---> 12 SciHub(doi, out).download(choose_scihub_url_index=3) C:\ProgramData\Anaconda3\lib\site-packages\scidownl\scihub.py in download(self, choose_scihub_url_index) 88 pdf = self.find_pdf_in_html(res.text) 89 ---> 90 self.download_pdf(pdf) 91 # try: 92 # pdf = self.find_pdf_in_html(res.text) C:\ProgramData\Anaconda3\lib\site-packages\scidownl\scihub.py in download_pdf(self, pdf) 168 out_file_path = os.path.join(self.out, pdf['title']+'.pdf') 169 downl_size = 0 --> 170 with open(out_file_path, 'wb') as f: 171 for data in res.iter_content(chunk_size=1024, decode_unicode=False): 172 f.write(data) FileNotFoundError: [Errno 2] No such file or directory: 'paper\\Preparation and Characterization of Flexible Asymmetric Supercapacitors Based on Transition-Metal-Oxide Nanowire Single-Walled Carbon Nanotube Hybrid Thin-Film Electrodes.pdf'
ping543f commented 3 years ago

Hi there I have solved this issue by changing line 168 of scihub.py from, out_file_path = os.path.join(self.out, pdf['title']+'.pdf') to out_file_path = os.path.join(self.out, pdf['pdf_url'].split("/")[-1])

I know it could be better but as a quick solution I have adapted it, now it is not saving the files with title rather the filename found in the url.