Skip to content

Commit 42cab36

Browse files
committed
Ensure copy-button always used; write raw clipboard bytes, add verification and diagnostics tools; prefer in-page captures; add tests and compare utility
1 parent bcff284 commit 42cab36

6 files changed

Lines changed: 533 additions & 525 deletions

File tree

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ VS Code
7474
python tv_downloader_fixed.py --url "https://www.tradingview.com/scripts/luxalgo/"
7575
```
7676

77-
### Docker (run headless with Playwright browsers)
77+
78+
### Docker (always runs in visible mode)
7879

7980
A Docker image is provided for running the downloader in an isolated, reproducible container. The image is based on the official Playwright Python image and includes browser binaries.
8081

@@ -215,7 +216,7 @@ The enhanced downloader will automatically continue loading "Show more" until th
215216
# Show browser window (for debugging)
216217
python tv_pinescript_downloader.py \
217218
--url "https://www.tradingview.com/scripts/editors-picks/" \
218-
--visible
219+
219220
220221
# Faster downloads (shorter delay - be respectful!)
221222
python tv_pinescript_downloader.py \
@@ -293,7 +294,7 @@ indicator("Smart Money Concepts [LuxAlgo]", overlay=true)
293294
| `--output`, `-o` | Output directory | `./pinescript_downloads` |
294295
| `--max-pages`, `-p` | Maximum pages to scan | `10` |
295296
| `--delay`, `-d` | Delay between downloads (seconds) | `2.0` |
296-
| `--visible` | Show browser window | `False` |
297+
297298

298299
### Enhanced Version (`tv_downloader_enhanced.py`)
299300

@@ -334,11 +335,10 @@ playwright install --force chromium
334335

335336
### Scripts not loading
336337

337-
Try running with visible browser to debug:
338338

339-
```bash
340-
python tv_downloader_enhanced.py --url "YOUR_URL" --visible
341-
```
339+
**Note:** The downloader always runs with a visible browser window to enable clipboard-based extraction. Headless mode is not supported, and the browser window must remain open during operation for correct script extraction.
340+
341+
If you encounter issues, ensure your system allows the browser window to open and clipboard access is permitted.
342342

343343
## Ethical Usage
344344

batch_download.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@
2020

2121

2222
async def batch_download(urls: list[str], output_dir: str | None = None,
23-
delay: float = 2.0, max_pages: int = 10, visible: bool = False, debug_pages: bool = False):
23+
delay: float = 2.0, max_pages: int = 10, debug_pages: bool = False):
2424
"""Download from multiple URLs sequentially.
2525
26-
visible: show browser window when downloading each page
2726
debug_pages: enable per-page debugging output
2827
"""
2928
# Resolve output_dir default if None
@@ -58,7 +57,7 @@ async def batch_download(urls: list[str], output_dir: str | None = None,
5857

5958
scraper = EnhancedTVScraper(
6059
output_dir=output_dir,
61-
headless=not visible
60+
headless=False # Always run in visible mode for clipboard extraction
6261
)
6362

6463
try:
@@ -149,7 +148,7 @@ async def main():
149148
help='Delay between requests'
150149
)
151150

152-
parser.add_argument('--visible', action='store_true', help='Show browser window')
151+
# --visible option removed: always runs in visible mode for clipboard extraction
153152
parser.add_argument('--debug-pages', action='store_true', help='Verbose page visit logging (debug)')
154153
parser.add_argument('--template', help='URL template with {n} or {n:02d} placeholder, e.g. ".../page-{n}/?..."')
155154
parser.add_argument('--start', type=int, default=1, help='Start number for template generation')
@@ -202,7 +201,6 @@ async def main():
202201
output_dir=args.output,
203202
delay=args.delay,
204203
max_pages=args.max_pages,
205-
visible=args.visible,
206204
debug_pages=args.debug_pages
207205
)
208206

example_urls.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ https://www.tradingview.com/scripts/editors-picks/
1010
# By category
1111
# https://www.tradingview.com/scripts/indicators/
1212
# https://www.tradingview.com/scripts/strategies/
13-
# https://www.tradingview.com/scripts/libraries/
13+
# https://www.tradingview.com/scripts/indicators/
1414

1515
# By specific tags
1616
# https://www.tradingview.com/scripts/volumeprofile/

tools/compare_bytes.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from pathlib import Path
2+
f1=Path('pinescript_downloads/Volume_Profile_correct_from_copy_clicpboard.pine')
3+
f2=Path('pinescript_downloads/8jW3AO3z/8jW3AO3z_Volume_Profile_-_Density_of_Density_DAFE.pine')
4+
if not f1.exists() or not f2.exists():
5+
print('files missing')
6+
raise SystemExit(1)
7+
8+
b1=f1.read_bytes()
9+
b2=f2.read_bytes()
10+
print('len1',len(b1),'len2',len(b2))
11+
for i,(x,y) in enumerate(zip(b1,b2)):
12+
if x!=y:
13+
print('first diff at',i,'b1',hex(x),'b2',hex(y))
14+
print('around bytes:',b1[max(0,i-20):i+20])
15+
print('vs:',b2[max(0,i-20):i+20])
16+
# show heuristic: try decode segments
17+
print('\nsegment1 repr:',b1[max(0,i-20):i+20])
18+
try:
19+
print('segment1 decoded utf8:',b1[max(0,i-20):i+20].decode('utf-8'))
20+
except Exception as e:
21+
print('utf8 decode error',e)
22+
try:
23+
print('segment1 decoded latin1:',b1[max(0,i-20):i+20].decode('latin-1'))
24+
except Exception as e:
25+
print('latin1 decode error',e)
26+
try:
27+
print('segment2 decoded utf8:',b2[max(0,i-20):i+20].decode('utf-8'))
28+
except Exception as e:
29+
print('utf8 decode error for b2',e)
30+
try:
31+
print('segment2 decoded latin1:',b2[max(0,i-20):i+20].decode('latin-1'))
32+
except Exception as e:
33+
print('latin1 decode error for b2',e)
34+
break
35+
else:
36+
if len(b1)!=len(b2):
37+
print('no byte diffs in prefix but lengths differ')
38+
else:
39+
print('files identical')

tools/test_save_clipboard.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import sys
2+
from pathlib import Path
3+
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
4+
from tv_downloader_enhanced import EnhancedTVScraper
5+
from pathlib import Path
6+
7+
s=EnhancedTVScraper()
8+
# Read the known-correct clipboard dump
9+
correct = Path('pinescript_downloads/Volume_Profile_correct_from_copy_clicpboard.pine').read_text(encoding='utf-8')
10+
result={
11+
'title':'Volume Profile - Density of Density [DAFE]',
12+
'script_id':'8jW3AO3z',
13+
'author':'DskyzInvestments',
14+
'url':'https://www.tradingview.com/script/8jW3AO3z-Volume-Profile-Density-of-Density-DAFE/',
15+
'published_date':'',
16+
'version':'',
17+
'is_strategy':False,
18+
'boosts':0,
19+
'tags':['multitimeframe','Support and Resistance','Volume Profile'],
20+
'source_origin':'clipboard',
21+
'source_raw':correct
22+
}
23+
24+
p = s.save_script(result, '8jW3AO3z')
25+
print('wrote file:',p)

0 commit comments

Comments
 (0)