{"record":{"id":"6aa994d42a01e0ea","repo":"soimort/you-get","slug":"server-reported-id-s-is-invalid","errorCode":null,"errorMessage":"Server reported id %s is invalid","messagePattern":"Server reported id (.+?) is invalid","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/you_get/extractors/ximalaya.py","lineNumber":22,"sourceCode":"\nfrom ..common import *\n\nimport json\nimport re\n\nstream_types = [\n        {'itag': '1', 'container': 'm4a', 'bitrate': 'default'},\n        {'itag': '2', 'container': 'm4a', 'bitrate': '32'},\n        {'itag': '3', 'container': 'm4a', 'bitrate': '64'}\n        ]\n\ndef ximalaya_download_by_id(id, title = None, output_dir = '.', info_only = False, stream_id = None):\n    BASE_URL = 'http://www.ximalaya.com/tracks/'\n    json_url = BASE_URL + id + '.json'\n    json_data = json.loads(get_content(json_url, headers=fake_headers))\n    if 'res' in json_data:\n        if json_data['res'] == False:\n            raise ValueError('Server reported id %s is invalid' % id)\n    if 'is_paid' in json_data and json_data['is_paid']:\n        if 'is_free' in json_data and not json_data['is_free']:\n            raise ValueError('%s is paid item' % id)\n    if (not title) and 'title' in json_data:\n        title = json_data['title']\n#no size data in the json. should it be calculated?\n    size = 0\n    url = json_data['play_path_64']\n    if stream_id:\n        if stream_id == '1':\n            url = json_data['play_path_32']\n        elif stream_id == '0':\n            url = json_data['play_path']\n    logging.debug('ximalaya_download_by_id: %s' % url)\n    ext = 'm4a' \n    urls = [url]\n    print('Site:        %s' % site_info)\n    print('title:       %s' % title)","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/soimort/you-get/blob/049548f3f3f35e67ba8d3181c71fdc71d11cf260/src/you_get/extractors/ximalaya.py#L4-L40","documentation":"ximalaya_download_by_id fetches http://www.ximalaya.com/tracks/<id>.json; when the payload contains res == False the server is explicitly reporting the track id is invalid (deleted, never existed, or hidden), so the extractor raises ValueError('Server reported id %s is invalid') before reading play paths.","triggerScenarios":"A /sound/<id> URL whose track was removed or is invisible (deleted by uploader, taken down for copyright, or VIP-hidden); also playlist scraping in ximalaya_download_page picking up sound_id attributes of removed tracks (those are caught and printed as 'perhaps paid item?').","commonSituations":"Stale bookmarked sound links; album pages containing deleted entries; ids transcribed incorrectly; region blocks making tracks appear invalid.","solutions":["Open http://www.ximalaya.com/tracks/<id>.json in a browser and confirm res:false — verify the track is gone","Find the track's album page and check whether the entry is deleted or paid","If the id came from a playlist scrape, treat it as expected noise: catch ValueError and skip, as ximalaya_download_page already does","Double-check the id for typos when constructing the URL manually"],"exampleFix":"# before\ntry:\n    ximalaya_download_by_id(id, ...)\nexcept ValueError:\n    print('something wrong with %s, perhaps paid item?' % id)\n\n# after (distinguish invalid vs paid)\ntry:\n    ximalaya_download_by_id(id, ...)\nexcept ValueError as e:\n    if 'invalid' in str(e):\n        print('track %s was removed, skipping' % id)\n    else:\n        print('track %s is paid or unavailable, skipping' % id)","handlingStrategy":"try-catch","validationCode":"import json\n\ndef ximalaya_track_valid(track_id, fetch):\n    d = json.loads(fetch('http://www.ximalaya.com/tracks/%s.json' % track_id))\n    return d.get('res') is not False","typeGuard":null,"tryCatchPattern":"try:\n    ximalaya_download(url, ...)\nexcept ValueError as e:\n    if 'invalid' in str(e):\n        print('track removed; skip')\n    else:\n        raise","preventionTips":["Validate ids against the tracks JSON before batch download","In album loops, catch ValueError per track and continue (paid/invalid entries are common)","Prefer resumable loops that record already-skipped ids"],"tags":["ximalaya","invalid-id","api-response","deleted-content"],"backgroundTag":null,"analyzedSha":"049548f3f3f35e67ba8d3181c71fdc71d11cf260","analyzedAt":"2026-08-15T03:58:15.069Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}